Skip to content

Commit 36ceaa4

Browse files
committed
Keep loaded_bytes in parser to reduce allocation
Also centralized memory ownership to make it easy to keep data around
1 parent c34b1a1 commit 36ceaa4

3 files changed

Lines changed: 60 additions & 529 deletions

File tree

include/simdjson/document.h

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1522,6 +1522,14 @@ class document::parser {
15221522
//
15231523
size_t _max_depth;
15241524

1525+
//
1526+
// The loaded buffer (reused each time load() is called)
1527+
//
1528+
std::unique_ptr<char[], decltype(&aligned_free_char)> loaded_bytes;
1529+
1530+
// Capacity of loaded_bytes buffer.
1531+
size_t _loaded_bytes_capacity{0};
1532+
15251533
// all nodes are stored on the doc.tape using a 64-bit word.
15261534
//
15271535
// strings, double and ints are stored as
@@ -1543,6 +1551,11 @@ class document::parser {
15431551
// and auto-allocate if not.
15441552
inline error_code ensure_capacity(size_t desired_capacity) noexcept;
15451553

1554+
//
1555+
// Read the file into loaded_bytes
1556+
//
1557+
inline simdjson_result<size_t> read_file(const std::string &path) noexcept;
1558+
15461559
#if SIMDJSON_EXCEPTIONS
15471560
// Used internally to get the document
15481561
inline const document &get_document() const noexcept(false);

0 commit comments

Comments
 (0)