mirror of
https://github.com/simdjson/simdjson
synced 2026-06-08 17:27:07 +00:00
Compare commits
13 Commits
| Author | SHA1 | Date | |
|---|---|---|---|
| 3e777c1759 | |||
| a410c723c8 | |||
| f91a1ae07e | |||
| c3954b1fb8 | |||
| ce74ece545 | |||
| dd4dce848e | |||
| e8f370b085 | |||
| 645033a8c8 | |||
| 3b5ceeb80d | |||
| 82433a67f9 | |||
| 8c1bfe782b | |||
| 730939f01c | |||
| b169dc2ea7 |
+3
-3
@@ -3,7 +3,7 @@ cmake_minimum_required(VERSION 3.14)
|
||||
project(
|
||||
simdjson
|
||||
# The version number is modified by tools/release.py
|
||||
VERSION 1.0.2
|
||||
VERSION 2.0.2
|
||||
DESCRIPTION "Parsing gigabytes of JSON per second"
|
||||
HOMEPAGE_URL "https://simdjson.org/"
|
||||
LANGUAGES CXX C
|
||||
@@ -20,8 +20,8 @@ string(
|
||||
# ---- Options, variables ----
|
||||
|
||||
# These version numbers are modified by tools/release.py
|
||||
set(SIMDJSON_LIB_VERSION "9.0.0" CACHE STRING "simdjson library version")
|
||||
set(SIMDJSON_LIB_SOVERSION "9" CACHE STRING "simdjson library soversion")
|
||||
set(SIMDJSON_LIB_VERSION "11.0.0" CACHE STRING "simdjson library version")
|
||||
set(SIMDJSON_LIB_SOVERSION "11" CACHE STRING "simdjson library soversion")
|
||||
|
||||
option(SIMDJSON_ENABLE_THREADS "Link with thread support" ON)
|
||||
|
||||
|
||||
+1
-1
@@ -40,6 +40,6 @@ Pavel Pavlov
|
||||
Hao Chen
|
||||
Nicolas Boyer
|
||||
Kim Walisch and Jatin Bhateja (AVX-512 bitset decoder)
|
||||
Eric Zhang (AVX-512 kernel)
|
||||
Fangzheng Zhang and Weiqiang Wan (AVX-512 kernel)
|
||||
# if you have contributed to the project and your name does not
|
||||
# appear in this list, please let us know!
|
||||
|
||||
@@ -38,7 +38,7 @@ PROJECT_NAME = simdjson
|
||||
# could be handy for archiving the generated documentation or if some version
|
||||
# control system is used.
|
||||
|
||||
PROJECT_NUMBER = "1.0.2"
|
||||
PROJECT_NUMBER = "2.0.2"
|
||||
|
||||
# Using the PROJECT_BRIEF tag one can provide an optional one line description
|
||||
# for a project that appears at the top of each page and should give viewer a
|
||||
|
||||
@@ -3,7 +3,7 @@
|
||||
[/badge.svg)](https://simdjson.org/plots.html)
|
||||

|
||||

|
||||
[![][license img]][license] [](https://simdjson.org/api/1.0.0/index.html)
|
||||
[![][license img]][license] [](https://simdjson.org/api/2.0.0/index.html)
|
||||
|
||||
simdjson : Parsing gigabytes of JSON per second
|
||||
===============================================
|
||||
|
||||
@@ -4,8 +4,12 @@
|
||||
#include <map>
|
||||
#include <string>
|
||||
|
||||
|
||||
namespace amazon_cellphones {
|
||||
|
||||
const bool UNTHREADED = false;
|
||||
const bool THREADED = true;
|
||||
|
||||
using namespace json_benchmark;
|
||||
|
||||
struct brand {
|
||||
@@ -59,10 +63,11 @@ struct runner : public file_runner<I> {
|
||||
}
|
||||
};
|
||||
|
||||
template<bool threaded>
|
||||
struct simdjson_dom;
|
||||
|
||||
template<typename I> simdjson_really_inline static void amazon_cellphones(benchmark::State &state) {
|
||||
run_json_benchmark<runner<I>, runner<simdjson_dom>>(state);
|
||||
run_json_benchmark<runner<I>, runner<simdjson_dom<UNTHREADED>>>(state);
|
||||
}
|
||||
|
||||
} // namespace amazon_cellphones
|
||||
@@ -8,12 +8,16 @@ namespace amazon_cellphones {
|
||||
|
||||
using namespace simdjson;
|
||||
|
||||
template<bool threaded>
|
||||
struct simdjson_dom {
|
||||
using StringType = std::string;
|
||||
|
||||
dom::parser parser{};
|
||||
|
||||
bool run(simdjson::padded_string &json, std::map<StringType, brand> &result) {
|
||||
#ifdef SIMDJSON_THREADS_ENABLED
|
||||
parser.threaded = threaded;
|
||||
#endif
|
||||
auto stream = parser.parse_many(json);
|
||||
auto i = stream.begin();
|
||||
++i; // Skip first line
|
||||
@@ -37,7 +41,10 @@ struct simdjson_dom {
|
||||
|
||||
};
|
||||
|
||||
BENCHMARK_TEMPLATE(amazon_cellphones, simdjson_dom)->UseManualTime();
|
||||
BENCHMARK_TEMPLATE(amazon_cellphones, simdjson_dom<UNTHREADED>)->UseManualTime();
|
||||
#ifdef SIMDJSON_THREADS_ENABLED
|
||||
BENCHMARK_TEMPLATE(amazon_cellphones, simdjson_dom<THREADED>)->UseManualTime();
|
||||
#endif
|
||||
|
||||
} // namespace amazon_cellphones
|
||||
|
||||
|
||||
@@ -8,12 +8,16 @@ namespace amazon_cellphones {
|
||||
|
||||
using namespace simdjson;
|
||||
|
||||
template<bool threaded>
|
||||
struct simdjson_ondemand {
|
||||
using StringType = std::string;
|
||||
|
||||
ondemand::parser parser{};
|
||||
|
||||
bool run(simdjson::padded_string &json, std::map<StringType, brand> &result) {
|
||||
#ifdef SIMDJSON_THREADS_ENABLED
|
||||
parser.threaded = threaded;
|
||||
#endif
|
||||
ondemand::document_stream stream = parser.iterate_many(json);
|
||||
ondemand::document_stream::iterator i = stream.begin();
|
||||
++i; // Skip first line
|
||||
@@ -58,7 +62,10 @@ struct simdjson_ondemand {
|
||||
|
||||
};
|
||||
|
||||
BENCHMARK_TEMPLATE(amazon_cellphones, simdjson_ondemand)->UseManualTime();
|
||||
BENCHMARK_TEMPLATE(amazon_cellphones, simdjson_ondemand<UNTHREADED>)->UseManualTime();
|
||||
#ifdef SIMDJSON_THREADS_ENABLED
|
||||
BENCHMARK_TEMPLATE(amazon_cellphones, simdjson_ondemand<THREADED>)->UseManualTime();
|
||||
#endif
|
||||
|
||||
} // namespace amazon_cellphones
|
||||
|
||||
|
||||
@@ -2,7 +2,7 @@
|
||||
#define __BENCHMARKER_H
|
||||
|
||||
#include "event_counter.h"
|
||||
#include "simdjson.h" // For SIMDJSON_DISABLE_DEPRECATED_WARNINGS
|
||||
#include "simdjson.h"
|
||||
|
||||
#include <cassert>
|
||||
#include <cctype>
|
||||
|
||||
@@ -6,6 +6,9 @@
|
||||
|
||||
namespace large_amazon_cellphones {
|
||||
|
||||
const bool UNTHREADED = false;
|
||||
const bool THREADED = true;
|
||||
|
||||
static const simdjson::padded_string &get_built_json();
|
||||
|
||||
using namespace json_benchmark;
|
||||
@@ -81,11 +84,11 @@ static const simdjson::padded_string &get_built_json() {
|
||||
return json;
|
||||
}
|
||||
|
||||
|
||||
template<bool threaded>
|
||||
struct simdjson_dom;
|
||||
|
||||
template<typename I> simdjson_really_inline static void large_amazon_cellphones(benchmark::State &state) {
|
||||
run_json_benchmark<runner<I>, runner<simdjson_dom>>(state);
|
||||
run_json_benchmark<runner<I>, runner<simdjson_dom<UNTHREADED>>>(state);
|
||||
}
|
||||
|
||||
} // namespace large_amazon_cellphones
|
||||
@@ -9,12 +9,16 @@ namespace large_amazon_cellphones {
|
||||
|
||||
using namespace simdjson;
|
||||
|
||||
template<bool threaded>
|
||||
struct simdjson_dom {
|
||||
using StringType = std::string;
|
||||
|
||||
dom::parser parser{};
|
||||
|
||||
bool run(simdjson::padded_string &json, std::map<StringType, brand> &result) {
|
||||
#ifdef SIMDJSON_THREADS_ENABLED
|
||||
parser.threaded = threaded;
|
||||
#endif
|
||||
auto stream = parser.parse_many(json);
|
||||
auto i = stream.begin();
|
||||
++i; // Skip first line
|
||||
@@ -38,7 +42,10 @@ struct simdjson_dom {
|
||||
|
||||
};
|
||||
|
||||
BENCHMARK_TEMPLATE(large_amazon_cellphones, simdjson_dom)->UseManualTime();
|
||||
BENCHMARK_TEMPLATE(large_amazon_cellphones, simdjson_dom<UNTHREADED>)->UseManualTime();
|
||||
#ifdef SIMDJSON_THREADS_ENABLED
|
||||
BENCHMARK_TEMPLATE(large_amazon_cellphones, simdjson_dom<THREADED>)->UseManualTime();
|
||||
#endif
|
||||
|
||||
} // namespace large_amazon_cellphones
|
||||
|
||||
|
||||
@@ -8,12 +8,16 @@ namespace large_amazon_cellphones {
|
||||
|
||||
using namespace simdjson;
|
||||
|
||||
template<bool threaded>
|
||||
struct simdjson_ondemand {
|
||||
using StringType = std::string;
|
||||
|
||||
ondemand::parser parser{};
|
||||
|
||||
bool run(simdjson::padded_string &json, std::map<StringType, brand> &result) {
|
||||
#ifdef SIMDJSON_THREADS_ENABLED
|
||||
parser.threaded = threaded;
|
||||
#endif
|
||||
ondemand::document_stream stream = parser.iterate_many(json);
|
||||
ondemand::document_stream::iterator i = stream.begin();
|
||||
++i; // Skip first line
|
||||
@@ -58,7 +62,10 @@ struct simdjson_ondemand {
|
||||
|
||||
};
|
||||
|
||||
BENCHMARK_TEMPLATE(large_amazon_cellphones, simdjson_ondemand)->UseManualTime();
|
||||
BENCHMARK_TEMPLATE(large_amazon_cellphones, simdjson_ondemand<UNTHREADED>)->UseManualTime();
|
||||
#ifdef SIMDJSON_THREADS_ENABLED
|
||||
BENCHMARK_TEMPLATE(large_amazon_cellphones, simdjson_ondemand<THREADED>)->UseManualTime();
|
||||
#endif
|
||||
|
||||
} // namespace amazon_cellphones
|
||||
|
||||
|
||||
+1
-7
@@ -1401,10 +1401,6 @@ You must check the type before accessing the value: it is an error to call `get_
|
||||
|
||||
The `get_number()` function is designed with performance in mind. When calling `get_number()`, you scan the number string only once, determining efficiently the type and storing it in an efficient manner.
|
||||
|
||||
If you only need to compute `v.get_number().get_number_type()` on
|
||||
a `document` or `value` instance, you should call directly the faster method
|
||||
`v.get_number_type()` which does not generate an
|
||||
intermediate `number` instance.
|
||||
|
||||
Consider the following example:
|
||||
```C++
|
||||
@@ -1417,9 +1413,7 @@ Consider the following example:
|
||||
std::cout << "negative: " << val.is_negative() << " ";
|
||||
std::cout << "is_integer: " << val.is_integer() << " ";
|
||||
ondemand::number num = val.get_number();
|
||||
// direct computation without materializing the number:
|
||||
ondemand::number_type dt = val.get_number_type();
|
||||
if(t != dt) { throw std::runtime_error("bug"); }
|
||||
ondemand::number_type t = num.get_number_type();
|
||||
switch(t) {
|
||||
case ondemand::number_type::signed_integer:
|
||||
std::cout << "integer: " << int64_t(num) << " ";
|
||||
|
||||
@@ -122,6 +122,9 @@ constexpr size_t DEFAULT_MAX_DEPTH = 1024;
|
||||
|
||||
#define SIMDJSON_PUSH_DISABLE_WARNINGS _Pragma("GCC diagnostic push")
|
||||
// gcc doesn't seem to disable all warnings with all and extra, add warnings here as necessary
|
||||
// We do it separately for clang since it has different warnings.
|
||||
#ifdef __clang__
|
||||
// clang is missing -Wmaybe-uninitialized.
|
||||
#define SIMDJSON_PUSH_DISABLE_ALL_WARNINGS SIMDJSON_PUSH_DISABLE_WARNINGS \
|
||||
SIMDJSON_DISABLE_GCC_WARNING(-Weffc++) \
|
||||
SIMDJSON_DISABLE_GCC_WARNING(-Wall) \
|
||||
@@ -134,6 +137,22 @@ constexpr size_t DEFAULT_MAX_DEPTH = 1024;
|
||||
SIMDJSON_DISABLE_GCC_WARNING(-Wshadow) \
|
||||
SIMDJSON_DISABLE_GCC_WARNING(-Wunused-parameter) \
|
||||
SIMDJSON_DISABLE_GCC_WARNING(-Wunused-variable)
|
||||
#else // __clang__
|
||||
#define SIMDJSON_PUSH_DISABLE_ALL_WARNINGS SIMDJSON_PUSH_DISABLE_WARNINGS \
|
||||
SIMDJSON_DISABLE_GCC_WARNING(-Weffc++) \
|
||||
SIMDJSON_DISABLE_GCC_WARNING(-Wall) \
|
||||
SIMDJSON_DISABLE_GCC_WARNING(-Wconversion) \
|
||||
SIMDJSON_DISABLE_GCC_WARNING(-Wextra) \
|
||||
SIMDJSON_DISABLE_GCC_WARNING(-Wattributes) \
|
||||
SIMDJSON_DISABLE_GCC_WARNING(-Wimplicit-fallthrough) \
|
||||
SIMDJSON_DISABLE_GCC_WARNING(-Wnon-virtual-dtor) \
|
||||
SIMDJSON_DISABLE_GCC_WARNING(-Wreturn-type) \
|
||||
SIMDJSON_DISABLE_GCC_WARNING(-Wshadow) \
|
||||
SIMDJSON_DISABLE_GCC_WARNING(-Wunused-parameter) \
|
||||
SIMDJSON_DISABLE_GCC_WARNING(-Wunused-variable) \
|
||||
SIMDJSON_DISABLE_GCC_WARNING(-Wmaybe-uninitialized)
|
||||
#endif // __clang__
|
||||
|
||||
#define SIMDJSON_PRAGMA(P) _Pragma(#P)
|
||||
#define SIMDJSON_DISABLE_GCC_WARNING(WARNING) SIMDJSON_PRAGMA(GCC diagnostic ignored #WARNING)
|
||||
#if defined(SIMDJSON_CLANG_VISUAL_STUDIO)
|
||||
|
||||
@@ -1067,6 +1067,11 @@ simdjson_unused simdjson_really_inline simdjson_result<ondemand::number_type> ge
|
||||
while(static_cast<uint8_t>(*p - '0') <= 9) { p++; }
|
||||
if ( p == src ) { return NUMBER_ERROR; }
|
||||
if (jsoncharutils::is_structural_or_whitespace(*p)) {
|
||||
// We have an integer.
|
||||
// If the number is negative and valid, it must be a signed integer.
|
||||
if(negative) { return ondemand::number_type::signed_integer; }
|
||||
// We want values larger or equal to 9223372036854775808 to be unsigned
|
||||
// integers, and the other values to be signed integers.
|
||||
int digit_count = int(p - src);
|
||||
if(digit_count >= 19) {
|
||||
const uint8_t * smaller_big_integer = reinterpret_cast<const uint8_t *>("9223372036854775808");
|
||||
@@ -1076,6 +1081,7 @@ simdjson_unused simdjson_really_inline simdjson_result<ondemand::number_type> ge
|
||||
}
|
||||
return ondemand::number_type::signed_integer;
|
||||
}
|
||||
// Hopefully, we have 'e' or 'E' or '.'.
|
||||
return ondemand::number_type::floating_point_number;
|
||||
}
|
||||
|
||||
|
||||
@@ -24,6 +24,10 @@ inline simdjson_result<const char *> document::current_location() noexcept {
|
||||
return iter.current_location();
|
||||
}
|
||||
|
||||
inline int32_t document::current_depth() const noexcept {
|
||||
return iter.depth();
|
||||
}
|
||||
|
||||
inline bool document::is_alive() noexcept {
|
||||
return iter.is_alive();
|
||||
}
|
||||
@@ -471,6 +475,11 @@ simdjson_really_inline simdjson_result<const char *> simdjson_result<SIMDJSON_IM
|
||||
return first.current_location();
|
||||
}
|
||||
|
||||
simdjson_really_inline int32_t simdjson_result<SIMDJSON_IMPLEMENTATION::ondemand::document>::current_depth() const noexcept {
|
||||
if (error()) { return error(); }
|
||||
return first.current_depth();
|
||||
}
|
||||
|
||||
simdjson_really_inline simdjson_result<std::string_view> simdjson_result<SIMDJSON_IMPLEMENTATION::ondemand::document>::raw_json_token() noexcept {
|
||||
if (error()) { return error(); }
|
||||
return first.raw_json_token();
|
||||
@@ -528,6 +537,7 @@ simdjson_really_inline simdjson_result<value> document_reference::find_field_uno
|
||||
simdjson_really_inline simdjson_result<json_type> document_reference::type() noexcept { return doc->type(); }
|
||||
simdjson_really_inline simdjson_result<bool> document_reference::is_scalar() noexcept { return doc->is_scalar(); }
|
||||
simdjson_really_inline simdjson_result<const char *> document_reference::current_location() noexcept { return doc->current_location(); }
|
||||
simdjson_really_inline int32_t document_reference::current_depth() const noexcept { return doc->current_depth(); }
|
||||
simdjson_really_inline bool document_reference::is_negative() noexcept { return doc->is_negative(); }
|
||||
simdjson_really_inline simdjson_result<bool> document_reference::is_integer() noexcept { return doc->is_integer(); }
|
||||
simdjson_really_inline simdjson_result<number_type> document_reference::get_number_type() noexcept { return doc->get_number_type(); }
|
||||
|
||||
@@ -399,7 +399,14 @@ public:
|
||||
*/
|
||||
simdjson_really_inline simdjson_result<bool> is_integer() noexcept;
|
||||
/**
|
||||
* Determine the number type (integer or floating-point number).
|
||||
* Determine the number type (integer or floating-point number) as quickly
|
||||
* as possible. This function does not fully validate the input. It is
|
||||
* useful when you only need to classify the numbers, without parsing them.
|
||||
*
|
||||
* If you are planning to retrieve the value or you need full validation,
|
||||
* consider using the get_number() method instead: it will fully parse
|
||||
* and validate the input, and give you access to the type:
|
||||
* get_number().get_number_type().
|
||||
*
|
||||
* get_number_type() is number_type::unsigned_integer if we have
|
||||
* an integer greater or equal to 9223372036854775808
|
||||
@@ -407,8 +414,7 @@ public:
|
||||
* integer that is less than 9223372036854775808
|
||||
* Otherwise, get_number_type() has value number_type::floating_point_number
|
||||
*
|
||||
* This function req
|
||||
* uires processing the number string, but it is expected
|
||||
* This function requires processing the number string, but it is expected
|
||||
* to be faster than get_number().get_number_type() because it is does not
|
||||
* parse the number value.
|
||||
*
|
||||
@@ -489,6 +495,17 @@ public:
|
||||
*/
|
||||
inline simdjson_result<const char *> current_location() noexcept;
|
||||
|
||||
/**
|
||||
* Returns the current depth in the document if in bounds.
|
||||
*
|
||||
* E.g.,
|
||||
* 0 = finished with document
|
||||
* 1 = document root value (could be [ or {, not yet known)
|
||||
* 2 = , or } inside root array/object
|
||||
* 3 = key or value inside root array/object.
|
||||
*/
|
||||
simdjson_really_inline int32_t current_depth() const noexcept;
|
||||
|
||||
/**
|
||||
* Get the value associated with the given JSON pointer. We use the RFC 6901
|
||||
* https://tools.ietf.org/html/rfc6901 standard.
|
||||
@@ -609,6 +626,7 @@ public:
|
||||
simdjson_really_inline simdjson_result<bool> is_scalar() noexcept;
|
||||
|
||||
simdjson_really_inline simdjson_result<const char *> current_location() noexcept;
|
||||
simdjson_really_inline int32_t current_depth() const noexcept;
|
||||
simdjson_really_inline bool is_negative() noexcept;
|
||||
simdjson_really_inline simdjson_result<bool> is_integer() noexcept;
|
||||
simdjson_really_inline simdjson_result<number_type> get_number_type() noexcept;
|
||||
@@ -675,6 +693,7 @@ public:
|
||||
simdjson_really_inline simdjson_result<SIMDJSON_IMPLEMENTATION::ondemand::json_type> type() noexcept;
|
||||
simdjson_really_inline simdjson_result<bool> is_scalar() noexcept;
|
||||
simdjson_really_inline simdjson_result<const char *> current_location() noexcept;
|
||||
simdjson_really_inline int32_t current_depth() const noexcept;
|
||||
simdjson_really_inline bool is_negative() noexcept;
|
||||
simdjson_really_inline simdjson_result<bool> is_integer() noexcept;
|
||||
simdjson_really_inline simdjson_result<SIMDJSON_IMPLEMENTATION::ondemand::number_type> get_number_type() noexcept;
|
||||
@@ -735,6 +754,7 @@ public:
|
||||
simdjson_really_inline simdjson_result<SIMDJSON_IMPLEMENTATION::ondemand::json_type> type() noexcept;
|
||||
simdjson_really_inline simdjson_result<bool> is_scalar() noexcept;
|
||||
simdjson_really_inline simdjson_result<const char *> current_location() noexcept;
|
||||
simdjson_really_inline int32_t current_depth() const noexcept;
|
||||
simdjson_really_inline bool is_negative() noexcept;
|
||||
simdjson_really_inline simdjson_result<bool> is_integer() noexcept;
|
||||
simdjson_really_inline simdjson_result<SIMDJSON_IMPLEMENTATION::ondemand::number_type> get_number_type() noexcept;
|
||||
|
||||
@@ -154,7 +154,7 @@ public:
|
||||
* This is not null-terminated; it is a view into the JSON.
|
||||
*
|
||||
* You may be pointing outside of the input buffer: it is not generally
|
||||
* safe to derefence this pointer.
|
||||
* safe to dereference this pointer.
|
||||
*/
|
||||
simdjson_really_inline const uint8_t *unsafe_pointer() const noexcept;
|
||||
/**
|
||||
|
||||
@@ -85,7 +85,7 @@ inline void log_headers() noexcept {
|
||||
printf("# skip says 'this is a structural or value I am skipping'\n");
|
||||
printf("# +/-skip says 'this is a start/end array or object I am skipping'\n");
|
||||
printf("#\n");
|
||||
printf("# The identation of the terms (array, string,...) indicates the depth,\n");
|
||||
printf("# The indentation of the terms (array, string,...) indicates the depth,\n");
|
||||
printf("# in addition to the depth being displayed.\n");
|
||||
printf("#\n");
|
||||
printf("# Every token in the document has a single depth determined by the tokens before it,\n");
|
||||
|
||||
@@ -118,7 +118,7 @@ public:
|
||||
* instance: there is no rewind and no invalidation.
|
||||
*
|
||||
* You may call at_pointer more than once on an object, but each time the pointer is advanced
|
||||
* to be within the value matched by the key indicated by the JSON pointer query. Thus any preceeding
|
||||
* to be within the value matched by the key indicated by the JSON pointer query. Thus any preceding
|
||||
* key (as well as the current key) can no longer be used with following JSON pointer calls.
|
||||
*
|
||||
* Also note that at_pointer() relies on find_field() which implies that we do not unescape keys when matching.
|
||||
@@ -168,7 +168,7 @@ public:
|
||||
simdjson_really_inline simdjson_result<size_t> count_fields() & noexcept;
|
||||
/**
|
||||
* Consumes the object and returns a string_view instance corresponding to the
|
||||
* object as represented in JSON. It points inside the original byte array containg
|
||||
* object as represented in JSON. It points inside the original byte array containing
|
||||
* the JSON document.
|
||||
*/
|
||||
simdjson_really_inline simdjson_result<std::string_view> raw_json() noexcept;
|
||||
|
||||
@@ -181,6 +181,10 @@ simdjson_really_inline simdjson_result<const char *> value::current_location() n
|
||||
return iter.json_iter().current_location();
|
||||
}
|
||||
|
||||
simdjson_really_inline int32_t value::current_depth() const noexcept{
|
||||
return iter.json_iter().depth();
|
||||
}
|
||||
|
||||
simdjson_really_inline simdjson_result<value> value::at_pointer(std::string_view json_pointer) noexcept {
|
||||
json_type t;
|
||||
SIMDJSON_TRY(type().get(t));
|
||||
@@ -400,6 +404,11 @@ simdjson_really_inline simdjson_result<const char *> simdjson_result<SIMDJSON_IM
|
||||
return first.current_location();
|
||||
}
|
||||
|
||||
simdjson_really_inline int32_t simdjson_result<SIMDJSON_IMPLEMENTATION::ondemand::value>::current_depth() const noexcept {
|
||||
if (error()) { return error(); }
|
||||
return first.current_depth();
|
||||
}
|
||||
|
||||
simdjson_really_inline simdjson_result<SIMDJSON_IMPLEMENTATION::ondemand::value> simdjson_result<SIMDJSON_IMPLEMENTATION::ondemand::value>::at_pointer(std::string_view json_pointer) noexcept {
|
||||
if (error()) { return error(); }
|
||||
return first.at_pointer(json_pointer);
|
||||
|
||||
@@ -369,7 +369,14 @@ public:
|
||||
*/
|
||||
simdjson_really_inline simdjson_result<bool> is_integer() noexcept;
|
||||
/**
|
||||
* Determine the number type (integer or floating-point number).
|
||||
* Determine the number type (integer or floating-point number) as quickly
|
||||
* as possible. This function does not fully validate the input. It is
|
||||
* useful when you only need to classify the numbers, without parsing them.
|
||||
*
|
||||
* If you are planning to retrieve the value or you need full validation,
|
||||
* consider using the get_number() method instead: it will fully parse
|
||||
* and validate the input, and give you access to the type:
|
||||
* get_number().get_number_type().
|
||||
*
|
||||
* get_number_type() is number_type::unsigned_integer if we have
|
||||
* an integer greater or equal to 9223372036854775808
|
||||
@@ -448,6 +455,17 @@ public:
|
||||
*/
|
||||
simdjson_really_inline simdjson_result<const char *> current_location() noexcept;
|
||||
|
||||
/**
|
||||
* Returns the current depth in the document if in bounds.
|
||||
*
|
||||
* E.g.,
|
||||
* 0 = finished with document
|
||||
* 1 = document root value (could be [ or {, not yet known)
|
||||
* 2 = , or } inside root array/object
|
||||
* 3 = key or value inside root array/object.
|
||||
*/
|
||||
simdjson_really_inline int32_t current_depth() const noexcept;
|
||||
|
||||
/**
|
||||
* Get the value associated with the given JSON pointer. We use the RFC 6901
|
||||
* https://tools.ietf.org/html/rfc6901 standard.
|
||||
@@ -479,7 +497,7 @@ public:
|
||||
* to call at_pointer on the same array.
|
||||
*
|
||||
* You may call at_pointer more than once on an object, but each time the pointer is advanced
|
||||
* to be within the value matched by the key indicated by the JSON pointer query. Thus any preceeding
|
||||
* to be within the value matched by the key indicated by the JSON pointer query. Thus any preceding
|
||||
* key (as well as the current key) can no longer be used with following JSON pointer calls.
|
||||
*
|
||||
* Also note that at_pointer() relies on find_field() which implies that we do not unescape keys when matching
|
||||
@@ -650,7 +668,8 @@ public:
|
||||
|
||||
/** @copydoc simdjson_really_inline simdjson_result<const char *> current_location() noexcept */
|
||||
simdjson_really_inline simdjson_result<const char *> current_location() noexcept;
|
||||
|
||||
/** @copydoc simdjson_really_inline int32_t current_depth() const noexcept */
|
||||
simdjson_really_inline int32_t current_depth() const noexcept;
|
||||
simdjson_really_inline simdjson_result<SIMDJSON_IMPLEMENTATION::ondemand::value> at_pointer(std::string_view json_pointer) noexcept;
|
||||
};
|
||||
|
||||
|
||||
@@ -76,7 +76,7 @@ public:
|
||||
/**
|
||||
* Get the depth of this value.
|
||||
*/
|
||||
simdjson_really_inline depth_t depth() const noexcept;
|
||||
simdjson_really_inline int32_t depth() const noexcept;
|
||||
|
||||
/**
|
||||
* Get the JSON type of this value.
|
||||
|
||||
@@ -3,6 +3,32 @@
|
||||
|
||||
#include "simdjson/internal/simdprune_tables.h"
|
||||
|
||||
|
||||
|
||||
#if defined(__GNUC__) && !defined(__clang__)
|
||||
#if __GNUC__ == 8
|
||||
#define SIMDJSON_GCC8 1
|
||||
#endif // __GNUC__ == 8
|
||||
#endif // defined(__GNUC__) && !defined(__clang__)
|
||||
|
||||
#if SIMDJSON_GCC8
|
||||
/**
|
||||
* GCC 8 fails to provide _mm512_set_epi8. We roll our own.
|
||||
*/
|
||||
inline __m512i _mm512_set_epi8(uint8_t a0, uint8_t a1, uint8_t a2, uint8_t a3, uint8_t a4, uint8_t a5, uint8_t a6, uint8_t a7, uint8_t a8, uint8_t a9, uint8_t a10, uint8_t a11, uint8_t a12, uint8_t a13, uint8_t a14, uint8_t a15, uint8_t a16, uint8_t a17, uint8_t a18, uint8_t a19, uint8_t a20, uint8_t a21, uint8_t a22, uint8_t a23, uint8_t a24, uint8_t a25, uint8_t a26, uint8_t a27, uint8_t a28, uint8_t a29, uint8_t a30, uint8_t a31, uint8_t a32, uint8_t a33, uint8_t a34, uint8_t a35, uint8_t a36, uint8_t a37, uint8_t a38, uint8_t a39, uint8_t a40, uint8_t a41, uint8_t a42, uint8_t a43, uint8_t a44, uint8_t a45, uint8_t a46, uint8_t a47, uint8_t a48, uint8_t a49, uint8_t a50, uint8_t a51, uint8_t a52, uint8_t a53, uint8_t a54, uint8_t a55, uint8_t a56, uint8_t a57, uint8_t a58, uint8_t a59, uint8_t a60, uint8_t a61, uint8_t a62, uint8_t a63) {
|
||||
return _mm512_set_epi64(uint64_t(a7) + (uint64_t(a6) << 8) + (uint64_t(a5) << 16) + (uint64_t(a4) << 24) + (uint64_t(a3) << 32) + (uint64_t(a2) << 40) + (uint64_t(a1) << 48) + (uint64_t(a0) << 56),
|
||||
uint64_t(a15) + (uint64_t(a14) << 8) + (uint64_t(a13) << 16) + (uint64_t(a12) << 24) + (uint64_t(a11) << 32) + (uint64_t(a10) << 40) + (uint64_t(a9) << 48) + (uint64_t(a8) << 56),
|
||||
uint64_t(a23) + (uint64_t(a22) << 8) + (uint64_t(a21) << 16) + (uint64_t(a20) << 24) + (uint64_t(a19) << 32) + (uint64_t(a18) << 40) + (uint64_t(a17) << 48) + (uint64_t(a16) << 56),
|
||||
uint64_t(a31) + (uint64_t(a30) << 8) + (uint64_t(a29) << 16) + (uint64_t(a28) << 24) + (uint64_t(a27) << 32) + (uint64_t(a26) << 40) + (uint64_t(a25) << 48) + (uint64_t(a24) << 56),
|
||||
uint64_t(a39) + (uint64_t(a38) << 8) + (uint64_t(a37) << 16) + (uint64_t(a36) << 24) + (uint64_t(a35) << 32) + (uint64_t(a34) << 40) + (uint64_t(a33) << 48) + (uint64_t(a32) << 56),
|
||||
uint64_t(a47) + (uint64_t(a46) << 8) + (uint64_t(a45) << 16) + (uint64_t(a44) << 24) + (uint64_t(a43) << 32) + (uint64_t(a42) << 40) + (uint64_t(a41) << 48) + (uint64_t(a40) << 56),
|
||||
uint64_t(a55) + (uint64_t(a54) << 8) + (uint64_t(a53) << 16) + (uint64_t(a52) << 24) + (uint64_t(a51) << 32) + (uint64_t(a50) << 40) + (uint64_t(a49) << 48) + (uint64_t(a48) << 56),
|
||||
uint64_t(a63) + (uint64_t(a62) << 8) + (uint64_t(a61) << 16) + (uint64_t(a60) << 24) + (uint64_t(a59) << 32) + (uint64_t(a58) << 40) + (uint64_t(a57) << 48) + (uint64_t(a56) << 56));
|
||||
}
|
||||
#endif // SIMDJSON_GCC8
|
||||
|
||||
|
||||
|
||||
namespace simdjson {
|
||||
namespace SIMDJSON_IMPLEMENTATION {
|
||||
namespace {
|
||||
@@ -51,7 +77,13 @@ namespace simd {
|
||||
|
||||
template<int N=1>
|
||||
simdjson_really_inline simd8<T> prev(const simd8<T> prev_chunk) const {
|
||||
#if SIMDJSON_GCC8
|
||||
// workaround for compilers unable to figure out that 16 - N is a constant (GCC 8)
|
||||
constexpr int shift = 16 - N;
|
||||
return _mm512_alignr_epi8(*this, _mm512_permutex2var_epi64(prev_chunk, _mm512_set_epi64(13, 12, 11, 10, 9, 8, 7, 6), *this), shift);
|
||||
#else
|
||||
return _mm512_alignr_epi8(*this, _mm512_permutex2var_epi64(prev_chunk, _mm512_set_epi64(13, 12, 11, 10, 9, 8, 7, 6), *this), 16 - N);
|
||||
#endif
|
||||
}
|
||||
};
|
||||
|
||||
@@ -328,8 +360,6 @@ namespace simd {
|
||||
const simd8<T> mask = simd8<T>::splat(m);
|
||||
return this->chunks[0] <= mask;
|
||||
}
|
||||
simdjson_really_inline operator __m512i() const { return __m512i(this->chunks[0]); }
|
||||
|
||||
}; // struct simd8x64<T>
|
||||
|
||||
} // namespace simd
|
||||
|
||||
@@ -21,6 +21,11 @@
|
||||
#endif
|
||||
#endif
|
||||
|
||||
// By default, we allow AVX512.
|
||||
#ifndef SIMDJSON_AVX512_ALLOWED
|
||||
#define SIMDJSON_AVX512_ALLOWED 1
|
||||
#endif
|
||||
|
||||
// Default Icelake to on if this is x86-64. Even if we're not compiled for it, it could be selected
|
||||
// at runtime.
|
||||
#ifndef SIMDJSON_IMPLEMENTATION_ICELAKE
|
||||
|
||||
@@ -4,14 +4,14 @@
|
||||
#define SIMDJSON_SIMDJSON_VERSION_H
|
||||
|
||||
/** The version of simdjson being used (major.minor.revision) */
|
||||
#define SIMDJSON_VERSION 1.0.2
|
||||
#define SIMDJSON_VERSION 2.0.2
|
||||
|
||||
namespace simdjson {
|
||||
enum {
|
||||
/**
|
||||
* The major version (MAJOR.minor.revision) of simdjson being used.
|
||||
*/
|
||||
SIMDJSON_VERSION_MAJOR = 1,
|
||||
SIMDJSON_VERSION_MAJOR = 2,
|
||||
/**
|
||||
* The minor version (major.MINOR.revision) of simdjson being used.
|
||||
*/
|
||||
|
||||
@@ -9,6 +9,7 @@ import subprocess
|
||||
import os
|
||||
import re
|
||||
import shutil
|
||||
import datetime
|
||||
|
||||
if sys.version_info < (3, 0):
|
||||
sys.stdout.write("Sorry, requires Python 3.x or better\n")
|
||||
@@ -80,8 +81,10 @@ def dofile(fid, prepath, filename):
|
||||
# print(f"// dofile: invoked with prepath={prepath}, filename={filename}",file=fid)
|
||||
file = os.path.join(prepath, filename)
|
||||
RELFILE = os.path.relpath(file, PROJECTPATH)
|
||||
# Windows use \ as a directory separator, but we do not want that:
|
||||
OSRELFILE = RELFILE.replace('\\','/')
|
||||
# Last lines are always ignored. Files should end by an empty lines.
|
||||
print(f"/* begin file {RELFILE} */", file=fid)
|
||||
print(f"/* begin file {OSRELFILE} */", file=fid)
|
||||
includepattern = re.compile('^#include "(.*)"')
|
||||
redefines_simdjson_implementation = re.compile('^#define\s+SIMDJSON_IMPLEMENTATION\s+(.*)')
|
||||
undefines_simdjson_implementation = re.compile('^#undef\s+SIMDJSON_IMPLEMENTATION\s*$')
|
||||
@@ -113,7 +116,7 @@ def dofile(fid, prepath, filename):
|
||||
else:
|
||||
# copy the line, with SIMDJSON_IMPLEMENTATION replace to what it is currently defined to
|
||||
print(uses_simdjson_implementation.sub(current_implementation+"\\1",line), file=fid)
|
||||
print(f"/* end file {RELFILE} */", file=fid)
|
||||
print(f"/* end file {OSRELFILE} */", file=fid)
|
||||
|
||||
|
||||
# Get the generation date from git, so the output is reproducible.
|
||||
@@ -121,8 +124,12 @@ def dofile(fid, prepath, filename):
|
||||
# does not change with locale and timezone at time of generation.
|
||||
# Forcing it to be UTC is difficult, because it needs to be portable
|
||||
# between gnu date and busybox date.
|
||||
timestamp = subprocess.run(['git', 'show', '-s', '--format=%ci', 'HEAD'],
|
||||
try:
|
||||
timestamp = subprocess.run(['git', 'show', '-s', '--format=%ci', 'HEAD'],
|
||||
stdout=subprocess.PIPE).stdout.decode('utf-8').strip()
|
||||
except:
|
||||
print("git not found, timestamp based on current time")
|
||||
timestamp = str(datetime.datetime.now())
|
||||
print(f"timestamp is {timestamp}")
|
||||
|
||||
os.makedirs(AMALGAMATE_OUTPUT_PATH, exist_ok=True)
|
||||
|
||||
+2358
-15
File diff suppressed because it is too large
Load Diff
+2547
-28
File diff suppressed because it is too large
Load Diff
@@ -102,7 +102,7 @@ simdjson_really_inline simd8<bool> must_be_2_3_continuation(const simd8<uint8_t>
|
||||
} // namespace SIMDJSON_IMPLEMENTATION
|
||||
} // namespace simdjson
|
||||
|
||||
#include "icelake/utf8_lookup4_algorithm.h"
|
||||
#include "generic/stage1/utf8_lookup4_algorithm.h"
|
||||
// defining SIMDJSON_CUSTOM_BIT_INDEXER allows us to provide our own bit_indexer::write
|
||||
#define SIMDJSON_CUSTOM_BIT_INDEXER
|
||||
#include "generic/stage1/json_structural_indexer.h"
|
||||
@@ -114,6 +114,9 @@ simdjson_really_inline simd8<bool> must_be_2_3_continuation(const simd8<uint8_t>
|
||||
* naked intrinsics.
|
||||
* TODO: make this code more elegant.
|
||||
*/
|
||||
// Under GCC 12, the intrinsic _mm512_extracti32x4_epi32 may generate 'maybe uninitialized'.
|
||||
// as a workaround, we disable warnings within the following function.
|
||||
SIMDJSON_PUSH_DISABLE_ALL_WARNINGS
|
||||
namespace simdjson { namespace SIMDJSON_IMPLEMENTATION { namespace { namespace stage1 {
|
||||
simdjson_really_inline void bit_indexer::write(uint32_t idx, uint64_t bits) {
|
||||
// In some instances, the next branch is expensive because it is mispredicted.
|
||||
@@ -148,6 +151,7 @@ simdjson_really_inline void bit_indexer::write(uint32_t idx, uint64_t bits) {
|
||||
this->tail += count;
|
||||
}
|
||||
}}}}
|
||||
SIMDJSON_POP_DISABLE_WARNINGS
|
||||
|
||||
#include "generic/stage1/utf8_validator.h"
|
||||
|
||||
|
||||
@@ -1,141 +0,0 @@
|
||||
namespace simdjson {
|
||||
namespace SIMDJSON_IMPLEMENTATION {
|
||||
namespace {
|
||||
namespace utf8_validation {
|
||||
|
||||
simdjson_really_inline __m512i check_special_cases(__m512i input, const __m512i prev1) {
|
||||
__m512i mask1 = _mm512_setr_epi64(
|
||||
0x0202020202020202,
|
||||
0x4915012180808080,
|
||||
0x0202020202020202,
|
||||
0x4915012180808080,
|
||||
0x0202020202020202,
|
||||
0x4915012180808080,
|
||||
0x0202020202020202,
|
||||
0x4915012180808080);
|
||||
|
||||
const __m512i v_0f = _mm512_set1_epi8(0x0f);
|
||||
__m512i index1 = _mm512_and_si512(_mm512_srli_epi16(prev1, 4), v_0f);
|
||||
|
||||
__m512i byte_1_high = _mm512_shuffle_epi8(mask1, index1);
|
||||
__m512i mask2 = _mm512_setr_epi64(
|
||||
0xcbcbcb8b8383a3e7,
|
||||
0xcbcbdbcbcbcbcbcb,
|
||||
0xcbcbcb8b8383a3e7,
|
||||
0xcbcbdbcbcbcbcbcb,
|
||||
0xcbcbcb8b8383a3e7,
|
||||
0xcbcbdbcbcbcbcbcb,
|
||||
0xcbcbcb8b8383a3e7,
|
||||
0xcbcbdbcbcbcbcbcb);
|
||||
__m512i index2 = _mm512_and_si512(prev1, v_0f);
|
||||
|
||||
__m512i byte_1_low = _mm512_shuffle_epi8(mask2, index2);
|
||||
__m512i mask3 = _mm512_setr_epi64(
|
||||
0x101010101010101,
|
||||
0x1010101babaaee6,
|
||||
0x101010101010101,
|
||||
0x1010101babaaee6,
|
||||
0x101010101010101,
|
||||
0x1010101babaaee6,
|
||||
0x101010101010101,
|
||||
0x1010101babaaee6
|
||||
);
|
||||
__m512i index3 = _mm512_and_si512(_mm512_srli_epi16(input, 4), v_0f);
|
||||
__m512i byte_2_high = _mm512_shuffle_epi8(mask3, index3);
|
||||
return _mm512_ternarylogic_epi64(byte_1_high, byte_1_low, byte_2_high, 128);
|
||||
}
|
||||
|
||||
simdjson_really_inline __m512i check_multibyte_lengths(const __m512i prev2,
|
||||
const __m512i prev3, const __m512i sc) {
|
||||
|
||||
__m512i is_third_byte = _mm512_subs_epu8(prev2, _mm512_set1_epi8(0b11100000u-1)); // Only 111_____ will be > 0
|
||||
__m512i is_fourth_byte = _mm512_subs_epu8(prev3, _mm512_set1_epi8(0b11110000u-1)); // Only 1111____ will be > 0
|
||||
__m512i is_third_or_fourth_byte = _mm512_or_si512(is_third_byte, is_fourth_byte);
|
||||
const __m512i v_7f = _mm512_set1_epi8(char(0x7f));
|
||||
is_third_or_fourth_byte = _mm512_adds_epu8(v_7f, is_third_or_fourth_byte);
|
||||
// We want to compute (is_third_or_fourth_byte AND v80) XOR sc.
|
||||
const __m512i v_80 = _mm512_set1_epi8(char(0x80));
|
||||
return _mm512_ternarylogic_epi32(is_third_or_fourth_byte, v_80, sc, 0b1101010);
|
||||
// We could also do it the long way:
|
||||
//
|
||||
//__m512i is_third_or_fourth_byte_mask = _mm512_and_si512(is_third_or_fourth_byte, v_80);
|
||||
//return _mm512_xor_si512(is_third_or_fourth_byte_mask, sc);
|
||||
}
|
||||
//
|
||||
// Return nonzero if there are incomplete multibyte characters at the end of the block:
|
||||
// e.g. if there is a 4-byte character, but it's 3 bytes from the end.
|
||||
//
|
||||
simdjson_really_inline __m512i is_incomplete(const __m512i input) {
|
||||
// If the previous input's last 3 bytes match this, they're too short (they ended at EOF):
|
||||
// ... 1111____ 111_____ 11______
|
||||
const __m512i max_value = _mm512_setr_epi64(
|
||||
0xffffffffffffffff,
|
||||
0xffffffffffffffff,
|
||||
0xffffffffffffffff,
|
||||
0xffffffffffffffff,
|
||||
0xffffffffffffffff,
|
||||
0xffffffffffffffff,
|
||||
0xffffffffffffffff,
|
||||
0xbfdfefffffffffff);
|
||||
return _mm512_subs_epu8(input, max_value);
|
||||
}
|
||||
|
||||
struct utf8_checker {
|
||||
// If this is nonzero, there has been a UTF-8 error.
|
||||
__m512i error{};
|
||||
|
||||
// The last input we received
|
||||
__m512i prev_input_block{};
|
||||
// Whether the last input we received was incomplete (used for ASCII fast path)
|
||||
__m512i prev_incomplete{};
|
||||
|
||||
//
|
||||
// Check whether the current bytes are valid UTF-8.
|
||||
//
|
||||
simdjson_really_inline void check_utf8_bytes(const __m512i input, const __m512i prev_input) {
|
||||
// Flip prev1...prev3 so we can easily determine if they are 2+, 3+ or 4+ lead bytes
|
||||
// (2, 3, 4-byte leads become large positive numbers instead of small negative numbers)
|
||||
const __m512i movemask = _mm512_set_epi64(13, 12, 11, 10, 9, 8, 7, 6);
|
||||
const __m512i rotated = _mm512_permutex2var_epi64(prev_input, movemask, input);
|
||||
__m512i prev1 = _mm512_alignr_epi8(input, rotated, 16-1);
|
||||
__m512i prev2 = _mm512_alignr_epi8(input, rotated, 16-2);
|
||||
__m512i prev3 = _mm512_alignr_epi8(input, rotated, 16-3);
|
||||
__m512i sc = check_special_cases(input, prev1);
|
||||
this->error = _mm512_or_si512(check_multibyte_lengths(prev2, prev3, sc), this->error);
|
||||
}
|
||||
|
||||
// The only problem that can happen at EOF is that a multibyte character is too short
|
||||
// or a byte value too large in the last bytes: check_special_cases only checks for bytes
|
||||
// too large in the first of two bytes.
|
||||
simdjson_really_inline void check_eof() {
|
||||
// If the previous block had incomplete UTF-8 characters at the end, an ASCII block can't
|
||||
// possibly finish them.
|
||||
this->error = _mm512_or_si512(this->error, this->prev_incomplete);
|
||||
}
|
||||
|
||||
// returns true if ASCII.
|
||||
simdjson_really_inline bool check_next_input(const __m512i input) {
|
||||
const __m512i v_80 = _mm512_set1_epi8(char(0x80));
|
||||
const __mmask64 ascii = _mm512_test_epi8_mask(input, v_80);
|
||||
if(ascii == 0) {
|
||||
this->error = _mm512_or_si512(this->error, this->prev_incomplete);
|
||||
return true;
|
||||
} else {
|
||||
this->check_utf8_bytes(input, this->prev_input_block);
|
||||
this->prev_incomplete = is_incomplete(input);
|
||||
this->prev_input_block = input;
|
||||
return false;
|
||||
}
|
||||
}
|
||||
// do not forget to call check_eof!
|
||||
simdjson_really_inline error_code errors() {
|
||||
return (_mm512_test_epi8_mask(this->error, this->error) != 0) ? error_code::UTF8_ERROR : error_code::SUCCESS;
|
||||
}
|
||||
}; // struct utf8_checker
|
||||
} // namespace utf8_validation
|
||||
|
||||
using utf8_validation::utf8_checker;
|
||||
|
||||
} // unnamed namespace
|
||||
} // namespace SIMDJSON_IMPLEMENTATION
|
||||
} // namespace simdjson
|
||||
@@ -16,7 +16,7 @@ namespace array_error_tests {
|
||||
size_t count = 0;
|
||||
for (auto elem : std::forward<T>(array)) {
|
||||
std::cout << "-"; std::cout.flush();
|
||||
V actual;
|
||||
V actual{};
|
||||
auto actual_error = elem.get(actual);
|
||||
if (count >= N) {
|
||||
if (count >= (N+N2)) {
|
||||
|
||||
@@ -197,16 +197,18 @@ namespace number_tests {
|
||||
bool get_number_tests() {
|
||||
TEST_START();
|
||||
ondemand::parser parser;
|
||||
padded_string docdata = R"([1.0, 3, 1, 3.1415,-13231232,9999999999999999999])"_padded;
|
||||
padded_string docdata = R"([1.0, 3, 1, 3.1415,-13231232,9999999999999999999,-9223372036854775807,-9223372036854775808])"_padded;
|
||||
ondemand::number_type expectedtypes[] = {ondemand::number_type::floating_point_number,
|
||||
ondemand::number_type::signed_integer,
|
||||
ondemand::number_type::signed_integer,
|
||||
ondemand::number_type::floating_point_number,
|
||||
ondemand::number_type::signed_integer,
|
||||
ondemand::number_type::unsigned_integer
|
||||
ondemand::number_type::unsigned_integer,
|
||||
ondemand::number_type::signed_integer,
|
||||
ondemand::number_type::signed_integer
|
||||
};
|
||||
bool is_negative[] = {false, false, false, false, true, false};
|
||||
bool is_integer[] = {false, true, true, false, true, true};
|
||||
bool is_negative[] = {false, false, false, false, true, false, true, true};
|
||||
bool is_integer[] = {false, true, true, false, true, true, true, true};
|
||||
|
||||
ondemand::document doc;
|
||||
ASSERT_SUCCESS(parser.iterate(docdata).get(doc));
|
||||
|
||||
@@ -109,6 +109,85 @@ bool basics_treewalk() {
|
||||
return true;
|
||||
}
|
||||
|
||||
void print_depth_space(ondemand::value element) {
|
||||
for(auto i = 0; i < element.current_depth(); i++) {
|
||||
cout << " ";
|
||||
}
|
||||
}
|
||||
|
||||
void recursive_print_json_breakline(ondemand::value element) {
|
||||
bool add_comma;
|
||||
switch (element.type()) {
|
||||
case ondemand::json_type::array:
|
||||
cout << endl;
|
||||
print_depth_space(element);
|
||||
cout << "[";
|
||||
add_comma = false;
|
||||
for (auto child : element.get_array()) {
|
||||
if (add_comma) {
|
||||
print_depth_space(element);
|
||||
cout << ",";
|
||||
}
|
||||
// We need the call to value() to get
|
||||
// an ondemand::value type.
|
||||
recursive_print_json_breakline(child.value());
|
||||
add_comma = true;
|
||||
}
|
||||
cout << "]";
|
||||
break;
|
||||
case ondemand::json_type::object:
|
||||
cout << endl;
|
||||
print_depth_space(element);
|
||||
cout << "{";
|
||||
add_comma = false;
|
||||
for (auto field : element.get_object()) {
|
||||
if (add_comma) {
|
||||
print_depth_space(element);
|
||||
cout << ",";
|
||||
}
|
||||
// key() returns the key as it appears in the raw
|
||||
// JSON document, if we want the unescaped key,
|
||||
// we should do field.unescaped_key().
|
||||
cout << "\"" << field.key() << "\": ";
|
||||
recursive_print_json_breakline(field.value());
|
||||
add_comma = true;
|
||||
}
|
||||
cout << "}\n";
|
||||
break;
|
||||
case ondemand::json_type::number:
|
||||
// assume it fits in a double
|
||||
cout << element.get_double();
|
||||
break;
|
||||
case ondemand::json_type::string:
|
||||
// get_string() would return escaped string, but
|
||||
// we are happy with unescaped string.
|
||||
cout << "\"" << element.get_raw_json_string() << "\"";
|
||||
break;
|
||||
case ondemand::json_type::boolean:
|
||||
cout << element.get_bool();
|
||||
break;
|
||||
case ondemand::json_type::null:
|
||||
cout << "null";
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
bool basics_treewalk_breakline() {
|
||||
padded_string json[3] = {R"( [
|
||||
{ "make": "Toyota", "model": "Camry", "year": 2018, "tire_pressure": [ 40.1, 39.9, 37.7, 40.4 ] },
|
||||
{ "make": "Kia", "model": "Soul", "year": 2012, "tire_pressure": [ 30.1, 31.0, 28.6, 28.7 ] },
|
||||
{ "make": "Toyota", "model": "Tercel", "year": 1999, "tire_pressure": [ 29.8, 30.0, 30.2, 30.5 ] }
|
||||
] )"_padded, R"( {"key":"value"} )"_padded, "[12,3]"_padded};
|
||||
ondemand::parser parser;
|
||||
for(size_t i = 0 ; i < 3; i++) {
|
||||
ondemand::document doc = parser.iterate(json[i]);
|
||||
ondemand::value val = doc;
|
||||
recursive_print_json_breakline(val);
|
||||
std::cout << std::endl;
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
bool basics_1() {
|
||||
TEST_START();
|
||||
|
||||
@@ -673,7 +752,7 @@ bool stream_capacity_example() {
|
||||
if( error ) { /* handle the error */ }
|
||||
for (auto doc: stream) {
|
||||
if(counter < 6) {
|
||||
int64_t val;
|
||||
int64_t val{};
|
||||
error = doc.at_pointer("/4").get(val);
|
||||
if( error ) { /* handle the error */ }
|
||||
std::cout << "5 = " << val << std::endl;
|
||||
@@ -882,6 +961,7 @@ bool current_location_no_error() {
|
||||
int main() {
|
||||
#if SIMDJSON_EXCEPTIONS
|
||||
basics_treewalk();
|
||||
basics_treewalk_breakline();
|
||||
#endif
|
||||
if (
|
||||
true
|
||||
|
||||
+30
-1
@@ -1,3 +1,4 @@
|
||||
#include <chrono>
|
||||
#include <iostream>
|
||||
#if (!(_MSC_VER) && !(__MINGW32__) && !(__MINGW64__))
|
||||
#include <dirent.h>
|
||||
@@ -38,6 +39,7 @@ int main(int argc, const char *argv[]) {
|
||||
}
|
||||
options.add_options()
|
||||
("a,arch", ss.str(), cxxopts::value<std::string>())
|
||||
("t,timing", "Report only timing.")
|
||||
("f,file", "File name.", cxxopts::value<std::string>())
|
||||
("h,help", "Print usage.")
|
||||
;
|
||||
@@ -79,7 +81,34 @@ int main(int argc, const char *argv[]) {
|
||||
size_t copy_len;
|
||||
error = simdjson::get_active_implementation()->minify((const uint8_t*)p.data(), p.length(), (uint8_t*)copy.data(), copy_len);
|
||||
if (error) { std::cerr << error << std::endl; return EXIT_FAILURE; }
|
||||
printf("%s", copy.data());
|
||||
/**
|
||||
* If a user only wants to time the required time, we do not output
|
||||
* the result and we simply do the processing in a tight loop.
|
||||
* At this point in time, we can assume that the processing will
|
||||
* succeed.
|
||||
*/
|
||||
if(result.count("timing")) {
|
||||
uint64_t beforens = std::chrono::duration_cast<::std::chrono::nanoseconds>(
|
||||
std::chrono::steady_clock::now().time_since_epoch())
|
||||
.count();
|
||||
error = simdjson::get_active_implementation()->minify((const uint8_t*)p.data(), p.length(), (uint8_t*)copy.data(), copy_len);
|
||||
uint64_t afterns = std::chrono::duration_cast<::std::chrono::nanoseconds>(
|
||||
std::chrono::steady_clock::now().time_since_epoch())
|
||||
.count();
|
||||
size_t times = 1;
|
||||
while(afterns - beforens < 1000000000) {
|
||||
error = simdjson::get_active_implementation()->minify((const uint8_t*)p.data(), p.length(), (uint8_t*)copy.data(), copy_len);
|
||||
afterns = std::chrono::duration_cast<::std::chrono::nanoseconds>(
|
||||
std::chrono::steady_clock::now().time_since_epoch())
|
||||
.count();
|
||||
times += 1;
|
||||
}
|
||||
if (error) { std::cerr << error << std::endl; return EXIT_FAILURE; }
|
||||
printf("%.3f GB/s\n", double(p.length() * times) / double(afterns - beforens));
|
||||
} else {
|
||||
// This is the expected path:
|
||||
printf("%s", copy.data());
|
||||
}
|
||||
return EXIT_SUCCESS;
|
||||
#ifdef __cpp_exceptions
|
||||
} catch (const cxxopts::OptionException& e) {
|
||||
|
||||
Reference in New Issue
Block a user