Skip to content

Commit a476531

Browse files
committed
Share ref_address everywhere it's used
1 parent e7e6ac5 commit a476531

File tree

3 files changed

+12
-15
lines changed

3 files changed

+12
-15
lines changed

include/simdjson/document.h

Lines changed: 7 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -89,6 +89,12 @@ class tape_ref {
8989
size_t json_index;
9090
};
9191

92+
#ifdef SIMDJSON_USE_COMPUTED_GOTO
93+
typedef void* ret_address;
94+
#else
95+
typedef char ret_address;
96+
#endif
97+
9298
} // namespace internal
9399

94100
namespace dom {
@@ -977,13 +983,8 @@ class parser {
977983
/** @private Tape location of each open { or [ */
978984
std::unique_ptr<scope_descriptor[]> containing_scope{};
979985

980-
#ifdef SIMDJSON_USE_COMPUTED_GOTO
981-
/** @private Return address of each open { or [ */
982-
std::unique_ptr<void*[]> ret_address{};
983-
#else
984986
/** @private Return address of each open { or [ */
985-
std::unique_ptr<char[]> ret_address{};
986-
#endif
987+
std::unique_ptr<internal::ret_address[]> ret_address{};
987988

988989
/** @private Use `if (parser.parse(...).error())` instead */
989990
bool valid{false};

include/simdjson/inline/document.h

Lines changed: 1 addition & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -509,11 +509,7 @@ inline error_code parser::allocate(size_t capacity, size_t max_depth) noexcept {
509509
// Initialize stage 2 state
510510
//
511511
containing_scope.reset(new (std::nothrow) scope_descriptor[max_depth]); // TODO realloc
512-
#ifdef SIMDJSON_USE_COMPUTED_GOTO
513-
ret_address.reset(new (std::nothrow) void *[max_depth]);
514-
#else
515-
ret_address.reset(new (std::nothrow) char[max_depth]);
516-
#endif
512+
ret_address.reset(new (std::nothrow) internal::ret_address[max_depth]);
517513

518514
if (!ret_address || !containing_scope) {
519515
// Could not allocate memory

src/generic/stage2_build_tape.h

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -5,13 +5,13 @@
55

66
namespace stage2 {
77

8+
using internal::ret_address;
9+
810
#ifdef SIMDJSON_USE_COMPUTED_GOTO
9-
typedef void* ret_address;
1011
#define INIT_ADDRESSES() { &&array_begin, &&array_continue, &&error, &&finish, &&object_begin, &&object_continue }
1112
#define GOTO(address) { goto *(address); }
1213
#define CONTINUE(address) { goto *(address); }
13-
#else
14-
typedef char ret_address;
14+
#else // SIMDJSON_USE_COMPUTED_GOTO
1515
#define INIT_ADDRESSES() { '[', 'a', 'e', 'f', '{', 'o' };
1616
#define GOTO(address) \
1717
{ \
@@ -33,7 +33,7 @@ typedef char ret_address;
3333
case 'f': goto finish; \
3434
} \
3535
}
36-
#endif
36+
#endif // SIMDJSON_USE_COMPUTED_GOTO
3737

3838
struct unified_machine_addresses {
3939
ret_address array_begin;

0 commit comments

Comments
 (0)