Skip to content

Commit 93aeabe

Browse files
committed
Improve code style
1 parent be95a99 commit 93aeabe

File tree

4 files changed

+72
-110
lines changed

4 files changed

+72
-110
lines changed

core/2d/FontAtlas.cpp

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -43,23 +43,23 @@
4343
#include "fmt/format.h"
4444
#include "base/ZipUtils.h"
4545

46-
#include "base/PaddedString.h"
46+
#include "base/json.h"
4747

4848
namespace ax
4949
{
50-
5150
const int FontAtlas::CacheTextureWidth = 512;
5251
const int FontAtlas::CacheTextureHeight = 512;
5352
const char* FontAtlas::CMD_PURGE_FONTATLAS = "__ax_PURGE_FONTATLAS";
5453
const char* FontAtlas::CMD_RESET_FONTATLAS = "__ax_RESET_FONTATLAS";
5554

5655
void FontAtlas::loadFontAtlas(std::string_view fontatlasFile, hlookup::string_map<FontAtlas*>& outAtlasMap)
5756
{
58-
using namespace simdjson;
57+
using namespace ::simdjson;
5958

6059
try
6160
{
62-
auto strJson = PaddedString::load(fontatlasFile);
61+
simdjson::PaddedString strJson;
62+
FileUtils::getInstance()->getContents(fontatlasFile, &strJson);
6363
ondemand::parser parser;
6464
ondemand::document settings = parser.iterate(strJson);
6565
std::string_view type = settings["type"];

core/base/CMakeLists.txt

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -78,7 +78,6 @@ set(_AX_BASE_HEADER
7878
base/Scheduler.h
7979
base/EventType.h
8080
base/IMEDispatcher.h
81-
base/PaddedString.h
8281
base/JsonWriter.h
8382
base/JobSystem.h
8483
)

core/base/PaddedString.h

Lines changed: 0 additions & 105 deletions
This file was deleted.

core/base/json.h

Lines changed: 68 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,3 +2,71 @@
22

33
#include "rapidjson/rapidjson.h"
44
#include "rapidjson/document.h"
5+
#include "simdjson/simdjson.h"
6+
7+
namespace simdjson
8+
{
9+
10+
/**
11+
* @addtogroup base
12+
* @{
13+
*/
14+
/**
15+
@brief A dedicated class for easy load padded string for simdjson parser.
16+
17+
The only legal use case is:
18+
19+
PaddedString strJson;
20+
FileUtils::getInstance()->getContents(filePath, &strJson);
21+
ondemand::parser parser;
22+
ondemand::document settings = parser.iterate(strJson);
23+
*/
24+
class PaddedString final
25+
{
26+
public:
27+
PaddedString() = default;
28+
~PaddedString() { delete[] data_ptr; }
29+
30+
PaddedString(PaddedString&& o) noexcept : viable_size(o.viable_size), data_ptr(o.data_ptr)
31+
{
32+
o.data_ptr = nullptr; // we take ownership
33+
}
34+
PaddedString& operator=(PaddedString&& o) noexcept
35+
{
36+
swap(o);
37+
return *this;
38+
}
39+
void swap(PaddedString& o) noexcept
40+
{
41+
std::swap(viable_size, o.viable_size);
42+
std::swap(data_ptr, o.data_ptr);
43+
}
44+
45+
using value_type = char;
46+
size_t size() const { return viable_size; }
47+
void resize(size_t size)
48+
{
49+
assert(!data_ptr || size <= viable_size); // not allow enlarge
50+
if (!data_ptr)
51+
data_ptr = internal::allocate_padded_buffer(size);
52+
viable_size = size;
53+
}
54+
55+
char* data() { return data_ptr; }
56+
const char* data() const { return data_ptr; }
57+
58+
operator padded_string_view() const noexcept
59+
{
60+
return padded_string_view(data(), size(), size() + SIMDJSON_PADDING);
61+
}
62+
63+
private:
64+
PaddedString(const PaddedString&) = delete;
65+
size_t viable_size{0};
66+
char* data_ptr{nullptr};
67+
};
68+
69+
// end of base group
70+
/** @} */
71+
72+
} // namespace ax::simdjson

0 commit comments

Comments
 (0)