You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
* work on the ondemand iterators
* guarding two SIMDJSON_ASSUME
* simplify following @jkeiser's comment
* adding safety rails to the iterators
* silencing a warning.
* updating the amalgamation files
Copy file name to clipboardExpand all lines: doc/basics.md
+13-3Lines changed: 13 additions & 3 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -354,7 +354,13 @@ the macro `SIMDJSON_DEVELOPMENT_CHECKS` to 1 prior to including
354
354
the `simdjson.h` header to enable these additional checks: just make sure you remove the
355
355
definition once your code has been tested. When `SIMDJSON_DEVELOPMENT_CHECKS` is set to 1, the
356
356
simdjson library runs additional (expensive) tests on your code to help ensure that you are
357
-
using the library in a safe manner.
357
+
using the library in a safe manner. We add asserts which may halt your program, helping
358
+
you find the bad programming pattern.
359
+
360
+
When `SIMDJSON_DEVELOPMENT_CHECKS`, some of our data structures contain extra data for
361
+
tracking explicitly potential programming mistakes. Thus you should not relying on the
362
+
size (`sizeof`) of our data structures to be constant: they may change depending on the
363
+
compiler settings.
358
364
359
365
Once your code has been tested, you can then run it in
360
366
Release mode: under Visual Studio, it means having the `_DEBUG` macro undefined, and, for other
@@ -437,8 +443,8 @@ support for users who avoid exceptions. See [the simdjson error handling documen
437
443
438
444
If you know the type of the value, you can cast it right there, too! `for (double value : array) { ... }`.
439
445
440
-
You may also use explicit iterators: `for(auto i = array.begin(); i != array.end(); i++) {}`. You can check that an array is empty with the condition `auto i = array.begin(); if (i == array.end()) {...}`.
441
-
***Object Iteration:** You can iterate through an object's fields, as well: `for (auto field : object) { ... }`. You may also use explicit iterators : `for(auto i = object.begin(); i != object.end(); i++) { auto field = *i; .... }`. You can check that an object is empty with the condition `auto i = object.begin(); if (i == object.end()) {...}`.
446
+
You may also use explicit iterators: `for(auto i = array.begin(); i != array.end(); i++) {}`. You can check that an array is empty with the condition `auto i = array.begin(); if (i == array.end()) {...}`. You should derefence (`*i`) an iterator at most once before incrementing it (`i++`), when compiling in debug mode with development checks, we add asserts to help you identify such a mistake.
447
+
***Object Iteration:** You can iterate through an object's fields, as well: `for (auto field : object) { ... }`.
442
448
-`field.unescaped_key()` will get you the unescaped key string as a `std::string_view` instance. E.g., the JSON string `"\u00e1"` becomes the Unicode string `á`. Optionally, you pass `true` as a parameter to the `unescaped_key` method if you want invalid escape sequences to be replaced by a default replacement character (e.g., `\ud800\ud801\ud811`): otherwise bad escape sequences lead to an immediate error.
443
449
-`field.escaped_key()` will get you the key string as as a `std::string_view` instance, but unlike `unescaped_key()`, the key is not processed, so no unescaping is done. E.g., the JSON string `"\u00e1"` becomes the Unicode string `\u00e1`. We expect that `escaped_key()` is faster than `field.unescaped_key()`.
444
450
-`field.value()` will get you the value, which you can then use all these other methods on.
@@ -451,6 +457,10 @@ support for users who avoid exceptions. See [the simdjson error handling documen
451
457
452
458
When you are iterating through an object, you are advancing through its keys and values. You should not also access the object or other objects. E.g. within a loop over `myobject`, you should not be accessing `myobject`. The following is an anti-pattern: `for(auto value: myobject) {myobject["mykey"]}`.
453
459
460
+
We discourage using the object iterators explicitly: `for(auto i = object.begin(); i != object.end(); i++) { auto field = *i; .... }`. In addition to the usual requirement to check against `end()` prior to dereferencing, you must also always dereference the pointer (`*it`) exactly once before you increment it (`it++`). You must also only deference the iterator once (never more than once). When compiling in
461
+
debug mode with development checks, we add asserts to help check whether you correctly
462
+
dereferenced the pointer before incrementing it.
463
+
454
464
You should never reset an object as you are iterating through it. The following is an anti-pattern: `for(auto value: myobject) {myobject.reset()}`.
455
465
***Array Index:** Because it is forward-only, you cannot look up an array element by index. Instead,
456
466
you should iterate through the array and keep an index yourself. Exceptionally, if need a single value
structsimdjson_result<SIMDJSON_IMPLEMENTATION::ondemand::array_iterator> : public SIMDJSON_IMPLEMENTATION::implementation_simdjson_result_base<SIMDJSON_IMPLEMENTATION::ondemand::array_iterator> {
95
+
using iterator_category = std::input_iterator_tag;
96
+
using value_type = simdjson_result<SIMDJSON_IMPLEMENTATION::ondemand::value>;
0 commit comments