Skip to content

Commit a5afec1

Browse files
committed
Make #defines into simdjson::constants
1 parent ac0899c commit a5afec1

11 files changed

Lines changed: 64 additions & 33 deletions

benchmark/parseandstatcompetition.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -62,10 +62,10 @@ simdjson_compute_stats(const simdjson::padded_string &p) {
6262
uint8_t type = (tape_val >> 56);
6363
size_t how_many = 0;
6464
assert(type == 'r');
65-
how_many = tape_val & JSON_VALUE_MASK;
65+
how_many = tape_val & simdjson::internal::JSON_VALUE_MASK;
6666
for (; tape_idx < how_many; tape_idx++) {
6767
tape_val = pj.doc.tape[tape_idx];
68-
// uint64_t payload = tape_val & JSON_VALUE_MASK;
68+
// uint64_t payload = tape_val & simdjson::internal::JSON_VALUE_MASK;
6969
type = (tape_val >> 56);
7070
switch (type) {
7171
case 'l': // we have a long int

benchmark/statisticalmodel.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -67,10 +67,10 @@ stat_t simdjson_compute_stats(const simdjson::padded_string &p) {
6767
uint8_t type = (tape_val >> 56);
6868
size_t how_many = 0;
6969
assert(type == 'r');
70-
how_many = tape_val & JSON_VALUE_MASK;
70+
how_many = tape_val & simdjson::internal::JSON_VALUE_MASK;
7171
for (; tape_idx < how_many; tape_idx++) {
7272
tape_val = pj.doc.tape[tape_idx];
73-
// uint64_t payload = tape_val & JSON_VALUE_MASK;
73+
// uint64_t payload = tape_val & simdjson::internal::JSON_VALUE_MASK;
7474
type = (tape_val >> 56);
7575
switch (type) {
7676
case 'l': // we have a long int

include/simdjson/common_defs.h

Lines changed: 23 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -4,14 +4,29 @@
44
#include <cassert>
55
#include "simdjson/portability.h"
66

7-
// we support documents up to 4GB
8-
#define SIMDJSON_MAXSIZE_BYTES 0xFFFFFFFF
9-
10-
// the input buf should be readable up to buf + SIMDJSON_PADDING
11-
// this is a stopgap; there should be a better description of the
12-
// main loop and its behavior that abstracts over this
13-
// See https://github.com/lemire/simdjson/issues/174
14-
#define SIMDJSON_PADDING 32
7+
namespace simdjson {
8+
9+
/** The maximum document size supported by simdjson. */
10+
constexpr size_t SIMDJSON_MAXSIZE_BYTES = 0xFFFFFFFF;
11+
12+
/**
13+
* The amount of padding needed in a buffer to parse JSON.
14+
*
15+
* the input buf should be readable up to buf + SIMDJSON_PADDING
16+
* this is a stopgap; there should be a better description of the
17+
* main loop and its behavior that abstracts over this
18+
* See https://github.com/lemire/simdjson/issues/174
19+
*/
20+
constexpr size_t SIMDJSON_PADDING = 32;
21+
22+
/**
23+
* By default, simdjson supports this many nested objects and arrays.
24+
*
25+
* This is the default for document::parser::max_depth().
26+
*/
27+
constexpr size_t DEFAULT_MAX_DEPTH = 1024;
28+
29+
} // namespace simdjson
1530

1631
#if defined(__GNUC__)
1732
// Marks a block with a name so that MCA analysis can see it.

include/simdjson/document.h

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -9,11 +9,12 @@
99
#include "simdjson/simdjson.h"
1010
#include "simdjson/padded_string.h"
1111

12-
#define JSON_VALUE_MASK 0x00FFFFFFFFFFFFFF
13-
#define DEFAULT_MAX_DEPTH 1024 // a JSON document with a depth exceeding 1024 is probably de facto invalid
14-
1512
namespace simdjson {
1613

14+
namespace internal {
15+
constexpr const uint64_t JSON_VALUE_MASK = 0x00FFFFFFFFFFFFFF;
16+
}
17+
1718
template<size_t max_depth> class document_iterator;
1819

1920
/**

include/simdjson/document_iterator.h

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -67,15 +67,15 @@ template <size_t max_depth> class document_iterator {
6767
// within the string: get_string_length determines the true string length.
6868
inline const char *get_string() const {
6969
return reinterpret_cast<const char *>(
70-
doc.string_buf.get() + (current_val & JSON_VALUE_MASK) + sizeof(uint32_t));
70+
doc.string_buf.get() + (current_val & internal::JSON_VALUE_MASK) + sizeof(uint32_t));
7171
}
7272

7373
// return the length of the string in bytes
7474
inline uint32_t get_string_length() const {
7575
uint32_t answer;
7676
memcpy(&answer,
7777
reinterpret_cast<const char *>(doc.string_buf.get() +
78-
(current_val & JSON_VALUE_MASK)),
78+
(current_val & internal::JSON_VALUE_MASK)),
7979
sizeof(uint32_t));
8080
return answer;
8181
}

include/simdjson/inline/document.h

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -247,7 +247,7 @@ inline bool document::print_json(std::ostream &os, size_t max_depth) const noexc
247247
uint8_t type = (tape_val >> 56);
248248
size_t how_many = 0;
249249
if (type == 'r') {
250-
how_many = tape_val & JSON_VALUE_MASK;
250+
how_many = tape_val & internal::JSON_VALUE_MASK;
251251
} else {
252252
// Error: no starting root node?
253253
return false;
@@ -260,7 +260,7 @@ inline bool document::print_json(std::ostream &os, size_t max_depth) const noexc
260260
in_object[depth] = false;
261261
for (; tape_idx < how_many; tape_idx++) {
262262
tape_val = tape[tape_idx];
263-
uint64_t payload = tape_val & JSON_VALUE_MASK;
263+
uint64_t payload = tape_val & internal::JSON_VALUE_MASK;
264264
type = (tape_val >> 56);
265265
if (!in_object[depth]) {
266266
if ((in_object_idx[depth] > 0) && (type != ']')) {
@@ -355,7 +355,7 @@ inline bool document::dump_raw_tape(std::ostream &os) const noexcept {
355355
tape_idx++;
356356
size_t how_many = 0;
357357
if (type == 'r') {
358-
how_many = tape_val & JSON_VALUE_MASK;
358+
how_many = tape_val & internal::JSON_VALUE_MASK;
359359
} else {
360360
// Error: no starting root node?
361361
return false;
@@ -365,7 +365,7 @@ inline bool document::dump_raw_tape(std::ostream &os) const noexcept {
365365
for (; tape_idx < how_many; tape_idx++) {
366366
os << tape_idx << " : ";
367367
tape_val = tape[tape_idx];
368-
payload = tape_val & JSON_VALUE_MASK;
368+
payload = tape_val & internal::JSON_VALUE_MASK;
369369
type = (tape_val >> 56);
370370
switch (type) {
371371
case '"': // we have a string
@@ -432,7 +432,7 @@ inline bool document::dump_raw_tape(std::ostream &os) const noexcept {
432432
}
433433
}
434434
tape_val = tape[tape_idx];
435-
payload = tape_val & JSON_VALUE_MASK;
435+
payload = tape_val & internal::JSON_VALUE_MASK;
436436
type = (tape_val >> 56);
437437
os << tape_idx << " : " << type << "\t// pointing to " << payload
438438
<< " (start root)\n";
@@ -685,7 +685,7 @@ really_inline document::tape_type document::tape_ref::type() const noexcept {
685685
return static_cast<tape_type>(doc->tape[json_index] >> 56);
686686
}
687687
really_inline uint64_t document::tape_ref::tape_value() const noexcept {
688-
return doc->tape[json_index] & JSON_VALUE_MASK;
688+
return doc->tape[json_index] & internal::JSON_VALUE_MASK;
689689
}
690690
template<typename T>
691691
really_inline T document::tape_ref::next_tape_value() const noexcept {

include/simdjson/inline/document_iterator.h

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -150,7 +150,7 @@ template <size_t max_depth> bool document_iterator<max_depth>::prev() {
150150
oldnpos = npos;
151151
if ((current_type == '[') || (current_type == '{')) {
152152
// we need to jump
153-
npos = (current_val & JSON_VALUE_MASK);
153+
npos = (current_val & internal::JSON_VALUE_MASK);
154154
} else {
155155
npos = npos + ((current_type == 'd' || current_type == 'l') ? 2 : 1);
156156
}
@@ -179,7 +179,7 @@ template <size_t max_depth> bool document_iterator<max_depth>::down() {
179179
return false;
180180
}
181181
if ((current_type == '[') || (current_type == '{')) {
182-
size_t npos = (current_val & JSON_VALUE_MASK);
182+
size_t npos = (current_val & internal::JSON_VALUE_MASK);
183183
if (npos == location + 2) {
184184
return false; // we have an empty scope
185185
}
@@ -206,7 +206,7 @@ template <size_t max_depth> bool document_iterator<max_depth>::next() {
206206
size_t npos;
207207
if ((current_type == '[') || (current_type == '{')) {
208208
// we need to jump
209-
npos = (current_val & JSON_VALUE_MASK);
209+
npos = (current_val & internal::JSON_VALUE_MASK);
210210
} else {
211211
npos = location + (is_number() ? 2 : 1);
212212
}
@@ -228,7 +228,7 @@ document_iterator<max_depth>::document_iterator(const document &doc_) noexcept
228228
current_val = doc.tape[location++];
229229
current_type = (current_val >> 56);
230230
depth_index[0].scope_type = current_type;
231-
tape_length = current_val & JSON_VALUE_MASK;
231+
tape_length = current_val & internal::JSON_VALUE_MASK;
232232
if (location < tape_length) {
233233
// If we make it here, then depth_capacity must >=2, but the compiler
234234
// may not know this.
@@ -456,7 +456,7 @@ bool document_iterator<max_depth>::relative_move_to(const char *pointer,
456456
size_t npos;
457457
if ((current_type == '[') || (current_type == '{')) {
458458
// we need to jump
459-
npos = (current_val & JSON_VALUE_MASK);
459+
npos = (current_val & internal::JSON_VALUE_MASK);
460460
} else {
461461
npos =
462462
location + ((current_type == 'd' || current_type == 'l') ? 2 : 1);

include/simdjson/jsonioutil.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,4 +19,4 @@ inline padded_string get_corpus(const std::string &filename) {
1919

2020
} // namespace simdjson
2121

22-
#endif
22+
#endif // SIMDJSON_JSONIOUTIL_H

include/simdjson/jsonminifier.h

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -26,5 +26,7 @@ static inline size_t json_minify(const std::string_view &p, char *out) {
2626
static inline size_t json_minify(const padded_string &p, char *out) {
2727
return json_minify(p.data(), p.size(), out);
2828
}
29+
2930
} // namespace simdjson
30-
#endif
31+
32+
#endif // SIMDJSON_JSONMINIFIER_H

include/simdjson/simdjson_version.h

Lines changed: 14 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,12 +2,25 @@
22
// do not change by hand
33
#ifndef SIMDJSON_SIMDJSON_VERSION_H
44
#define SIMDJSON_SIMDJSON_VERSION_H
5+
6+
/** The version of simdjson being used (major.minor.revision) */
57
#define SIMDJSON_VERSION 0.2.1
8+
69
namespace simdjson {
710
enum {
11+
/**
12+
* The major version (MAJOR.minor.revision) of simdjson being used.
13+
*/
814
SIMDJSON_VERSION_MAJOR = 0,
15+
/**
16+
* The minor version (major.MINOR.revision) of simdjson being used.
17+
*/
918
SIMDJSON_VERSION_MINOR = 2,
19+
/**
20+
* The revision (major.minor.REVISION) of simdjson being used.
21+
*/
1022
SIMDJSON_VERSION_REVISION = 1
1123
};
12-
}
24+
} // namespace simdjson
25+
1326
#endif // SIMDJSON_SIMDJSON_VERSION_H

0 commit comments

Comments
 (0)