From 65148b123b3f8adf47bb4e1b4175004434d80917 Mon Sep 17 00:00:00 2001 From: John Keiser Date: Fri, 24 Jul 2020 07:32:12 -0700 Subject: [PATCH 1/5] Put anonymous namespace in front of everything --- src/arm64/bitmanipulation.h | 2 ++ src/arm64/bitmask.h | 1 + src/arm64/dom_parser_implementation.cpp | 20 ++++++++++++ src/arm64/implementation.cpp | 2 ++ src/arm64/implementation.h | 2 ++ src/arm64/numberparsing.h | 2 ++ src/arm64/simd.h | 2 ++ src/arm64/stringparsing.h | 2 ++ src/fallback/bitmanipulation.h | 2 ++ src/fallback/dom_parser_implementation.cpp | 19 ++++++++++++ src/fallback/implementation.cpp | 2 ++ src/fallback/implementation.h | 2 ++ src/fallback/numberparsing.h | 2 ++ src/fallback/stringparsing.h | 2 ++ src/generic/dom_parser_implementation.h | 4 +++ src/generic/stage1/allocate.h | 2 ++ src/generic/stage1/buf_block_reader.h | 2 ++ src/generic/stage1/find_next_document_index.h | 2 ++ src/generic/stage1/json_minifier.h | 2 ++ src/generic/stage1/json_scanner.h | 2 ++ src/generic/stage1/json_string_scanner.h | 2 ++ src/generic/stage1/json_structural_indexer.h | 2 ++ .../stage1/utf8_fastvalidate_algorithm.h | 1 + src/generic/stage1/utf8_lookup2_algorithm.h | 6 ++-- src/generic/stage1/utf8_lookup3_algorithm.h | 6 ++-- src/generic/stage1/utf8_lookup4_algorithm.h | 3 +- src/generic/stage1/utf8_lookup_algorithm.h | 7 ++--- src/generic/stage1/utf8_range_algorithm.h | 1 + src/generic/stage1/utf8_validator.h | 2 ++ src/generic/stage1/utf8_zwegner_algorithm.h | 1 + src/generic/stage2/allocate.h | 2 ++ src/generic/stage2/atomparsing.h | 4 +-- src/generic/stage2/jsoncharutils.h | 2 ++ src/generic/stage2/logger.h | 4 +++ src/generic/stage2/numberparsing.h | 2 ++ src/generic/stage2/stringparsing.h | 2 ++ src/generic/stage2/structural_iterator.h | 2 ++ src/generic/stage2/structural_parser.h | 31 ++----------------- src/generic/stage2/tape_writer.h | 2 ++ src/haswell/bitmanipulation.h | 2 ++ src/haswell/bitmask.h | 2 ++ src/haswell/dom_parser_implementation.cpp | 22 ++++++++++++- src/haswell/implementation.cpp | 2 ++ src/haswell/implementation.h | 2 ++ src/haswell/numberparsing.h | 2 ++ src/haswell/simd.h | 2 ++ src/haswell/stringparsing.h | 2 ++ src/westmere/bitmanipulation.h | 2 ++ src/westmere/bitmask.h | 2 ++ src/westmere/dom_parser_implementation.cpp | 21 +++++++++++++ src/westmere/implementation.cpp | 2 ++ src/westmere/implementation.h | 2 ++ src/westmere/numberparsing.h | 2 ++ src/westmere/simd.h | 2 ++ src/westmere/stringparsing.h | 2 ++ 55 files changed, 188 insertions(+), 41 deletions(-) diff --git a/src/arm64/bitmanipulation.h b/src/arm64/bitmanipulation.h index bb5a0afea..c9203530e 100644 --- a/src/arm64/bitmanipulation.h +++ b/src/arm64/bitmanipulation.h @@ -3,6 +3,7 @@ namespace simdjson { namespace arm64 { +namespace { // We sometimes call trailing_zero on inputs that are zero, // but the algorithms do not end up using the returned value. @@ -64,6 +65,7 @@ really_inline bool mul_overflow(uint64_t value1, uint64_t value2, uint64_t *resu #endif } +} // namespace { } // namespace arm64 } // namespace simdjson diff --git a/src/arm64/bitmask.h b/src/arm64/bitmask.h index 8e9530147..2c3094e27 100644 --- a/src/arm64/bitmask.h +++ b/src/arm64/bitmask.h @@ -3,6 +3,7 @@ namespace simdjson { namespace arm64 { +namespace { // // Perform a "cumulative bitwise xor," flipping bits each time a 1 is encountered. diff --git a/src/arm64/dom_parser_implementation.cpp b/src/arm64/dom_parser_implementation.cpp index 500631495..e512006ca 100644 --- a/src/arm64/dom_parser_implementation.cpp +++ b/src/arm64/dom_parser_implementation.cpp @@ -98,6 +98,7 @@ really_inline simd8 must_be_2_3_continuation(const simd8 prev2, c return is_third_byte ^ is_fourth_byte; } +} // namespace { } // namespace SIMDJSON_IMPLEMENTATION } // namespace simdjson @@ -120,6 +121,7 @@ namespace simdjson { namespace SIMDJSON_IMPLEMENTATION { namespace stage1 { +namespace { really_inline uint64_t json_string_scanner::find_escaped(uint64_t backslash) { // On ARM, we don't short-circuit this if there are no backslashes, because the branch gives us no @@ -128,6 +130,7 @@ really_inline uint64_t json_string_scanner::find_escaped(uint64_t backslash) { return find_escaped_branchless(backslash); } +} // namespace { } // namespace stage1 WARN_UNUSED error_code implementation::minify(const uint8_t *buf, size_t len, uint8_t *dst, size_t &dst_len) const noexcept { @@ -144,6 +147,23 @@ WARN_UNUSED bool implementation::validate_utf8(const char *buf, size_t len) cons return simdjson::arm64::stage1::generic_validate_utf8(buf,len); } +WARN_UNUSED error_code dom_parser_implementation::stage2(dom::document &_doc) noexcept { + error_code result = stage2::parse_structurals(*this, _doc); + if (result) { return result; } + + // If we didn't make it to the end, it's an error + if ( next_structural_index != n_structural_indexes ) { + logger::log_string("More than one JSON value at the root of the document, or extra characters at the end of the JSON!"); + return error = TAPE_ERROR; + } + + return SUCCESS; +} + +WARN_UNUSED error_code dom_parser_implementation::stage2_next(dom::document &_doc) noexcept { + return stage2::parse_structurals(*this, _doc); +} + WARN_UNUSED error_code dom_parser_implementation::parse(const uint8_t *_buf, size_t _len, dom::document &_doc) noexcept { error_code err = stage1(_buf, _len, false); if (err) { return err; } diff --git a/src/arm64/implementation.cpp b/src/arm64/implementation.cpp index a4b8958da..8a9a7984f 100644 --- a/src/arm64/implementation.cpp +++ b/src/arm64/implementation.cpp @@ -3,6 +3,7 @@ namespace simdjson { namespace SIMDJSON_IMPLEMENTATION { +namespace { WARN_UNUSED error_code implementation::create_dom_parser_implementation( size_t capacity, @@ -16,6 +17,7 @@ WARN_UNUSED error_code implementation::create_dom_parser_implementation( return SUCCESS; } +} // namespace { } // namespace SIMDJSON_IMPLEMENTATION } // namespace simdjson diff --git a/src/arm64/implementation.h b/src/arm64/implementation.h index 53a923fc2..b9eb7c571 100644 --- a/src/arm64/implementation.h +++ b/src/arm64/implementation.h @@ -6,6 +6,7 @@ namespace simdjson { namespace arm64 { +namespace { using namespace simdjson::dom; @@ -21,6 +22,7 @@ public: WARN_UNUSED bool validate_utf8(const char *buf, size_t len) const noexcept final; }; +} // namespace { } // namespace arm64 } // namespace simdjson diff --git a/src/arm64/numberparsing.h b/src/arm64/numberparsing.h index d8cc2db01..e0079170a 100644 --- a/src/arm64/numberparsing.h +++ b/src/arm64/numberparsing.h @@ -3,6 +3,7 @@ namespace simdjson { namespace arm64 { +namespace { // we don't have SSE, so let us use a scalar function // credit: https://johnnylee-sde.github.io/Fast-numeric-string-to-int/ @@ -14,6 +15,7 @@ static really_inline uint32_t parse_eight_digits_unrolled(const uint8_t *chars) return uint32_t((val & 0x0000FFFF0000FFFF) * 42949672960001 >> 32); } +} // namespace { } // namespace arm64 } // namespace simdjson diff --git a/src/arm64/simd.h b/src/arm64/simd.h index e36654278..d12e78293 100644 --- a/src/arm64/simd.h +++ b/src/arm64/simd.h @@ -9,6 +9,7 @@ namespace simdjson { namespace arm64 { +namespace { namespace simd { #ifdef SIMDJSON_REGULAR_VISUAL_STUDIO @@ -494,6 +495,7 @@ really_inline int8x16_t make_int8x16_t(int8_t x1, int8_t x2, int8_t x3, int8_ }; // struct simd8x64 } // namespace simd +} // namespace { } // namespace arm64 } // namespace simdjson diff --git a/src/arm64/stringparsing.h b/src/arm64/stringparsing.h index d6e55d6ec..91fb8d90a 100644 --- a/src/arm64/stringparsing.h +++ b/src/arm64/stringparsing.h @@ -7,6 +7,7 @@ namespace simdjson { namespace arm64 { +namespace { using namespace simd; @@ -43,6 +44,7 @@ really_inline backslash_and_quote backslash_and_quote::copy_and_find(const uint8 }; } +} // namespace { } // namespace arm64 } // namespace simdjson diff --git a/src/fallback/bitmanipulation.h b/src/fallback/bitmanipulation.h index 3574b651c..c85aa7b16 100644 --- a/src/fallback/bitmanipulation.h +++ b/src/fallback/bitmanipulation.h @@ -6,6 +6,7 @@ namespace simdjson { namespace fallback { +namespace { #if defined(_MSC_VER) && !defined(_M_ARM64) && !defined(_M_X64) static inline unsigned char _BitScanForward64(unsigned long* ret, uint64_t x) { @@ -71,6 +72,7 @@ really_inline bool mul_overflow(uint64_t value1, uint64_t value2, uint64_t *resu return value2 > 0 && value1 > std::numeric_limits::max() / value2; } +} // namespace { } // namespace fallback } // namespace simdjson diff --git a/src/fallback/dom_parser_implementation.cpp b/src/fallback/dom_parser_implementation.cpp index 980343324..0364762eb 100644 --- a/src/fallback/dom_parser_implementation.cpp +++ b/src/fallback/dom_parser_implementation.cpp @@ -9,6 +9,7 @@ namespace simdjson { namespace SIMDJSON_IMPLEMENTATION { +namespace { namespace stage1 { class structural_scanner { @@ -307,6 +308,7 @@ WARN_UNUSED bool implementation::validate_utf8(const char *buf, size_t len) cons return true; } +} // namespace { } // namespace SIMDJSON_IMPLEMENTATION } // namespace simdjson @@ -320,6 +322,23 @@ WARN_UNUSED bool implementation::validate_utf8(const char *buf, size_t len) cons namespace simdjson { namespace SIMDJSON_IMPLEMENTATION { +WARN_UNUSED error_code dom_parser_implementation::stage2(dom::document &_doc) noexcept { + error_code result = stage2::parse_structurals(*this, _doc); + if (result) { return result; } + + // If we didn't make it to the end, it's an error + if ( next_structural_index != n_structural_indexes ) { + logger::log_string("More than one JSON value at the root of the document, or extra characters at the end of the JSON!"); + return error = TAPE_ERROR; + } + + return SUCCESS; +} + +WARN_UNUSED error_code dom_parser_implementation::stage2_next(dom::document &_doc) noexcept { + return stage2::parse_structurals(*this, _doc); +} + WARN_UNUSED error_code dom_parser_implementation::parse(const uint8_t *_buf, size_t _len, dom::document &_doc) noexcept { error_code err = stage1(_buf, _len, false); if (err) { return err; } diff --git a/src/fallback/implementation.cpp b/src/fallback/implementation.cpp index 305e040c8..ff2a4f8cc 100644 --- a/src/fallback/implementation.cpp +++ b/src/fallback/implementation.cpp @@ -3,6 +3,7 @@ namespace simdjson { namespace SIMDJSON_IMPLEMENTATION { +namespace { WARN_UNUSED error_code implementation::create_dom_parser_implementation( size_t capacity, @@ -16,6 +17,7 @@ WARN_UNUSED error_code implementation::create_dom_parser_implementation( return SUCCESS; } +} // namespace { } // namespace SIMDJSON_IMPLEMENTATION } // namespace simdjson diff --git a/src/fallback/implementation.h b/src/fallback/implementation.h index 5b99218cd..540030990 100644 --- a/src/fallback/implementation.h +++ b/src/fallback/implementation.h @@ -6,6 +6,7 @@ namespace simdjson { namespace fallback { +namespace { using namespace simdjson::dom; @@ -25,6 +26,7 @@ public: WARN_UNUSED bool validate_utf8(const char *buf, size_t len) const noexcept final; }; +} // namespace { } // namespace fallback } // namespace simdjson diff --git a/src/fallback/numberparsing.h b/src/fallback/numberparsing.h index ef5bb422e..ce1e9b898 100644 --- a/src/fallback/numberparsing.h +++ b/src/fallback/numberparsing.h @@ -10,6 +10,7 @@ void found_float(double result, const uint8_t *buf); namespace simdjson { namespace SIMDJSON_IMPLEMENTATION { +namespace { static really_inline uint32_t parse_eight_digits_unrolled(const char *chars) { uint32_t result = 0; for (int i=0;i<8;i++) { @@ -21,6 +22,7 @@ static really_inline uint32_t parse_eight_digits_unrolled(const uint8_t *chars) return parse_eight_digits_unrolled((const char *)chars); } +} // namespace { } // namespace SIMDJSON_IMPLEMENTATION } // namespace simdjson diff --git a/src/fallback/stringparsing.h b/src/fallback/stringparsing.h index 1359740fd..4fed27e85 100644 --- a/src/fallback/stringparsing.h +++ b/src/fallback/stringparsing.h @@ -5,6 +5,7 @@ namespace simdjson { namespace fallback { +namespace { // Holds backslashes and quotes locations. struct backslash_and_quote { @@ -26,6 +27,7 @@ really_inline backslash_and_quote backslash_and_quote::copy_and_find(const uint8 return { src[0] }; } +} // namespace { } // namespace fallback } // namespace simdjson diff --git a/src/generic/dom_parser_implementation.h b/src/generic/dom_parser_implementation.h index ee59694b2..e242157b9 100644 --- a/src/generic/dom_parser_implementation.h +++ b/src/generic/dom_parser_implementation.h @@ -3,6 +3,7 @@ namespace simdjson { namespace SIMDJSON_IMPLEMENTATION { +namespace { // expectation: sizeof(scope_descriptor) = 64/8. struct scope_descriptor { @@ -44,6 +45,7 @@ public: WARN_UNUSED error_code set_max_depth(size_t max_depth) noexcept final; }; +} // namespace { } // namespace SIMDJSON_IMPLEMENTATION } // namespace simdjson @@ -52,6 +54,7 @@ public: namespace simdjson { namespace SIMDJSON_IMPLEMENTATION { +namespace { really_inline dom_parser_implementation::dom_parser_implementation() {} @@ -70,5 +73,6 @@ WARN_UNUSED error_code dom_parser_implementation::set_max_depth(size_t max_depth return SUCCESS; } +} // namespace { } // namespace SIMDJSON_IMPLEMENTATION } // namespace simdjson diff --git a/src/generic/stage1/allocate.h b/src/generic/stage1/allocate.h index e9ecb07e4..5a57e0700 100644 --- a/src/generic/stage1/allocate.h +++ b/src/generic/stage1/allocate.h @@ -1,5 +1,6 @@ namespace simdjson { namespace SIMDJSON_IMPLEMENTATION { +namespace { namespace stage1 { namespace allocate { @@ -17,5 +18,6 @@ really_inline error_code set_capacity(internal::dom_parser_implementation &parse } // namespace allocate } // namespace stage1 +} // namespace { } // namespace SIMDJSON_IMPLEMENTATION } // namespace simdjson diff --git a/src/generic/stage1/buf_block_reader.h b/src/generic/stage1/buf_block_reader.h index 6eb28cc71..ca25d1eed 100644 --- a/src/generic/stage1/buf_block_reader.h +++ b/src/generic/stage1/buf_block_reader.h @@ -1,5 +1,6 @@ namespace simdjson { namespace SIMDJSON_IMPLEMENTATION { +namespace { // Walks through a buffer in block-sized increments, loading the last part with spaces template @@ -85,5 +86,6 @@ really_inline void buf_block_reader::advance() { idx += STEP_SIZE; } +} // namespace { } // namespace SIMDJSON_IMPLEMENTATION } // namespace simdjson diff --git a/src/generic/stage1/find_next_document_index.h b/src/generic/stage1/find_next_document_index.h index 7e42d7f32..acbd3a0e0 100644 --- a/src/generic/stage1/find_next_document_index.h +++ b/src/generic/stage1/find_next_document_index.h @@ -1,5 +1,6 @@ namespace simdjson { namespace SIMDJSON_IMPLEMENTATION { +namespace { /** * This algorithm is used to quickly identify the last structural position that @@ -88,5 +89,6 @@ really_inline size_t trim_partial_utf8(const uint8_t *buf, size_t len) { return len; } +} // namespace { } // namespace SIMDJSON_IMPLEMENTATION } // namespace simdjson diff --git a/src/generic/stage1/json_minifier.h b/src/generic/stage1/json_minifier.h index 46bfd4e52..e567418c5 100644 --- a/src/generic/stage1/json_minifier.h +++ b/src/generic/stage1/json_minifier.h @@ -5,6 +5,7 @@ namespace simdjson { namespace SIMDJSON_IMPLEMENTATION { +namespace { namespace stage1 { class json_minifier { @@ -77,5 +78,6 @@ error_code json_minifier::minify(const uint8_t *buf, size_t len, uint8_t *dst, s } } // namespace stage1 +} // namespace { } // namespace SIMDJSON_IMPLEMENTATION } // namespace simdjson diff --git a/src/generic/stage1/json_scanner.h b/src/generic/stage1/json_scanner.h index 8544a8cff..7a9e05e1e 100644 --- a/src/generic/stage1/json_scanner.h +++ b/src/generic/stage1/json_scanner.h @@ -1,5 +1,6 @@ namespace simdjson { namespace SIMDJSON_IMPLEMENTATION { +namespace { namespace stage1 { /** @@ -104,5 +105,6 @@ really_inline error_code json_scanner::finish(bool streaming) { } } // namespace stage1 +} // namespace { } // namespace SIMDJSON_IMPLEMENTATION } // namespace simdjson diff --git a/src/generic/stage1/json_string_scanner.h b/src/generic/stage1/json_string_scanner.h index 24d24d8ce..c53a9bac9 100644 --- a/src/generic/stage1/json_string_scanner.h +++ b/src/generic/stage1/json_string_scanner.h @@ -1,5 +1,6 @@ namespace simdjson { namespace SIMDJSON_IMPLEMENTATION { +namespace { namespace stage1 { struct json_string_block { @@ -139,5 +140,6 @@ really_inline error_code json_string_scanner::finish(bool streaming) { } } // namespace stage1 +} // namespace { } // namespace SIMDJSON_IMPLEMENTATION } // namespace simdjson diff --git a/src/generic/stage1/json_structural_indexer.h b/src/generic/stage1/json_structural_indexer.h index c08833418..16c497cb5 100644 --- a/src/generic/stage1/json_structural_indexer.h +++ b/src/generic/stage1/json_structural_indexer.h @@ -11,6 +11,7 @@ namespace simdjson { namespace SIMDJSON_IMPLEMENTATION { +namespace { namespace stage1 { class bit_indexer { @@ -204,5 +205,6 @@ really_inline error_code json_structural_indexer::finish(dom_parser_implementati } } // namespace stage1 +} // namespace { } // namespace SIMDJSON_IMPLEMENTATION } // namespace simdjson diff --git a/src/generic/stage1/utf8_fastvalidate_algorithm.h b/src/generic/stage1/utf8_fastvalidate_algorithm.h index fb9b95dc4..24adaeebe 100644 --- a/src/generic/stage1/utf8_fastvalidate_algorithm.h +++ b/src/generic/stage1/utf8_fastvalidate_algorithm.h @@ -180,5 +180,6 @@ struct utf8_checker { } }; // struct utf8_checker +} // namespace { } // namespace SIMDJSON_IMPLEMENTATION } // namespace simdjson diff --git a/src/generic/stage1/utf8_lookup2_algorithm.h b/src/generic/stage1/utf8_lookup2_algorithm.h index 6badfa077..9be898988 100644 --- a/src/generic/stage1/utf8_lookup2_algorithm.h +++ b/src/generic/stage1/utf8_lookup2_algorithm.h @@ -1,5 +1,7 @@ namespace simdjson { namespace SIMDJSON_IMPLEMENTATION { +namespace { +namespace utf8_validation { // // Detect Unicode errors. @@ -66,7 +68,6 @@ namespace SIMDJSON_IMPLEMENTATION { // using namespace simd; -namespace utf8_validation { // For a detailed description of the lookup2 algorithm, see the file HACKING.md under "UTF-8 validation (lookup2)". // @@ -216,7 +217,8 @@ namespace utf8_validation { } }; // struct utf8_checker -} +} // namespace { +} // namespace utf8_validation using utf8_validation::utf8_checker; diff --git a/src/generic/stage1/utf8_lookup3_algorithm.h b/src/generic/stage1/utf8_lookup3_algorithm.h index c8e439c29..641b8005f 100644 --- a/src/generic/stage1/utf8_lookup3_algorithm.h +++ b/src/generic/stage1/utf8_lookup3_algorithm.h @@ -1,5 +1,7 @@ namespace simdjson { namespace SIMDJSON_IMPLEMENTATION { +namespace { +namespace utf8_validation { // // Detect Unicode errors. @@ -66,7 +68,6 @@ namespace SIMDJSON_IMPLEMENTATION { // using namespace simd; -namespace utf8_validation { // For a detailed description of the lookup2 algorithm, see the file HACKING.md under "UTF-8 validation (lookup2)". // @@ -236,7 +237,8 @@ namespace utf8_validation { } }; // struct utf8_checker -} +} // namespace { +} // namespace utf8_validation using utf8_validation::utf8_checker; diff --git a/src/generic/stage1/utf8_lookup4_algorithm.h b/src/generic/stage1/utf8_lookup4_algorithm.h index 1bb0fcac2..2deeafde7 100644 --- a/src/generic/stage1/utf8_lookup4_algorithm.h +++ b/src/generic/stage1/utf8_lookup4_algorithm.h @@ -1,6 +1,6 @@ namespace simdjson { namespace SIMDJSON_IMPLEMENTATION { - +namespace { namespace utf8_validation { using namespace simd; @@ -174,6 +174,7 @@ using namespace simd; } }; // struct utf8_checker +} // namespace { } // namespace utf8_validation using utf8_validation::utf8_checker; diff --git a/src/generic/stage1/utf8_lookup_algorithm.h b/src/generic/stage1/utf8_lookup_algorithm.h index 4ad9b1fb8..9462b2ddf 100644 --- a/src/generic/stage1/utf8_lookup_algorithm.h +++ b/src/generic/stage1/utf8_lookup_algorithm.h @@ -1,5 +1,6 @@ namespace simdjson { namespace SIMDJSON_IMPLEMENTATION { +namespace utf8_validation { // // Detect Unicode errors. @@ -66,10 +67,6 @@ namespace SIMDJSON_IMPLEMENTATION { // using namespace simd; -namespace utf8_validation { - -} // namespace utf8_validation - struct utf8_checker { // If this is nonzero, there has been a UTF-8 error. simd8 error; @@ -301,5 +298,7 @@ struct utf8_checker { }; // struct utf8_checker +} // namespace utf8_validation +} // namespace { } // namespace SIMDJSON_IMPLEMENTATION } // namespace simdjson diff --git a/src/generic/stage1/utf8_range_algorithm.h b/src/generic/stage1/utf8_range_algorithm.h index ac301bb8f..f4b479eb6 100644 --- a/src/generic/stage1/utf8_range_algorithm.h +++ b/src/generic/stage1/utf8_range_algorithm.h @@ -182,5 +182,6 @@ struct utf8_checker { } }; // struct utf8_checker +} // namespace { } // namespace SIMDJSON_IMPLEMENTATION } // namespace simdjson diff --git a/src/generic/stage1/utf8_validator.h b/src/generic/stage1/utf8_validator.h index 5e50166e2..3c2765b45 100644 --- a/src/generic/stage1/utf8_validator.h +++ b/src/generic/stage1/utf8_validator.h @@ -1,5 +1,6 @@ namespace simdjson { namespace SIMDJSON_IMPLEMENTATION { +namespace { namespace stage1 { /** @@ -27,5 +28,6 @@ bool generic_validate_utf8(const char * input, size_t length) { } } // namespace stage1 +} // namespace { } // namespace SIMDJSON_IMPLEMENTATION } // namespace simdjson diff --git a/src/generic/stage1/utf8_zwegner_algorithm.h b/src/generic/stage1/utf8_zwegner_algorithm.h index be81648cd..b8a7bd807 100644 --- a/src/generic/stage1/utf8_zwegner_algorithm.h +++ b/src/generic/stage1/utf8_zwegner_algorithm.h @@ -361,5 +361,6 @@ struct utf8_checker { } }; // struct utf8_checker +} // namespace { } // namespace SIMDJSON_IMPLEMENTATION } // namespace simdjson diff --git a/src/generic/stage2/allocate.h b/src/generic/stage2/allocate.h index e33a48472..5d9bdb352 100644 --- a/src/generic/stage2/allocate.h +++ b/src/generic/stage2/allocate.h @@ -1,5 +1,6 @@ namespace simdjson { namespace SIMDJSON_IMPLEMENTATION { +namespace { namespace stage2 { namespace allocate { @@ -18,5 +19,6 @@ really_inline error_code set_max_depth(dom_parser_implementation &parser, size_t } // namespace allocate } // namespace stage2 +} // namespace { } // namespace SIMDJSON_IMPLEMENTATION } // namespace simdjson diff --git a/src/generic/stage2/atomparsing.h b/src/generic/stage2/atomparsing.h index c0d5f78fc..26ffa5221 100644 --- a/src/generic/stage2/atomparsing.h +++ b/src/generic/stage2/atomparsing.h @@ -1,9 +1,9 @@ namespace simdjson { namespace SIMDJSON_IMPLEMENTATION { +namespace { namespace stage2 { namespace atomparsing { -namespace{ // The string_to_uint32 is exclusively used to map literal strings to 32-bit values. // We use memcpy instead of a pointer cast to avoid undefined behaviors since we cannot // be certain that the character pointer will be properly aligned. @@ -22,7 +22,6 @@ really_inline uint32_t str4ncmp(const uint8_t *src, const char* atom) { std::memcpy(&srcval, src, sizeof(uint32_t)); return srcval ^ string_to_uint32(atom); } -} // anonymous namespace WARN_UNUSED really_inline bool is_valid_true_atom(const uint8_t *src) { @@ -62,5 +61,6 @@ really_inline bool is_valid_null_atom(const uint8_t *src, size_t len) { } // namespace atomparsing } // namespace stage2 +} // namespace { } // namespace SIMDJSON_IMPLEMENTATION } // namespace simdjson diff --git a/src/generic/stage2/jsoncharutils.h b/src/generic/stage2/jsoncharutils.h index 5a66bcdac..e560a1eba 100644 --- a/src/generic/stage2/jsoncharutils.h +++ b/src/generic/stage2/jsoncharutils.h @@ -1,5 +1,6 @@ namespace simdjson { namespace SIMDJSON_IMPLEMENTATION { +namespace { namespace stage2 { // return non-zero if not a structural or whitespace char @@ -115,5 +116,6 @@ really_inline value128 full_multiplication(uint64_t value1, uint64_t value2) { } } // namespace stage2 +} // namespace { } // namespace SIMDJSON_IMPLEMENTATION } // namespace simdjson diff --git a/src/generic/stage2/logger.h b/src/generic/stage2/logger.h index 9da6c1ef9..dfafb6f68 100644 --- a/src/generic/stage2/logger.h +++ b/src/generic/stage2/logger.h @@ -2,7 +2,9 @@ // Set LOG_ENABLED = true to log what stage 2 is doing! namespace simdjson { namespace SIMDJSON_IMPLEMENTATION { +namespace { namespace logger { + static constexpr const char * DASHES = "----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------"; static constexpr const bool LOG_ENABLED = false; @@ -62,6 +64,8 @@ namespace logger { printf("|\n"); } } + } // namespace logger +} // namespace { } // namespace SIMDJSON_IMPLEMENTATION } // namespace simdjson diff --git a/src/generic/stage2/numberparsing.h b/src/generic/stage2/numberparsing.h index 8a8fb3907..94059e51d 100644 --- a/src/generic/stage2/numberparsing.h +++ b/src/generic/stage2/numberparsing.h @@ -3,6 +3,7 @@ namespace simdjson { namespace SIMDJSON_IMPLEMENTATION { +namespace { namespace stage2 { namespace numberparsing { @@ -504,5 +505,6 @@ really_inline bool parse_number(const uint8_t *const src, W &writer) { } // namespace numberparsing } // namespace stage2 +} // namespace { } // namespace SIMDJSON_IMPLEMENTATION } // namespace simdjson diff --git a/src/generic/stage2/stringparsing.h b/src/generic/stage2/stringparsing.h index ad144d5dd..b2568e282 100644 --- a/src/generic/stage2/stringparsing.h +++ b/src/generic/stage2/stringparsing.h @@ -3,6 +3,7 @@ namespace simdjson { namespace SIMDJSON_IMPLEMENTATION { +namespace { namespace stage2 { namespace stringparsing { @@ -121,5 +122,6 @@ WARN_UNUSED really_inline uint8_t *parse_string(const uint8_t *src, uint8_t *dst } // namespace stringparsing } // namespace stage2 +} // namespace { } // namespace SIMDJSON_IMPLEMENTATION } // namespace simdjson diff --git a/src/generic/stage2/structural_iterator.h b/src/generic/stage2/structural_iterator.h index c1c7b759c..c849f9a21 100644 --- a/src/generic/stage2/structural_iterator.h +++ b/src/generic/stage2/structural_iterator.h @@ -1,5 +1,6 @@ namespace simdjson { namespace SIMDJSON_IMPLEMENTATION { +namespace { namespace stage2 { class structural_iterator { @@ -46,5 +47,6 @@ public: }; } // namespace stage2 +} // namespace { } // namespace SIMDJSON_IMPLEMENTATION } // namespace simdjson diff --git a/src/generic/stage2/structural_parser.h b/src/generic/stage2/structural_parser.h index 52e2ffa34..f6cd15db5 100644 --- a/src/generic/stage2/structural_parser.h +++ b/src/generic/stage2/structural_parser.h @@ -10,9 +10,8 @@ namespace simdjson { namespace SIMDJSON_IMPLEMENTATION { -namespace stage2 { - namespace { // Make everything here private +namespace stage2 { #ifdef SIMDJSON_USE_COMPUTED_GOTO #define INIT_ADDRESSES() { &&array_begin, &&array_continue, &&error, &&finish, &&object_begin, &&object_continue } @@ -468,33 +467,7 @@ error: return parser.error(); } -} // namespace {} } // namespace stage2 - -/************ - * The JSON is parsed to a tape, see the accompanying tape.md file - * for documentation. - ***********/ -WARN_UNUSED error_code dom_parser_implementation::stage2(dom::document &_doc) noexcept { - error_code result = stage2::parse_structurals(*this, _doc); - if (result) { return result; } - - // If we didn't make it to the end, it's an error - if ( next_structural_index != n_structural_indexes ) { - logger::log_string("More than one JSON value at the root of the document, or extra characters at the end of the JSON!"); - return error = TAPE_ERROR; - } - - return SUCCESS; -} - -/************ - * The JSON is parsed to a tape, see the accompanying tape.md file - * for documentation. - ***********/ -WARN_UNUSED error_code dom_parser_implementation::stage2_next(dom::document &_doc) noexcept { - return stage2::parse_structurals(*this, _doc); -} - +} // namespace { } // namespace SIMDJSON_IMPLEMENTATION } // namespace simdjson diff --git a/src/generic/stage2/tape_writer.h b/src/generic/stage2/tape_writer.h index aed7e91f3..8c9f8c4b2 100644 --- a/src/generic/stage2/tape_writer.h +++ b/src/generic/stage2/tape_writer.h @@ -1,5 +1,6 @@ namespace simdjson { namespace SIMDJSON_IMPLEMENTATION { +namespace { namespace stage2 { struct tape_writer { @@ -99,5 +100,6 @@ really_inline void tape_writer::write(uint64_t &tape_loc, uint64_t val, internal } } // namespace stage2 +} // namespace { } // namespace SIMDJSON_IMPLEMENTATION } // namespace simdjson diff --git a/src/haswell/bitmanipulation.h b/src/haswell/bitmanipulation.h index 78c56795f..51ce7437c 100644 --- a/src/haswell/bitmanipulation.h +++ b/src/haswell/bitmanipulation.h @@ -3,6 +3,7 @@ namespace simdjson { namespace SIMDJSON_IMPLEMENTATION { +namespace { // We sometimes call trailing_zero on inputs that are zero, // but the algorithms do not end up using the returned value. @@ -68,6 +69,7 @@ really_inline bool mul_overflow(uint64_t value1, uint64_t value2, #endif } +} // namespace { } // namespace SIMDJSON_IMPLEMENTATION } // namespace simdjson diff --git a/src/haswell/bitmask.h b/src/haswell/bitmask.h index b29c66680..b5d0727b8 100644 --- a/src/haswell/bitmask.h +++ b/src/haswell/bitmask.h @@ -3,6 +3,7 @@ namespace simdjson { namespace SIMDJSON_IMPLEMENTATION { +namespace { // // Perform a "cumulative bitwise xor," flipping bits each time a 1 is encountered. @@ -17,6 +18,7 @@ really_inline uint64_t prefix_xor(const uint64_t bitmask) { return _mm_cvtsi128_si64(result); } +} // namespace { } // namespace SIMDJSON_IMPLEMENTATION } // namespace simdjson diff --git a/src/haswell/dom_parser_implementation.cpp b/src/haswell/dom_parser_implementation.cpp index 345b01506..cd35619b1 100644 --- a/src/haswell/dom_parser_implementation.cpp +++ b/src/haswell/dom_parser_implementation.cpp @@ -8,6 +8,7 @@ namespace simdjson { namespace SIMDJSON_IMPLEMENTATION { +namespace { using namespace simd; @@ -64,6 +65,7 @@ really_inline simd8 must_be_2_3_continuation(const simd8 prev2, c return simd8(is_third_byte | is_fourth_byte) > int8_t(0); } +} // namespace { } // namespace SIMDJSON_IMPLEMENTATION } // namespace simdjson @@ -83,7 +85,7 @@ really_inline simd8 must_be_2_3_continuation(const simd8 prev2, c // namespace simdjson { namespace SIMDJSON_IMPLEMENTATION { - +namespace { namespace stage1 { really_inline uint64_t json_string_scanner::find_escaped(uint64_t backslash) { @@ -92,6 +94,7 @@ really_inline uint64_t json_string_scanner::find_escaped(uint64_t backslash) { } } // namespace stage1 +} // namespace { WARN_UNUSED error_code implementation::minify(const uint8_t *buf, size_t len, uint8_t *dst, size_t &dst_len) const noexcept { return haswell::stage1::json_minifier::minify<128>(buf, len, dst, dst_len); @@ -107,6 +110,23 @@ WARN_UNUSED bool implementation::validate_utf8(const char *buf, size_t len) cons return simdjson::haswell::stage1::generic_validate_utf8(buf,len); } +WARN_UNUSED error_code dom_parser_implementation::stage2(dom::document &_doc) noexcept { + error_code result = stage2::parse_structurals(*this, _doc); + if (result) { return result; } + + // If we didn't make it to the end, it's an error + if ( next_structural_index != n_structural_indexes ) { + logger::log_string("More than one JSON value at the root of the document, or extra characters at the end of the JSON!"); + return error = TAPE_ERROR; + } + + return SUCCESS; +} + +WARN_UNUSED error_code dom_parser_implementation::stage2_next(dom::document &_doc) noexcept { + return stage2::parse_structurals(*this, _doc); +} + WARN_UNUSED error_code dom_parser_implementation::parse(const uint8_t *_buf, size_t _len, dom::document &_doc) noexcept { error_code err = stage1(_buf, _len, false); if (err) { return err; } diff --git a/src/haswell/implementation.cpp b/src/haswell/implementation.cpp index 09c38abad..45f5b4fe8 100644 --- a/src/haswell/implementation.cpp +++ b/src/haswell/implementation.cpp @@ -3,6 +3,7 @@ namespace simdjson { namespace SIMDJSON_IMPLEMENTATION { +namespace { WARN_UNUSED error_code implementation::create_dom_parser_implementation( size_t capacity, @@ -16,6 +17,7 @@ WARN_UNUSED error_code implementation::create_dom_parser_implementation( return SUCCESS; } +} // namespace { } // namespace SIMDJSON_IMPLEMENTATION } // namespace simdjson diff --git a/src/haswell/implementation.h b/src/haswell/implementation.h index efd20e30d..b2a549324 100644 --- a/src/haswell/implementation.h +++ b/src/haswell/implementation.h @@ -7,6 +7,7 @@ // The constructor may be executed on any host, so we take care not to use SIMDJSON_TARGET_REGION namespace simdjson { namespace haswell { +namespace { class implementation final : public simdjson::implementation { public: @@ -24,6 +25,7 @@ public: WARN_UNUSED bool validate_utf8(const char *buf, size_t len) const noexcept final; }; +} // namespace { } // namespace haswell } // namespace simdjson diff --git a/src/haswell/numberparsing.h b/src/haswell/numberparsing.h index e412adce7..547d3baba 100644 --- a/src/haswell/numberparsing.h +++ b/src/haswell/numberparsing.h @@ -3,6 +3,7 @@ namespace simdjson { namespace SIMDJSON_IMPLEMENTATION { +namespace { static really_inline uint32_t parse_eight_digits_unrolled(const uint8_t *chars) { // this actually computes *16* values so we are being wasteful. @@ -22,6 +23,7 @@ static really_inline uint32_t parse_eight_digits_unrolled(const uint8_t *chars) t4); // only captures the sum of the first 8 digits, drop the rest } +} // namespace { } // namespace SIMDJSON_IMPLEMENTATION } // namespace simdjson diff --git a/src/haswell/simd.h b/src/haswell/simd.h index 3cd068000..26e13de41 100644 --- a/src/haswell/simd.h +++ b/src/haswell/simd.h @@ -5,6 +5,7 @@ namespace simdjson { namespace SIMDJSON_IMPLEMENTATION { +namespace { namespace simd { // Forward-declared so they can be used by splat and friends. @@ -346,6 +347,7 @@ namespace simd { } }; // struct simd8x64 +} // namespace { } // namespace simd } // namespace SIMDJSON_IMPLEMENTATION diff --git a/src/haswell/stringparsing.h b/src/haswell/stringparsing.h index 63b3a233d..575745460 100644 --- a/src/haswell/stringparsing.h +++ b/src/haswell/stringparsing.h @@ -7,6 +7,7 @@ namespace simdjson { namespace SIMDJSON_IMPLEMENTATION { +namespace { using namespace simd; @@ -38,6 +39,7 @@ really_inline backslash_and_quote backslash_and_quote::copy_and_find(const uint8 }; } +} // namespace { } // namespace SIMDJSON_IMPLEMENTATION } // namespace simdjson diff --git a/src/westmere/bitmanipulation.h b/src/westmere/bitmanipulation.h index a621381da..641a5ac9b 100644 --- a/src/westmere/bitmanipulation.h +++ b/src/westmere/bitmanipulation.h @@ -3,6 +3,7 @@ namespace simdjson { namespace SIMDJSON_IMPLEMENTATION { +namespace { // We sometimes call trailing_zero on inputs that are zero, // but the algorithms do not end up using the returned value. @@ -77,6 +78,7 @@ really_inline bool mul_overflow(uint64_t value1, uint64_t value2, #endif } +} // namespace { } // namespace SIMDJSON_IMPLEMENTATION } // namespace simdjson diff --git a/src/westmere/bitmask.h b/src/westmere/bitmask.h index 79813fac6..2da19c90c 100644 --- a/src/westmere/bitmask.h +++ b/src/westmere/bitmask.h @@ -3,6 +3,7 @@ namespace simdjson { namespace SIMDJSON_IMPLEMENTATION { +namespace { // // Perform a "cumulative bitwise xor," flipping bits each time a 1 is encountered. @@ -17,6 +18,7 @@ really_inline uint64_t prefix_xor(const uint64_t bitmask) { return _mm_cvtsi128_si64(result); } +} // namespace { } // namespace SIMDJSON_IMPLEMENTATION } // namespace simdjson diff --git a/src/westmere/dom_parser_implementation.cpp b/src/westmere/dom_parser_implementation.cpp index 32c0fdd0f..d158cbf99 100644 --- a/src/westmere/dom_parser_implementation.cpp +++ b/src/westmere/dom_parser_implementation.cpp @@ -8,6 +8,7 @@ namespace simdjson { namespace SIMDJSON_IMPLEMENTATION { +namespace { using namespace simd; @@ -69,6 +70,7 @@ really_inline simd8 must_be_2_3_continuation(const simd8 prev2, c return simd8(is_third_byte | is_fourth_byte) > int8_t(0); } +} // namespace { } // namespace SIMDJSON_IMPLEMENTATION } // namespace simdjson @@ -89,6 +91,7 @@ really_inline simd8 must_be_2_3_continuation(const simd8 prev2, c namespace simdjson { namespace SIMDJSON_IMPLEMENTATION { +namespace { namespace stage1 { really_inline uint64_t json_string_scanner::find_escaped(uint64_t backslash) { @@ -97,6 +100,7 @@ really_inline uint64_t json_string_scanner::find_escaped(uint64_t backslash) { } } // namespace stage1 +} // namespace { WARN_UNUSED error_code implementation::minify(const uint8_t *buf, size_t len, uint8_t *dst, size_t &dst_len) const noexcept { return westmere::stage1::json_minifier::minify<64>(buf, len, dst, dst_len); @@ -112,6 +116,23 @@ WARN_UNUSED bool implementation::validate_utf8(const char *buf, size_t len) cons return simdjson::westmere::stage1::generic_validate_utf8(buf,len); } +WARN_UNUSED error_code dom_parser_implementation::stage2(dom::document &_doc) noexcept { + error_code result = stage2::parse_structurals(*this, _doc); + if (result) { return result; } + + // If we didn't make it to the end, it's an error + if ( next_structural_index != n_structural_indexes ) { + logger::log_string("More than one JSON value at the root of the document, or extra characters at the end of the JSON!"); + return error = TAPE_ERROR; + } + + return SUCCESS; +} + +WARN_UNUSED error_code dom_parser_implementation::stage2_next(dom::document &_doc) noexcept { + return stage2::parse_structurals(*this, _doc); +} + WARN_UNUSED error_code dom_parser_implementation::parse(const uint8_t *_buf, size_t _len, dom::document &_doc) noexcept { error_code err = stage1(_buf, _len, false); if (err) { return err; } diff --git a/src/westmere/implementation.cpp b/src/westmere/implementation.cpp index e166210b0..e39efb02a 100644 --- a/src/westmere/implementation.cpp +++ b/src/westmere/implementation.cpp @@ -3,6 +3,7 @@ namespace simdjson { namespace SIMDJSON_IMPLEMENTATION { +namespace { WARN_UNUSED error_code implementation::create_dom_parser_implementation( size_t capacity, @@ -16,6 +17,7 @@ WARN_UNUSED error_code implementation::create_dom_parser_implementation( return SUCCESS; } +} // namespace { } // namespace SIMDJSON_IMPLEMENTATION } // namespace simdjson diff --git a/src/westmere/implementation.h b/src/westmere/implementation.h index 3fe8e6ac5..453c065dd 100644 --- a/src/westmere/implementation.h +++ b/src/westmere/implementation.h @@ -8,6 +8,7 @@ // The constructor may be executed on any host, so we take care not to use SIMDJSON_TARGET_REGION namespace simdjson { namespace westmere { +namespace { using namespace simdjson::dom; @@ -23,6 +24,7 @@ public: WARN_UNUSED bool validate_utf8(const char *buf, size_t len) const noexcept final; }; +} // namespace { } // namespace westmere } // namespace simdjson diff --git a/src/westmere/numberparsing.h b/src/westmere/numberparsing.h index 31b8bf5e4..c72a14564 100644 --- a/src/westmere/numberparsing.h +++ b/src/westmere/numberparsing.h @@ -3,6 +3,7 @@ namespace simdjson { namespace SIMDJSON_IMPLEMENTATION { +namespace { static really_inline uint32_t parse_eight_digits_unrolled(const uint8_t *chars) { // this actually computes *16* values so we are being wasteful. @@ -22,6 +23,7 @@ static really_inline uint32_t parse_eight_digits_unrolled(const uint8_t *chars) t4); // only captures the sum of the first 8 digits, drop the rest } +} // namespace { } // namespace SIMDJSON_IMPLEMENTATION } // namespace simdjson diff --git a/src/westmere/simd.h b/src/westmere/simd.h index 41eb3e273..bcb7db9b4 100644 --- a/src/westmere/simd.h +++ b/src/westmere/simd.h @@ -5,6 +5,7 @@ namespace simdjson { namespace SIMDJSON_IMPLEMENTATION { +namespace { namespace simd { template @@ -327,6 +328,7 @@ namespace simd { }; // struct simd8x64 } // namespace simd +} // namespace { } // namespace SIMDJSON_IMPLEMENTATION } // namespace simdjson diff --git a/src/westmere/stringparsing.h b/src/westmere/stringparsing.h index fa5033166..7eab837e4 100644 --- a/src/westmere/stringparsing.h +++ b/src/westmere/stringparsing.h @@ -3,6 +3,7 @@ namespace simdjson { namespace SIMDJSON_IMPLEMENTATION { +namespace { using namespace simd; @@ -36,6 +37,7 @@ really_inline backslash_and_quote backslash_and_quote::copy_and_find(const uint8 }; } +} // namespace { } // namespace SIMDJSON_IMPLEMENTATION } // namespace simdjson From c7fa9b5fe804c7f99cb696dc956058a1f8363224 Mon Sep 17 00:00:00 2001 From: John Keiser Date: Fri, 24 Jul 2020 08:09:34 -0700 Subject: [PATCH 2/5] Make entire implementation namespaces anonymous --- src/arm64/bitmanipulation.h | 6 ++---- src/arm64/bitmask.h | 3 +-- src/arm64/dom_parser_implementation.cpp | 14 +++++--------- src/arm64/implementation.cpp | 6 ++---- src/arm64/implementation.h | 7 +++---- src/arm64/numberparsing.h | 6 ++---- src/arm64/simd.h | 6 ++---- src/arm64/stringparsing.h | 6 ++---- src/fallback/bitmanipulation.h | 6 ++---- src/fallback/dom_parser_implementation.cpp | 10 ++++------ src/fallback/implementation.cpp | 6 ++---- src/fallback/implementation.h | 7 +++---- src/fallback/numberparsing.h | 6 ++---- src/fallback/stringparsing.h | 6 ++---- src/generic/dom_parser_implementation.h | 12 ++++-------- src/generic/stage1/allocate.h | 6 ++---- src/generic/stage1/buf_block_reader.h | 6 ++---- src/generic/stage1/find_next_document_index.h | 6 ++---- src/generic/stage1/json_minifier.h | 6 ++---- src/generic/stage1/json_scanner.h | 6 ++---- src/generic/stage1/json_string_scanner.h | 6 ++---- src/generic/stage1/json_structural_indexer.h | 6 ++---- src/generic/stage1/utf8_fastvalidate_algorithm.h | 3 +-- src/generic/stage1/utf8_lookup2_algorithm.h | 5 ++--- src/generic/stage1/utf8_lookup3_algorithm.h | 5 ++--- src/generic/stage1/utf8_lookup4_algorithm.h | 6 ++---- src/generic/stage1/utf8_lookup_algorithm.h | 3 +-- src/generic/stage1/utf8_range_algorithm.h | 3 +-- src/generic/stage1/utf8_validator.h | 6 ++---- src/generic/stage1/utf8_zwegner_algorithm.h | 3 +-- src/generic/stage2/allocate.h | 6 ++---- src/generic/stage2/atomparsing.h | 6 ++---- src/generic/stage2/jsoncharutils.h | 6 ++---- src/generic/stage2/logger.h | 6 ++---- src/generic/stage2/numberparsing.h | 6 ++---- src/generic/stage2/stringparsing.h | 6 ++---- src/generic/stage2/structural_iterator.h | 6 ++---- src/generic/stage2/structural_parser.h | 6 ++---- src/generic/stage2/tape_writer.h | 6 ++---- src/haswell/bitmanipulation.h | 6 ++---- src/haswell/bitmask.h | 6 ++---- src/haswell/dom_parser_implementation.cpp | 14 +++++--------- src/haswell/implementation.cpp | 6 ++---- src/haswell/implementation.h | 8 ++++---- src/haswell/numberparsing.h | 6 ++---- src/haswell/simd.h | 6 ++---- src/haswell/stringparsing.h | 6 ++---- src/westmere/bitmanipulation.h | 6 ++---- src/westmere/bitmask.h | 6 ++---- src/westmere/dom_parser_implementation.cpp | 14 +++++--------- src/westmere/implementation.cpp | 6 ++---- src/westmere/implementation.h | 7 +++---- src/westmere/numberparsing.h | 6 ++---- src/westmere/simd.h | 6 ++---- src/westmere/stringparsing.h | 6 ++---- 55 files changed, 123 insertions(+), 229 deletions(-) diff --git a/src/arm64/bitmanipulation.h b/src/arm64/bitmanipulation.h index c9203530e..4df7d60d8 100644 --- a/src/arm64/bitmanipulation.h +++ b/src/arm64/bitmanipulation.h @@ -1,9 +1,8 @@ #ifndef SIMDJSON_ARM64_BITMANIPULATION_H #define SIMDJSON_ARM64_BITMANIPULATION_H -namespace simdjson { -namespace arm64 { namespace { +namespace arm64 { // We sometimes call trailing_zero on inputs that are zero, // but the algorithms do not end up using the returned value. @@ -65,8 +64,7 @@ really_inline bool mul_overflow(uint64_t value1, uint64_t value2, uint64_t *resu #endif } -} // namespace { } // namespace arm64 -} // namespace simdjson +} // namespace { #endif // SIMDJSON_ARM64_BITMANIPULATION_H diff --git a/src/arm64/bitmask.h b/src/arm64/bitmask.h index 2c3094e27..7c392281a 100644 --- a/src/arm64/bitmask.h +++ b/src/arm64/bitmask.h @@ -1,9 +1,8 @@ #ifndef SIMDJSON_ARM64_BITMASK_H #define SIMDJSON_ARM64_BITMASK_H -namespace simdjson { -namespace arm64 { namespace { +namespace arm64 { // // Perform a "cumulative bitwise xor," flipping bits each time a 1 is encountered. diff --git a/src/arm64/dom_parser_implementation.cpp b/src/arm64/dom_parser_implementation.cpp index e512006ca..7a964044d 100644 --- a/src/arm64/dom_parser_implementation.cpp +++ b/src/arm64/dom_parser_implementation.cpp @@ -5,7 +5,7 @@ // // Stage 1 // -namespace simdjson { +namespace { namespace SIMDJSON_IMPLEMENTATION { using namespace simd; @@ -98,9 +98,8 @@ really_inline simd8 must_be_2_3_continuation(const simd8 prev2, c return is_third_byte ^ is_fourth_byte; } -} // namespace { } // namespace SIMDJSON_IMPLEMENTATION -} // namespace simdjson +} // namespace { #include "generic/stage1/utf8_lookup4_algorithm.h" #include "generic/stage1/json_structural_indexer.h" @@ -117,11 +116,9 @@ really_inline simd8 must_be_2_3_continuation(const simd8 prev2, c // // Implementation-specific overrides // -namespace simdjson { -namespace SIMDJSON_IMPLEMENTATION { - -namespace stage1 { namespace { +namespace SIMDJSON_IMPLEMENTATION { +namespace stage1 { really_inline uint64_t json_string_scanner::find_escaped(uint64_t backslash) { // On ARM, we don't short-circuit this if there are no backslashes, because the branch gives us no @@ -130,7 +127,6 @@ really_inline uint64_t json_string_scanner::find_escaped(uint64_t backslash) { return find_escaped_branchless(backslash); } -} // namespace { } // namespace stage1 WARN_UNUSED error_code implementation::minify(const uint8_t *buf, size_t len, uint8_t *dst, size_t &dst_len) const noexcept { @@ -171,6 +167,6 @@ WARN_UNUSED error_code dom_parser_implementation::parse(const uint8_t *_buf, siz } } // namespace SIMDJSON_IMPLEMENTATION -} // namespace simdjson +} // namespace { #include "arm64/end_implementation.h" diff --git a/src/arm64/implementation.cpp b/src/arm64/implementation.cpp index 8a9a7984f..93a79ec63 100644 --- a/src/arm64/implementation.cpp +++ b/src/arm64/implementation.cpp @@ -1,9 +1,8 @@ #include "arm64/begin_implementation.h" #include "arm64/dom_parser_implementation.h" -namespace simdjson { -namespace SIMDJSON_IMPLEMENTATION { namespace { +namespace SIMDJSON_IMPLEMENTATION { WARN_UNUSED error_code implementation::create_dom_parser_implementation( size_t capacity, @@ -17,8 +16,7 @@ WARN_UNUSED error_code implementation::create_dom_parser_implementation( return SUCCESS; } -} // namespace { } // namespace SIMDJSON_IMPLEMENTATION -} // namespace simdjson +} // namespace { #include "arm64/end_implementation.h" \ No newline at end of file diff --git a/src/arm64/implementation.h b/src/arm64/implementation.h index b9eb7c571..2b98e30fe 100644 --- a/src/arm64/implementation.h +++ b/src/arm64/implementation.h @@ -4,10 +4,10 @@ #include "simdjson.h" #include "isadetection.h" -namespace simdjson { -namespace arm64 { namespace { +namespace arm64 { +using namespace simdjson; using namespace simdjson::dom; class implementation final : public simdjson::implementation { @@ -22,8 +22,7 @@ public: WARN_UNUSED bool validate_utf8(const char *buf, size_t len) const noexcept final; }; -} // namespace { } // namespace arm64 -} // namespace simdjson +} // namespace { #endif // SIMDJSON_ARM64_IMPLEMENTATION_H diff --git a/src/arm64/numberparsing.h b/src/arm64/numberparsing.h index e0079170a..6783ad27a 100644 --- a/src/arm64/numberparsing.h +++ b/src/arm64/numberparsing.h @@ -1,9 +1,8 @@ #ifndef SIMDJSON_ARM64_NUMBERPARSING_H #define SIMDJSON_ARM64_NUMBERPARSING_H -namespace simdjson { -namespace arm64 { namespace { +namespace arm64 { // we don't have SSE, so let us use a scalar function // credit: https://johnnylee-sde.github.io/Fast-numeric-string-to-int/ @@ -15,9 +14,8 @@ static really_inline uint32_t parse_eight_digits_unrolled(const uint8_t *chars) return uint32_t((val & 0x0000FFFF0000FFFF) * 42949672960001 >> 32); } -} // namespace { } // namespace arm64 -} // namespace simdjson +} // namespace { #define SWAR_NUMBER_PARSING diff --git a/src/arm64/simd.h b/src/arm64/simd.h index d12e78293..551ebeec8 100644 --- a/src/arm64/simd.h +++ b/src/arm64/simd.h @@ -7,9 +7,8 @@ #include -namespace simdjson { -namespace arm64 { namespace { +namespace arm64 { namespace simd { #ifdef SIMDJSON_REGULAR_VISUAL_STUDIO @@ -495,8 +494,7 @@ really_inline int8x16_t make_int8x16_t(int8_t x1, int8_t x2, int8_t x3, int8_ }; // struct simd8x64 } // namespace simd -} // namespace { } // namespace arm64 -} // namespace simdjson +} // namespace { #endif // SIMDJSON_ARM64_SIMD_H diff --git a/src/arm64/stringparsing.h b/src/arm64/stringparsing.h index 91fb8d90a..3890e6697 100644 --- a/src/arm64/stringparsing.h +++ b/src/arm64/stringparsing.h @@ -5,9 +5,8 @@ #include "arm64/simd.h" #include "arm64/bitmanipulation.h" -namespace simdjson { -namespace arm64 { namespace { +namespace arm64 { using namespace simd; @@ -44,9 +43,8 @@ really_inline backslash_and_quote backslash_and_quote::copy_and_find(const uint8 }; } -} // namespace { } // namespace arm64 -} // namespace simdjson +} // namespace { #include "generic/stage2/stringparsing.h" diff --git a/src/fallback/bitmanipulation.h b/src/fallback/bitmanipulation.h index c85aa7b16..e1e96d712 100644 --- a/src/fallback/bitmanipulation.h +++ b/src/fallback/bitmanipulation.h @@ -4,9 +4,8 @@ #include "simdjson.h" #include -namespace simdjson { -namespace fallback { namespace { +namespace fallback { #if defined(_MSC_VER) && !defined(_M_ARM64) && !defined(_M_X64) static inline unsigned char _BitScanForward64(unsigned long* ret, uint64_t x) { @@ -72,8 +71,7 @@ really_inline bool mul_overflow(uint64_t value1, uint64_t value2, uint64_t *resu return value2 > 0 && value1 > std::numeric_limits::max() / value2; } -} // namespace { } // namespace fallback -} // namespace simdjson +} // namespace { #endif // SIMDJSON_FALLBACK_BITMANIPULATION_H diff --git a/src/fallback/dom_parser_implementation.cpp b/src/fallback/dom_parser_implementation.cpp index 0364762eb..0c4a59478 100644 --- a/src/fallback/dom_parser_implementation.cpp +++ b/src/fallback/dom_parser_implementation.cpp @@ -7,9 +7,8 @@ // #include "generic/stage1/find_next_document_index.h" -namespace simdjson { -namespace SIMDJSON_IMPLEMENTATION { namespace { +namespace SIMDJSON_IMPLEMENTATION { namespace stage1 { class structural_scanner { @@ -308,9 +307,8 @@ WARN_UNUSED bool implementation::validate_utf8(const char *buf, size_t len) cons return true; } -} // namespace { } // namespace SIMDJSON_IMPLEMENTATION -} // namespace simdjson +} // namespace { // // Stage 2 @@ -319,7 +317,7 @@ WARN_UNUSED bool implementation::validate_utf8(const char *buf, size_t len) cons #include "fallback/numberparsing.h" #include "generic/stage2/structural_parser.h" -namespace simdjson { +namespace { namespace SIMDJSON_IMPLEMENTATION { WARN_UNUSED error_code dom_parser_implementation::stage2(dom::document &_doc) noexcept { @@ -346,6 +344,6 @@ WARN_UNUSED error_code dom_parser_implementation::parse(const uint8_t *_buf, siz } } // namespace SIMDJSON_IMPLEMENTATION -} // namespace simdjson +} // namespace { #include "fallback/end_implementation.h" \ No newline at end of file diff --git a/src/fallback/implementation.cpp b/src/fallback/implementation.cpp index ff2a4f8cc..d4c6e8318 100644 --- a/src/fallback/implementation.cpp +++ b/src/fallback/implementation.cpp @@ -1,9 +1,8 @@ #include "fallback/begin_implementation.h" #include "fallback/dom_parser_implementation.h" -namespace simdjson { -namespace SIMDJSON_IMPLEMENTATION { namespace { +namespace SIMDJSON_IMPLEMENTATION { WARN_UNUSED error_code implementation::create_dom_parser_implementation( size_t capacity, @@ -17,8 +16,7 @@ WARN_UNUSED error_code implementation::create_dom_parser_implementation( return SUCCESS; } -} // namespace { } // namespace SIMDJSON_IMPLEMENTATION -} // namespace simdjson +} // namespace { #include "fallback/end_implementation.h" \ No newline at end of file diff --git a/src/fallback/implementation.h b/src/fallback/implementation.h index 540030990..fe6005328 100644 --- a/src/fallback/implementation.h +++ b/src/fallback/implementation.h @@ -4,10 +4,10 @@ #include "simdjson.h" #include "isadetection.h" -namespace simdjson { -namespace fallback { namespace { +namespace fallback { +using namespace simdjson; using namespace simdjson::dom; class implementation final : public simdjson::implementation { @@ -26,8 +26,7 @@ public: WARN_UNUSED bool validate_utf8(const char *buf, size_t len) const noexcept final; }; -} // namespace { } // namespace fallback -} // namespace simdjson +} // namespace { #endif // SIMDJSON_FALLBACK_IMPLEMENTATION_H \ No newline at end of file diff --git a/src/fallback/numberparsing.h b/src/fallback/numberparsing.h index ce1e9b898..bf87bb947 100644 --- a/src/fallback/numberparsing.h +++ b/src/fallback/numberparsing.h @@ -8,9 +8,8 @@ void found_unsigned_integer(uint64_t result, const uint8_t *buf); void found_float(double result, const uint8_t *buf); #endif -namespace simdjson { -namespace SIMDJSON_IMPLEMENTATION { namespace { +namespace SIMDJSON_IMPLEMENTATION { static really_inline uint32_t parse_eight_digits_unrolled(const char *chars) { uint32_t result = 0; for (int i=0;i<8;i++) { @@ -22,9 +21,8 @@ static really_inline uint32_t parse_eight_digits_unrolled(const uint8_t *chars) return parse_eight_digits_unrolled((const char *)chars); } -} // namespace { } // namespace SIMDJSON_IMPLEMENTATION -} // namespace simdjson +} // namespace { #define SWAR_NUMBER_PARSING #include "generic/stage2/numberparsing.h" diff --git a/src/fallback/stringparsing.h b/src/fallback/stringparsing.h index 4fed27e85..eb45dd409 100644 --- a/src/fallback/stringparsing.h +++ b/src/fallback/stringparsing.h @@ -3,9 +3,8 @@ #include "simdjson.h" -namespace simdjson { -namespace fallback { namespace { +namespace fallback { // Holds backslashes and quotes locations. struct backslash_and_quote { @@ -27,9 +26,8 @@ really_inline backslash_and_quote backslash_and_quote::copy_and_find(const uint8 return { src[0] }; } -} // namespace { } // namespace fallback -} // namespace simdjson +} // namespace { #include "generic/stage2/stringparsing.h" diff --git a/src/generic/dom_parser_implementation.h b/src/generic/dom_parser_implementation.h index e242157b9..f41f4046a 100644 --- a/src/generic/dom_parser_implementation.h +++ b/src/generic/dom_parser_implementation.h @@ -1,9 +1,8 @@ #include "simdjson.h" #include "isadetection.h" -namespace simdjson { -namespace SIMDJSON_IMPLEMENTATION { namespace { +namespace SIMDJSON_IMPLEMENTATION { // expectation: sizeof(scope_descriptor) = 64/8. struct scope_descriptor { @@ -45,16 +44,14 @@ public: WARN_UNUSED error_code set_max_depth(size_t max_depth) noexcept final; }; -} // namespace { } // namespace SIMDJSON_IMPLEMENTATION -} // namespace simdjson +} // namespace { #include "generic/stage1/allocate.h" #include "generic/stage2/allocate.h" -namespace simdjson { -namespace SIMDJSON_IMPLEMENTATION { namespace { +namespace SIMDJSON_IMPLEMENTATION { really_inline dom_parser_implementation::dom_parser_implementation() {} @@ -73,6 +70,5 @@ WARN_UNUSED error_code dom_parser_implementation::set_max_depth(size_t max_depth return SUCCESS; } -} // namespace { } // namespace SIMDJSON_IMPLEMENTATION -} // namespace simdjson +} // namespace { diff --git a/src/generic/stage1/allocate.h b/src/generic/stage1/allocate.h index 5a57e0700..f145e95d7 100644 --- a/src/generic/stage1/allocate.h +++ b/src/generic/stage1/allocate.h @@ -1,6 +1,5 @@ -namespace simdjson { -namespace SIMDJSON_IMPLEMENTATION { namespace { +namespace SIMDJSON_IMPLEMENTATION { namespace stage1 { namespace allocate { @@ -18,6 +17,5 @@ really_inline error_code set_capacity(internal::dom_parser_implementation &parse } // namespace allocate } // namespace stage1 -} // namespace { } // namespace SIMDJSON_IMPLEMENTATION -} // namespace simdjson +} // namespace { diff --git a/src/generic/stage1/buf_block_reader.h b/src/generic/stage1/buf_block_reader.h index ca25d1eed..d1dc57e18 100644 --- a/src/generic/stage1/buf_block_reader.h +++ b/src/generic/stage1/buf_block_reader.h @@ -1,6 +1,5 @@ -namespace simdjson { -namespace SIMDJSON_IMPLEMENTATION { namespace { +namespace SIMDJSON_IMPLEMENTATION { // Walks through a buffer in block-sized increments, loading the last part with spaces template @@ -86,6 +85,5 @@ really_inline void buf_block_reader::advance() { idx += STEP_SIZE; } -} // namespace { } // namespace SIMDJSON_IMPLEMENTATION -} // namespace simdjson +} // namespace { diff --git a/src/generic/stage1/find_next_document_index.h b/src/generic/stage1/find_next_document_index.h index acbd3a0e0..f1b51d63e 100644 --- a/src/generic/stage1/find_next_document_index.h +++ b/src/generic/stage1/find_next_document_index.h @@ -1,6 +1,5 @@ -namespace simdjson { -namespace SIMDJSON_IMPLEMENTATION { namespace { +namespace SIMDJSON_IMPLEMENTATION { /** * This algorithm is used to quickly identify the last structural position that @@ -89,6 +88,5 @@ really_inline size_t trim_partial_utf8(const uint8_t *buf, size_t len) { return len; } -} // namespace { } // namespace SIMDJSON_IMPLEMENTATION -} // namespace simdjson +} // namespace { diff --git a/src/generic/stage1/json_minifier.h b/src/generic/stage1/json_minifier.h index e567418c5..766ef6ef2 100644 --- a/src/generic/stage1/json_minifier.h +++ b/src/generic/stage1/json_minifier.h @@ -3,9 +3,8 @@ // We assume the file in which it is included already includes // "simdjson/stage1.h" (this simplifies amalgation) -namespace simdjson { -namespace SIMDJSON_IMPLEMENTATION { namespace { +namespace SIMDJSON_IMPLEMENTATION { namespace stage1 { class json_minifier { @@ -78,6 +77,5 @@ error_code json_minifier::minify(const uint8_t *buf, size_t len, uint8_t *dst, s } } // namespace stage1 -} // namespace { } // namespace SIMDJSON_IMPLEMENTATION -} // namespace simdjson +} // namespace { diff --git a/src/generic/stage1/json_scanner.h b/src/generic/stage1/json_scanner.h index 7a9e05e1e..a8b0b17ea 100644 --- a/src/generic/stage1/json_scanner.h +++ b/src/generic/stage1/json_scanner.h @@ -1,6 +1,5 @@ -namespace simdjson { -namespace SIMDJSON_IMPLEMENTATION { namespace { +namespace SIMDJSON_IMPLEMENTATION { namespace stage1 { /** @@ -105,6 +104,5 @@ really_inline error_code json_scanner::finish(bool streaming) { } } // namespace stage1 -} // namespace { } // namespace SIMDJSON_IMPLEMENTATION -} // namespace simdjson +} // namespace { diff --git a/src/generic/stage1/json_string_scanner.h b/src/generic/stage1/json_string_scanner.h index c53a9bac9..4c22507ab 100644 --- a/src/generic/stage1/json_string_scanner.h +++ b/src/generic/stage1/json_string_scanner.h @@ -1,6 +1,5 @@ -namespace simdjson { -namespace SIMDJSON_IMPLEMENTATION { namespace { +namespace SIMDJSON_IMPLEMENTATION { namespace stage1 { struct json_string_block { @@ -140,6 +139,5 @@ really_inline error_code json_string_scanner::finish(bool streaming) { } } // namespace stage1 -} // namespace { } // namespace SIMDJSON_IMPLEMENTATION -} // namespace simdjson +} // namespace { diff --git a/src/generic/stage1/json_structural_indexer.h b/src/generic/stage1/json_structural_indexer.h index 16c497cb5..b887eea41 100644 --- a/src/generic/stage1/json_structural_indexer.h +++ b/src/generic/stage1/json_structural_indexer.h @@ -9,9 +9,8 @@ #include "generic/stage1/json_minifier.h" #include "generic/stage1/find_next_document_index.h" -namespace simdjson { -namespace SIMDJSON_IMPLEMENTATION { namespace { +namespace SIMDJSON_IMPLEMENTATION { namespace stage1 { class bit_indexer { @@ -205,6 +204,5 @@ really_inline error_code json_structural_indexer::finish(dom_parser_implementati } } // namespace stage1 -} // namespace { } // namespace SIMDJSON_IMPLEMENTATION -} // namespace simdjson +} // namespace { diff --git a/src/generic/stage1/utf8_fastvalidate_algorithm.h b/src/generic/stage1/utf8_fastvalidate_algorithm.h index 24adaeebe..da526696c 100644 --- a/src/generic/stage1/utf8_fastvalidate_algorithm.h +++ b/src/generic/stage1/utf8_fastvalidate_algorithm.h @@ -180,6 +180,5 @@ struct utf8_checker { } }; // struct utf8_checker -} // namespace { } // namespace SIMDJSON_IMPLEMENTATION -} // namespace simdjson +} // namespace { diff --git a/src/generic/stage1/utf8_lookup2_algorithm.h b/src/generic/stage1/utf8_lookup2_algorithm.h index 9be898988..9c8a7e288 100644 --- a/src/generic/stage1/utf8_lookup2_algorithm.h +++ b/src/generic/stage1/utf8_lookup2_algorithm.h @@ -1,6 +1,5 @@ -namespace simdjson { -namespace SIMDJSON_IMPLEMENTATION { namespace { +namespace SIMDJSON_IMPLEMENTATION { namespace utf8_validation { // @@ -217,8 +216,8 @@ using namespace simd; } }; // struct utf8_checker -} // namespace { } // namespace utf8_validation +} // namespace { using utf8_validation::utf8_checker; diff --git a/src/generic/stage1/utf8_lookup3_algorithm.h b/src/generic/stage1/utf8_lookup3_algorithm.h index 641b8005f..5de0d062c 100644 --- a/src/generic/stage1/utf8_lookup3_algorithm.h +++ b/src/generic/stage1/utf8_lookup3_algorithm.h @@ -1,6 +1,5 @@ -namespace simdjson { -namespace SIMDJSON_IMPLEMENTATION { namespace { +namespace SIMDJSON_IMPLEMENTATION { namespace utf8_validation { // @@ -237,8 +236,8 @@ using namespace simd; } }; // struct utf8_checker -} // namespace { } // namespace utf8_validation +} // namespace { using utf8_validation::utf8_checker; diff --git a/src/generic/stage1/utf8_lookup4_algorithm.h b/src/generic/stage1/utf8_lookup4_algorithm.h index 2deeafde7..3aec36a2b 100644 --- a/src/generic/stage1/utf8_lookup4_algorithm.h +++ b/src/generic/stage1/utf8_lookup4_algorithm.h @@ -1,6 +1,5 @@ -namespace simdjson { -namespace SIMDJSON_IMPLEMENTATION { namespace { +namespace SIMDJSON_IMPLEMENTATION { namespace utf8_validation { using namespace simd; @@ -174,10 +173,9 @@ using namespace simd; } }; // struct utf8_checker -} // namespace { } // namespace utf8_validation using utf8_validation::utf8_checker; } // namespace SIMDJSON_IMPLEMENTATION -} // namespace simdjson +} // namespace { diff --git a/src/generic/stage1/utf8_lookup_algorithm.h b/src/generic/stage1/utf8_lookup_algorithm.h index 9462b2ddf..e6d735402 100644 --- a/src/generic/stage1/utf8_lookup_algorithm.h +++ b/src/generic/stage1/utf8_lookup_algorithm.h @@ -299,6 +299,5 @@ struct utf8_checker { }; // struct utf8_checker } // namespace utf8_validation -} // namespace { } // namespace SIMDJSON_IMPLEMENTATION -} // namespace simdjson +} // namespace { diff --git a/src/generic/stage1/utf8_range_algorithm.h b/src/generic/stage1/utf8_range_algorithm.h index f4b479eb6..05163a261 100644 --- a/src/generic/stage1/utf8_range_algorithm.h +++ b/src/generic/stage1/utf8_range_algorithm.h @@ -182,6 +182,5 @@ struct utf8_checker { } }; // struct utf8_checker -} // namespace { } // namespace SIMDJSON_IMPLEMENTATION -} // namespace simdjson +} // namespace { diff --git a/src/generic/stage1/utf8_validator.h b/src/generic/stage1/utf8_validator.h index 3c2765b45..49c9dbc77 100644 --- a/src/generic/stage1/utf8_validator.h +++ b/src/generic/stage1/utf8_validator.h @@ -1,6 +1,5 @@ -namespace simdjson { -namespace SIMDJSON_IMPLEMENTATION { namespace { +namespace SIMDJSON_IMPLEMENTATION { namespace stage1 { /** @@ -28,6 +27,5 @@ bool generic_validate_utf8(const char * input, size_t length) { } } // namespace stage1 -} // namespace { } // namespace SIMDJSON_IMPLEMENTATION -} // namespace simdjson +} // namespace { diff --git a/src/generic/stage1/utf8_zwegner_algorithm.h b/src/generic/stage1/utf8_zwegner_algorithm.h index b8a7bd807..91743351b 100644 --- a/src/generic/stage1/utf8_zwegner_algorithm.h +++ b/src/generic/stage1/utf8_zwegner_algorithm.h @@ -361,6 +361,5 @@ struct utf8_checker { } }; // struct utf8_checker -} // namespace { } // namespace SIMDJSON_IMPLEMENTATION -} // namespace simdjson +} // namespace { diff --git a/src/generic/stage2/allocate.h b/src/generic/stage2/allocate.h index 5d9bdb352..f82f023d5 100644 --- a/src/generic/stage2/allocate.h +++ b/src/generic/stage2/allocate.h @@ -1,6 +1,5 @@ -namespace simdjson { -namespace SIMDJSON_IMPLEMENTATION { namespace { +namespace SIMDJSON_IMPLEMENTATION { namespace stage2 { namespace allocate { @@ -19,6 +18,5 @@ really_inline error_code set_max_depth(dom_parser_implementation &parser, size_t } // namespace allocate } // namespace stage2 -} // namespace { } // namespace SIMDJSON_IMPLEMENTATION -} // namespace simdjson +} // namespace { diff --git a/src/generic/stage2/atomparsing.h b/src/generic/stage2/atomparsing.h index 26ffa5221..e993c7caa 100644 --- a/src/generic/stage2/atomparsing.h +++ b/src/generic/stage2/atomparsing.h @@ -1,6 +1,5 @@ -namespace simdjson { -namespace SIMDJSON_IMPLEMENTATION { namespace { +namespace SIMDJSON_IMPLEMENTATION { namespace stage2 { namespace atomparsing { @@ -61,6 +60,5 @@ really_inline bool is_valid_null_atom(const uint8_t *src, size_t len) { } // namespace atomparsing } // namespace stage2 -} // namespace { } // namespace SIMDJSON_IMPLEMENTATION -} // namespace simdjson +} // namespace { diff --git a/src/generic/stage2/jsoncharutils.h b/src/generic/stage2/jsoncharutils.h index e560a1eba..6d7c1167b 100644 --- a/src/generic/stage2/jsoncharutils.h +++ b/src/generic/stage2/jsoncharutils.h @@ -1,6 +1,5 @@ -namespace simdjson { -namespace SIMDJSON_IMPLEMENTATION { namespace { +namespace SIMDJSON_IMPLEMENTATION { namespace stage2 { // return non-zero if not a structural or whitespace char @@ -116,6 +115,5 @@ really_inline value128 full_multiplication(uint64_t value1, uint64_t value2) { } } // namespace stage2 -} // namespace { } // namespace SIMDJSON_IMPLEMENTATION -} // namespace simdjson +} // namespace { diff --git a/src/generic/stage2/logger.h b/src/generic/stage2/logger.h index dfafb6f68..a6584cb3a 100644 --- a/src/generic/stage2/logger.h +++ b/src/generic/stage2/logger.h @@ -1,8 +1,7 @@ // This is for an internal-only stage 2 specific logger. // Set LOG_ENABLED = true to log what stage 2 is doing! -namespace simdjson { -namespace SIMDJSON_IMPLEMENTATION { namespace { +namespace SIMDJSON_IMPLEMENTATION { namespace logger { static constexpr const char * DASHES = "----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------"; @@ -66,6 +65,5 @@ namespace logger { } } // namespace logger -} // namespace { } // namespace SIMDJSON_IMPLEMENTATION -} // namespace simdjson +} // namespace { diff --git a/src/generic/stage2/numberparsing.h b/src/generic/stage2/numberparsing.h index 94059e51d..920c2b9d6 100644 --- a/src/generic/stage2/numberparsing.h +++ b/src/generic/stage2/numberparsing.h @@ -1,9 +1,8 @@ #include #include -namespace simdjson { -namespace SIMDJSON_IMPLEMENTATION { namespace { +namespace SIMDJSON_IMPLEMENTATION { namespace stage2 { namespace numberparsing { @@ -505,6 +504,5 @@ really_inline bool parse_number(const uint8_t *const src, W &writer) { } // namespace numberparsing } // namespace stage2 -} // namespace { } // namespace SIMDJSON_IMPLEMENTATION -} // namespace simdjson +} // namespace { diff --git a/src/generic/stage2/stringparsing.h b/src/generic/stage2/stringparsing.h index b2568e282..f11103df0 100644 --- a/src/generic/stage2/stringparsing.h +++ b/src/generic/stage2/stringparsing.h @@ -1,9 +1,8 @@ // This file contains the common code every implementation uses // It is intended to be included multiple times and compiled multiple times -namespace simdjson { -namespace SIMDJSON_IMPLEMENTATION { namespace { +namespace SIMDJSON_IMPLEMENTATION { namespace stage2 { namespace stringparsing { @@ -122,6 +121,5 @@ WARN_UNUSED really_inline uint8_t *parse_string(const uint8_t *src, uint8_t *dst } // namespace stringparsing } // namespace stage2 -} // namespace { } // namespace SIMDJSON_IMPLEMENTATION -} // namespace simdjson +} // namespace { diff --git a/src/generic/stage2/structural_iterator.h b/src/generic/stage2/structural_iterator.h index c849f9a21..2871a93ed 100644 --- a/src/generic/stage2/structural_iterator.h +++ b/src/generic/stage2/structural_iterator.h @@ -1,6 +1,5 @@ -namespace simdjson { -namespace SIMDJSON_IMPLEMENTATION { namespace { +namespace SIMDJSON_IMPLEMENTATION { namespace stage2 { class structural_iterator { @@ -47,6 +46,5 @@ public: }; } // namespace stage2 -} // namespace { } // namespace SIMDJSON_IMPLEMENTATION -} // namespace simdjson +} // namespace { diff --git a/src/generic/stage2/structural_parser.h b/src/generic/stage2/structural_parser.h index f6cd15db5..a248ce085 100644 --- a/src/generic/stage2/structural_parser.h +++ b/src/generic/stage2/structural_parser.h @@ -8,9 +8,8 @@ #include "generic/stage2/atomparsing.h" #include "generic/stage2/structural_iterator.h" -namespace simdjson { -namespace SIMDJSON_IMPLEMENTATION { namespace { // Make everything here private +namespace SIMDJSON_IMPLEMENTATION { namespace stage2 { #ifdef SIMDJSON_USE_COMPUTED_GOTO @@ -468,6 +467,5 @@ error: } } // namespace stage2 -} // namespace { } // namespace SIMDJSON_IMPLEMENTATION -} // namespace simdjson +} // namespace { diff --git a/src/generic/stage2/tape_writer.h b/src/generic/stage2/tape_writer.h index 8c9f8c4b2..3a44f0477 100644 --- a/src/generic/stage2/tape_writer.h +++ b/src/generic/stage2/tape_writer.h @@ -1,6 +1,5 @@ -namespace simdjson { -namespace SIMDJSON_IMPLEMENTATION { namespace { +namespace SIMDJSON_IMPLEMENTATION { namespace stage2 { struct tape_writer { @@ -100,6 +99,5 @@ really_inline void tape_writer::write(uint64_t &tape_loc, uint64_t val, internal } } // namespace stage2 -} // namespace { } // namespace SIMDJSON_IMPLEMENTATION -} // namespace simdjson +} // namespace { diff --git a/src/haswell/bitmanipulation.h b/src/haswell/bitmanipulation.h index 51ce7437c..8e22b7d8d 100644 --- a/src/haswell/bitmanipulation.h +++ b/src/haswell/bitmanipulation.h @@ -1,9 +1,8 @@ #ifndef SIMDJSON_HASWELL_BITMANIPULATION_H #define SIMDJSON_HASWELL_BITMANIPULATION_H -namespace simdjson { -namespace SIMDJSON_IMPLEMENTATION { namespace { +namespace SIMDJSON_IMPLEMENTATION { // We sometimes call trailing_zero on inputs that are zero, // but the algorithms do not end up using the returned value. @@ -69,8 +68,7 @@ really_inline bool mul_overflow(uint64_t value1, uint64_t value2, #endif } -} // namespace { } // namespace SIMDJSON_IMPLEMENTATION -} // namespace simdjson +} // namespace { #endif // SIMDJSON_HASWELL_BITMANIPULATION_H diff --git a/src/haswell/bitmask.h b/src/haswell/bitmask.h index b5d0727b8..a2702e232 100644 --- a/src/haswell/bitmask.h +++ b/src/haswell/bitmask.h @@ -1,9 +1,8 @@ #ifndef SIMDJSON_HASWELL_BITMASK_H #define SIMDJSON_HASWELL_BITMASK_H -namespace simdjson { -namespace SIMDJSON_IMPLEMENTATION { namespace { +namespace SIMDJSON_IMPLEMENTATION { // // Perform a "cumulative bitwise xor," flipping bits each time a 1 is encountered. @@ -18,8 +17,7 @@ really_inline uint64_t prefix_xor(const uint64_t bitmask) { return _mm_cvtsi128_si64(result); } -} // namespace { } // namespace SIMDJSON_IMPLEMENTATION -} // namespace simdjson +} // namespace { #endif // SIMDJSON_HASWELL_BITMASK_H diff --git a/src/haswell/dom_parser_implementation.cpp b/src/haswell/dom_parser_implementation.cpp index cd35619b1..68fa6aa6e 100644 --- a/src/haswell/dom_parser_implementation.cpp +++ b/src/haswell/dom_parser_implementation.cpp @@ -6,9 +6,8 @@ // Stage 1 // -namespace simdjson { -namespace SIMDJSON_IMPLEMENTATION { namespace { +namespace SIMDJSON_IMPLEMENTATION { using namespace simd; @@ -65,9 +64,8 @@ really_inline simd8 must_be_2_3_continuation(const simd8 prev2, c return simd8(is_third_byte | is_fourth_byte) > int8_t(0); } -} // namespace { } // namespace SIMDJSON_IMPLEMENTATION -} // namespace simdjson +} // namespace { #include "generic/stage1/utf8_lookup4_algorithm.h" #include "generic/stage1/json_structural_indexer.h" @@ -83,9 +81,8 @@ really_inline simd8 must_be_2_3_continuation(const simd8 prev2, c // // Implementation-specific overrides // -namespace simdjson { -namespace SIMDJSON_IMPLEMENTATION { namespace { +namespace SIMDJSON_IMPLEMENTATION { namespace stage1 { really_inline uint64_t json_string_scanner::find_escaped(uint64_t backslash) { @@ -94,7 +91,6 @@ really_inline uint64_t json_string_scanner::find_escaped(uint64_t backslash) { } } // namespace stage1 -} // namespace { WARN_UNUSED error_code implementation::minify(const uint8_t *buf, size_t len, uint8_t *dst, size_t &dst_len) const noexcept { return haswell::stage1::json_minifier::minify<128>(buf, len, dst, dst_len); @@ -107,7 +103,7 @@ WARN_UNUSED error_code dom_parser_implementation::stage1(const uint8_t *_buf, si } WARN_UNUSED bool implementation::validate_utf8(const char *buf, size_t len) const noexcept { - return simdjson::haswell::stage1::generic_validate_utf8(buf,len); + return haswell::stage1::generic_validate_utf8(buf,len); } WARN_UNUSED error_code dom_parser_implementation::stage2(dom::document &_doc) noexcept { @@ -134,6 +130,6 @@ WARN_UNUSED error_code dom_parser_implementation::parse(const uint8_t *_buf, siz } } // namespace SIMDJSON_IMPLEMENTATION -} // namespace simdjson +} // namespace { #include "haswell/end_implementation.h" diff --git a/src/haswell/implementation.cpp b/src/haswell/implementation.cpp index 45f5b4fe8..8c70b81c7 100644 --- a/src/haswell/implementation.cpp +++ b/src/haswell/implementation.cpp @@ -1,9 +1,8 @@ #include "haswell/begin_implementation.h" #include "haswell/dom_parser_implementation.h" -namespace simdjson { -namespace SIMDJSON_IMPLEMENTATION { namespace { +namespace SIMDJSON_IMPLEMENTATION { WARN_UNUSED error_code implementation::create_dom_parser_implementation( size_t capacity, @@ -17,9 +16,8 @@ WARN_UNUSED error_code implementation::create_dom_parser_implementation( return SUCCESS; } -} // namespace { } // namespace SIMDJSON_IMPLEMENTATION -} // namespace simdjson +} // namespace { #include "haswell/end_implementation.h" diff --git a/src/haswell/implementation.h b/src/haswell/implementation.h index b2a549324..45ea9908a 100644 --- a/src/haswell/implementation.h +++ b/src/haswell/implementation.h @@ -5,9 +5,10 @@ #include "isadetection.h" // The constructor may be executed on any host, so we take care not to use SIMDJSON_TARGET_REGION -namespace simdjson { -namespace haswell { namespace { +namespace haswell { + +using namespace simdjson; class implementation final : public simdjson::implementation { public: @@ -25,8 +26,7 @@ public: WARN_UNUSED bool validate_utf8(const char *buf, size_t len) const noexcept final; }; -} // namespace { } // namespace haswell -} // namespace simdjson +} // namespace { #endif // SIMDJSON_HASWELL_IMPLEMENTATION_H \ No newline at end of file diff --git a/src/haswell/numberparsing.h b/src/haswell/numberparsing.h index 547d3baba..08d0a5c14 100644 --- a/src/haswell/numberparsing.h +++ b/src/haswell/numberparsing.h @@ -1,9 +1,8 @@ #ifndef SIMDJSON_HASWELL_NUMBERPARSING_H #define SIMDJSON_HASWELL_NUMBERPARSING_H -namespace simdjson { -namespace SIMDJSON_IMPLEMENTATION { namespace { +namespace SIMDJSON_IMPLEMENTATION { static really_inline uint32_t parse_eight_digits_unrolled(const uint8_t *chars) { // this actually computes *16* values so we are being wasteful. @@ -23,9 +22,8 @@ static really_inline uint32_t parse_eight_digits_unrolled(const uint8_t *chars) t4); // only captures the sum of the first 8 digits, drop the rest } -} // namespace { } // namespace SIMDJSON_IMPLEMENTATION -} // namespace simdjson +} // namespace { #define SWAR_NUMBER_PARSING diff --git a/src/haswell/simd.h b/src/haswell/simd.h index 26e13de41..183c4b124 100644 --- a/src/haswell/simd.h +++ b/src/haswell/simd.h @@ -3,9 +3,8 @@ #include "simdprune_tables.h" -namespace simdjson { -namespace SIMDJSON_IMPLEMENTATION { namespace { +namespace SIMDJSON_IMPLEMENTATION { namespace simd { // Forward-declared so they can be used by splat and friends. @@ -347,10 +346,9 @@ namespace simd { } }; // struct simd8x64 -} // namespace { } // namespace simd } // namespace SIMDJSON_IMPLEMENTATION -} // namespace simdjson +} // namespace { #endif // SIMDJSON_HASWELL_SIMD_H diff --git a/src/haswell/stringparsing.h b/src/haswell/stringparsing.h index 575745460..8d7f95622 100644 --- a/src/haswell/stringparsing.h +++ b/src/haswell/stringparsing.h @@ -5,9 +5,8 @@ #include "haswell/simd.h" #include "haswell/bitmanipulation.h" -namespace simdjson { -namespace SIMDJSON_IMPLEMENTATION { namespace { +namespace SIMDJSON_IMPLEMENTATION { using namespace simd; @@ -39,9 +38,8 @@ really_inline backslash_and_quote backslash_and_quote::copy_and_find(const uint8 }; } -} // namespace { } // namespace SIMDJSON_IMPLEMENTATION -} // namespace simdjson +} // namespace { #include "generic/stage2/stringparsing.h" diff --git a/src/westmere/bitmanipulation.h b/src/westmere/bitmanipulation.h index 641a5ac9b..928dbfd18 100644 --- a/src/westmere/bitmanipulation.h +++ b/src/westmere/bitmanipulation.h @@ -1,9 +1,8 @@ #ifndef SIMDJSON_WESTMERE_BITMANIPULATION_H #define SIMDJSON_WESTMERE_BITMANIPULATION_H -namespace simdjson { -namespace SIMDJSON_IMPLEMENTATION { namespace { +namespace SIMDJSON_IMPLEMENTATION { // We sometimes call trailing_zero on inputs that are zero, // but the algorithms do not end up using the returned value. @@ -78,8 +77,7 @@ really_inline bool mul_overflow(uint64_t value1, uint64_t value2, #endif } -} // namespace { } // namespace SIMDJSON_IMPLEMENTATION -} // namespace simdjson +} // namespace { #endif // SIMDJSON_WESTMERE_BITMANIPULATION_H diff --git a/src/westmere/bitmask.h b/src/westmere/bitmask.h index 2da19c90c..ad397357c 100644 --- a/src/westmere/bitmask.h +++ b/src/westmere/bitmask.h @@ -1,9 +1,8 @@ #ifndef SIMDJSON_WESTMERE_BITMASK_H #define SIMDJSON_WESTMERE_BITMASK_H -namespace simdjson { -namespace SIMDJSON_IMPLEMENTATION { namespace { +namespace SIMDJSON_IMPLEMENTATION { // // Perform a "cumulative bitwise xor," flipping bits each time a 1 is encountered. @@ -18,8 +17,7 @@ really_inline uint64_t prefix_xor(const uint64_t bitmask) { return _mm_cvtsi128_si64(result); } -} // namespace { } // namespace SIMDJSON_IMPLEMENTATION -} // namespace simdjson +} // namespace { #endif // SIMDJSON_WESTMERE_BITMASK_H diff --git a/src/westmere/dom_parser_implementation.cpp b/src/westmere/dom_parser_implementation.cpp index d158cbf99..1f561c216 100644 --- a/src/westmere/dom_parser_implementation.cpp +++ b/src/westmere/dom_parser_implementation.cpp @@ -6,9 +6,8 @@ // Stage 1 // -namespace simdjson { -namespace SIMDJSON_IMPLEMENTATION { namespace { +namespace SIMDJSON_IMPLEMENTATION { using namespace simd; @@ -70,9 +69,8 @@ really_inline simd8 must_be_2_3_continuation(const simd8 prev2, c return simd8(is_third_byte | is_fourth_byte) > int8_t(0); } -} // namespace { } // namespace SIMDJSON_IMPLEMENTATION -} // namespace simdjson +} // namespace { #include "generic/stage1/utf8_lookup4_algorithm.h" #include "generic/stage1/json_structural_indexer.h" @@ -88,10 +86,9 @@ really_inline simd8 must_be_2_3_continuation(const simd8 prev2, c // // Implementation-specific overrides // -namespace simdjson { -namespace SIMDJSON_IMPLEMENTATION { namespace { +namespace SIMDJSON_IMPLEMENTATION { namespace stage1 { really_inline uint64_t json_string_scanner::find_escaped(uint64_t backslash) { @@ -100,7 +97,6 @@ really_inline uint64_t json_string_scanner::find_escaped(uint64_t backslash) { } } // namespace stage1 -} // namespace { WARN_UNUSED error_code implementation::minify(const uint8_t *buf, size_t len, uint8_t *dst, size_t &dst_len) const noexcept { return westmere::stage1::json_minifier::minify<64>(buf, len, dst, dst_len); @@ -113,7 +109,7 @@ WARN_UNUSED error_code dom_parser_implementation::stage1(const uint8_t *_buf, si } WARN_UNUSED bool implementation::validate_utf8(const char *buf, size_t len) const noexcept { - return simdjson::westmere::stage1::generic_validate_utf8(buf,len); + return westmere::stage1::generic_validate_utf8(buf,len); } WARN_UNUSED error_code dom_parser_implementation::stage2(dom::document &_doc) noexcept { @@ -140,6 +136,6 @@ WARN_UNUSED error_code dom_parser_implementation::parse(const uint8_t *_buf, siz } } // namespace SIMDJSON_IMPLEMENTATION -} // namespace simdjson +} // namespace { #include "westmere/end_implementation.h" diff --git a/src/westmere/implementation.cpp b/src/westmere/implementation.cpp index e39efb02a..a58e676af 100644 --- a/src/westmere/implementation.cpp +++ b/src/westmere/implementation.cpp @@ -1,9 +1,8 @@ #include "westmere/begin_implementation.h" #include "westmere/dom_parser_implementation.h" -namespace simdjson { -namespace SIMDJSON_IMPLEMENTATION { namespace { +namespace SIMDJSON_IMPLEMENTATION { WARN_UNUSED error_code implementation::create_dom_parser_implementation( size_t capacity, @@ -17,8 +16,7 @@ WARN_UNUSED error_code implementation::create_dom_parser_implementation( return SUCCESS; } -} // namespace { } // namespace SIMDJSON_IMPLEMENTATION -} // namespace simdjson +} // namespace { #include "westmere/end_implementation.h" \ No newline at end of file diff --git a/src/westmere/implementation.h b/src/westmere/implementation.h index 453c065dd..c16922b93 100644 --- a/src/westmere/implementation.h +++ b/src/westmere/implementation.h @@ -6,10 +6,10 @@ #include "isadetection.h" // The constructor may be executed on any host, so we take care not to use SIMDJSON_TARGET_REGION -namespace simdjson { -namespace westmere { namespace { +namespace westmere { +using namespace simdjson; using namespace simdjson::dom; class implementation final : public simdjson::implementation { @@ -24,8 +24,7 @@ public: WARN_UNUSED bool validate_utf8(const char *buf, size_t len) const noexcept final; }; -} // namespace { } // namespace westmere -} // namespace simdjson +} // namespace { #endif // SIMDJSON_WESTMERE_IMPLEMENTATION_H \ No newline at end of file diff --git a/src/westmere/numberparsing.h b/src/westmere/numberparsing.h index c72a14564..681a079e2 100644 --- a/src/westmere/numberparsing.h +++ b/src/westmere/numberparsing.h @@ -1,9 +1,8 @@ #ifndef SIMDJSON_WESTMERE_NUMBERPARSING_H #define SIMDJSON_WESTMERE_NUMBERPARSING_H -namespace simdjson { -namespace SIMDJSON_IMPLEMENTATION { namespace { +namespace SIMDJSON_IMPLEMENTATION { static really_inline uint32_t parse_eight_digits_unrolled(const uint8_t *chars) { // this actually computes *16* values so we are being wasteful. @@ -23,9 +22,8 @@ static really_inline uint32_t parse_eight_digits_unrolled(const uint8_t *chars) t4); // only captures the sum of the first 8 digits, drop the rest } -} // namespace { } // namespace SIMDJSON_IMPLEMENTATION -} // namespace simdjson +} // namespace { #define SWAR_NUMBER_PARSING diff --git a/src/westmere/simd.h b/src/westmere/simd.h index bcb7db9b4..9f328c675 100644 --- a/src/westmere/simd.h +++ b/src/westmere/simd.h @@ -3,9 +3,8 @@ #include "simdprune_tables.h" -namespace simdjson { -namespace SIMDJSON_IMPLEMENTATION { namespace { +namespace SIMDJSON_IMPLEMENTATION { namespace simd { template @@ -328,8 +327,7 @@ namespace simd { }; // struct simd8x64 } // namespace simd -} // namespace { } // namespace SIMDJSON_IMPLEMENTATION -} // namespace simdjson +} // namespace { #endif // SIMDJSON_WESTMERE_SIMD_INPUT_H diff --git a/src/westmere/stringparsing.h b/src/westmere/stringparsing.h index 7eab837e4..a0e8900ae 100644 --- a/src/westmere/stringparsing.h +++ b/src/westmere/stringparsing.h @@ -1,9 +1,8 @@ #ifndef SIMDJSON_WESTMERE_STRINGPARSING_H #define SIMDJSON_WESTMERE_STRINGPARSING_H -namespace simdjson { -namespace SIMDJSON_IMPLEMENTATION { namespace { +namespace SIMDJSON_IMPLEMENTATION { using namespace simd; @@ -37,9 +36,8 @@ really_inline backslash_and_quote backslash_and_quote::copy_and_find(const uint8 }; } -} // namespace { } // namespace SIMDJSON_IMPLEMENTATION -} // namespace simdjson +} // namespace { #include "generic/stage2/stringparsing.h" From 4e944a9f3c8a010211c760643952b8527ffb0673 Mon Sep 17 00:00:00 2001 From: John Keiser Date: Fri, 24 Jul 2020 17:20:18 -0700 Subject: [PATCH 3/5] Eliminate unused functions in fallback --- src/arm64/bitmanipulation.h | 2 ++ src/arm64/dom_parser_implementation.cpp | 2 +- src/fallback/bitmanipulation.h | 10 ++++-- src/generic/stage1/find_next_document_index.h | 21 ------------ src/generic/stage1/json_scanner.h | 13 -------- src/generic/stage1/json_structural_indexer.h | 21 ++++++++++++ src/generic/stage2/jsoncharutils.h | 10 ------ src/haswell/bitmanipulation.h | 2 ++ src/haswell/dom_parser_implementation.cpp | 2 +- src/jsoncharutils_tables.h | 32 ------------------- src/westmere/bitmanipulation.h | 2 ++ src/westmere/dom_parser_implementation.cpp | 2 +- 12 files changed, 37 insertions(+), 82 deletions(-) diff --git a/src/arm64/bitmanipulation.h b/src/arm64/bitmanipulation.h index 4df7d60d8..e0d380e7e 100644 --- a/src/arm64/bitmanipulation.h +++ b/src/arm64/bitmanipulation.h @@ -55,6 +55,7 @@ really_inline bool add_overflow(uint64_t value1, uint64_t value2, uint64_t *resu #endif } +#if 0 // Currently unused really_inline bool mul_overflow(uint64_t value1, uint64_t value2, uint64_t *result) { #ifdef SIMDJSON_REGULAR_VISUAL_STUDIO *result = value1 * value2; @@ -63,6 +64,7 @@ really_inline bool mul_overflow(uint64_t value1, uint64_t value2, uint64_t *resu return __builtin_umulll_overflow(value1, value2, (unsigned long long *)result); #endif } +#endif // Currently unused } // namespace arm64 } // namespace { diff --git a/src/arm64/dom_parser_implementation.cpp b/src/arm64/dom_parser_implementation.cpp index 7a964044d..d64103013 100644 --- a/src/arm64/dom_parser_implementation.cpp +++ b/src/arm64/dom_parser_implementation.cpp @@ -80,7 +80,7 @@ really_inline bool is_ascii(const simd8x64& input) { return bits.max() < 0b10000000u; } -really_inline simd8 must_be_continuation(const simd8 prev1, const simd8 prev2, const simd8 prev3) { +UNUSED really_inline simd8 must_be_continuation(const simd8 prev1, const simd8 prev2, const simd8 prev3) { simd8 is_second_byte = prev1 >= uint8_t(0b11000000u); simd8 is_third_byte = prev2 >= uint8_t(0b11100000u); simd8 is_fourth_byte = prev3 >= uint8_t(0b11110000u); diff --git a/src/fallback/bitmanipulation.h b/src/fallback/bitmanipulation.h index e1e96d712..ab223bb3f 100644 --- a/src/fallback/bitmanipulation.h +++ b/src/fallback/bitmanipulation.h @@ -24,9 +24,10 @@ static unsigned char _BitScanReverse64(unsigned long* ret, uint64_t x) { } #endif -// We sometimes call trailing_zero on inputs that are zero, -// but the algorithms do not end up using the returned value. -// Sadly, sanitizers are not smart enough to figure it out. +// +// These are currently unused, but one day will be. +// +#if 0 // Currently unused NO_SANITIZE_UNDEFINED really_inline int trailing_zeroes(uint64_t input_num) { #ifdef _MSC_VER @@ -44,6 +45,7 @@ really_inline int trailing_zeroes(uint64_t input_num) { really_inline uint64_t clear_lowest_bit(uint64_t input_num) { return input_num & (input_num-1); } +#endif // Currently unused /* result might be undefined when input_num is zero */ really_inline int leading_zeroes(uint64_t input_num) { @@ -60,6 +62,7 @@ really_inline int leading_zeroes(uint64_t input_num) { #endif// _MSC_VER } +#if 0 // Currently unused really_inline bool add_overflow(uint64_t value1, uint64_t value2, uint64_t *result) { *result = value1 + value2; return *result < value1; @@ -70,6 +73,7 @@ really_inline bool mul_overflow(uint64_t value1, uint64_t value2, uint64_t *resu // TODO there must be a faster way return value2 > 0 && value1 > std::numeric_limits::max() / value2; } +#endif // Currently unused } // namespace fallback } // namespace { diff --git a/src/generic/stage1/find_next_document_index.h b/src/generic/stage1/find_next_document_index.h index f1b51d63e..176a76a51 100644 --- a/src/generic/stage1/find_next_document_index.h +++ b/src/generic/stage1/find_next_document_index.h @@ -67,26 +67,5 @@ really_inline uint32_t find_next_document_index(dom_parser_implementation &parse return 0; } -// Skip the last character if it is partial -really_inline size_t trim_partial_utf8(const uint8_t *buf, size_t len) { - if (unlikely(len < 3)) { - switch (len) { - case 2: - if (buf[len-1] >= 0b11000000) { return len-1; } // 2-, 3- and 4-byte characters with only 1 byte left - if (buf[len-2] >= 0b11100000) { return len-2; } // 3- and 4-byte characters with only 2 bytes left - return len; - case 1: - if (buf[len-1] >= 0b11000000) { return len-1; } // 2-, 3- and 4-byte characters with only 1 byte left - return len; - case 0: - return len; - } - } - if (buf[len-1] >= 0b11000000) { return len-1; } // 2-, 3- and 4-byte characters with only 1 byte left - if (buf[len-2] >= 0b11100000) { return len-2; } // 3- and 4-byte characters with only 1 byte left - if (buf[len-3] >= 0b11110000) { return len-3; } // 4-byte characters with only 3 bytes left - return len; -} - } // namespace SIMDJSON_IMPLEMENTATION } // namespace { diff --git a/src/generic/stage1/json_scanner.h b/src/generic/stage1/json_scanner.h index a8b0b17ea..3338ab135 100644 --- a/src/generic/stage1/json_scanner.h +++ b/src/generic/stage1/json_scanner.h @@ -75,19 +75,6 @@ really_inline uint64_t follows(const uint64_t match, uint64_t &overflow) { return result; } -// -// Check if the current character follows a matching character, with possible "filler" between. -// For example, this checks for empty curly braces, e.g. -// -// in.eq('}') & follows(in.eq('['), in.eq(' '), prev_empty_array) // { * } -// -really_inline uint64_t follows(const uint64_t match, const uint64_t filler, uint64_t &overflow) { - uint64_t follows_match = follows(match, overflow); - uint64_t result; - overflow |= uint64_t(add_overflow(follows_match, filler, &result)); - return result; -} - really_inline json_block json_scanner::next(const simd::simd8x64& in) { json_string_block strings = string_scanner.next(in); json_character_block characters = json_character_block::classify(in); diff --git a/src/generic/stage1/json_structural_indexer.h b/src/generic/stage1/json_structural_indexer.h index b887eea41..0a4a2298b 100644 --- a/src/generic/stage1/json_structural_indexer.h +++ b/src/generic/stage1/json_structural_indexer.h @@ -91,6 +91,27 @@ private: really_inline json_structural_indexer::json_structural_indexer(uint32_t *structural_indexes) : indexer{structural_indexes} {} +// Skip the last character if it is partial +really_inline size_t trim_partial_utf8(const uint8_t *buf, size_t len) { + if (unlikely(len < 3)) { + switch (len) { + case 2: + if (buf[len-1] >= 0b11000000) { return len-1; } // 2-, 3- and 4-byte characters with only 1 byte left + if (buf[len-2] >= 0b11100000) { return len-2; } // 3- and 4-byte characters with only 2 bytes left + return len; + case 1: + if (buf[len-1] >= 0b11000000) { return len-1; } // 2-, 3- and 4-byte characters with only 1 byte left + return len; + case 0: + return len; + } + } + if (buf[len-1] >= 0b11000000) { return len-1; } // 2-, 3- and 4-byte characters with only 1 byte left + if (buf[len-2] >= 0b11100000) { return len-2; } // 3- and 4-byte characters with only 1 byte left + if (buf[len-3] >= 0b11110000) { return len-3; } // 4-byte characters with only 3 bytes left + return len; +} + // // PERF NOTES: // We pipe 2 inputs through these stages: diff --git a/src/generic/stage2/jsoncharutils.h b/src/generic/stage2/jsoncharutils.h index 6d7c1167b..1c0419ee6 100644 --- a/src/generic/stage2/jsoncharutils.h +++ b/src/generic/stage2/jsoncharutils.h @@ -2,22 +2,12 @@ namespace { namespace SIMDJSON_IMPLEMENTATION { namespace stage2 { -// return non-zero if not a structural or whitespace char -// zero otherwise -really_inline uint32_t is_not_structural_or_whitespace_or_null(uint8_t c) { - return structural_or_whitespace_or_null_negated[c]; -} - // return non-zero if not a structural or whitespace char // zero otherwise really_inline uint32_t is_not_structural_or_whitespace(uint8_t c) { return structural_or_whitespace_negated[c]; } -really_inline uint32_t is_structural_or_whitespace_or_null(uint8_t c) { - return structural_or_whitespace_or_null[c]; -} - really_inline uint32_t is_structural_or_whitespace(uint8_t c) { return structural_or_whitespace[c]; } diff --git a/src/haswell/bitmanipulation.h b/src/haswell/bitmanipulation.h index 8e22b7d8d..e7b0769c4 100644 --- a/src/haswell/bitmanipulation.h +++ b/src/haswell/bitmanipulation.h @@ -53,6 +53,7 @@ really_inline bool add_overflow(uint64_t value1, uint64_t value2, #endif } +#if 0 // Currently unused #if defined(SIMDJSON_REGULAR_VISUAL_STUDIO) || defined(SIMDJSON_IS_32BITS) #pragma intrinsic(_umul128) #endif @@ -67,6 +68,7 @@ really_inline bool mul_overflow(uint64_t value1, uint64_t value2, (unsigned long long *)result); #endif } +#endif // Currently unused } // namespace SIMDJSON_IMPLEMENTATION } // namespace { diff --git a/src/haswell/dom_parser_implementation.cpp b/src/haswell/dom_parser_implementation.cpp index 68fa6aa6e..39cafef1e 100644 --- a/src/haswell/dom_parser_implementation.cpp +++ b/src/haswell/dom_parser_implementation.cpp @@ -49,7 +49,7 @@ really_inline bool is_ascii(const simd8x64& input) { return input.reduce_or().is_ascii(); } -really_inline simd8 must_be_continuation(const simd8 prev1, const simd8 prev2, const simd8 prev3) { +UNUSED really_inline simd8 must_be_continuation(const simd8 prev1, const simd8 prev2, const simd8 prev3) { simd8 is_second_byte = prev1.saturating_sub(0b11000000u-1); // Only 11______ will be > 0 simd8 is_third_byte = prev2.saturating_sub(0b11100000u-1); // Only 111_____ will be > 0 simd8 is_fourth_byte = prev3.saturating_sub(0b11110000u-1); // Only 1111____ will be > 0 diff --git a/src/jsoncharutils_tables.h b/src/jsoncharutils_tables.h index 365ef4156..afa1ebe51 100644 --- a/src/jsoncharutils_tables.h +++ b/src/jsoncharutils_tables.h @@ -15,25 +15,6 @@ namespace simdjson { // we are also interested in the four whitespace characters // space 0x20, linefeed 0x0a, horizontal tab 0x09 and carriage return 0x0d -// these are the chars that can follow a true/false/null or number atom -// and nothing else -const uint32_t structural_or_whitespace_or_null_negated[256] = { - 0, 1, 1, 1, 1, 1, 1, 1, 1, 0, 0, 1, 1, 0, 1, 1, 1, 1, 1, 1, 1, 1, - 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 0, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, - 0, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 0, 1, 1, 1, 1, 1, - - 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, - 1, 1, 1, 1, 1, 0, 1, 0, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, - 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 0, 1, 0, 1, 1, - - 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, - 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, - 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, - - 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, - 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, - 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1}; - const uint32_t structural_or_whitespace_negated[256] = { 1, 1, 1, 1, 1, 1, 1, 1, 1, 0, 0, 1, 1, 0, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 0, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, @@ -51,19 +32,6 @@ const uint32_t structural_or_whitespace_negated[256] = { 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1}; -const uint32_t structural_or_whitespace_or_null[256] = { - 1, 0, 0, 0, 0, 0, 0, 0, 0, 1, 1, 0, 0, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, - 0, 0, 0, 0, 0, 0, 0, 0, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1, 0, 0, 0, - 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, - 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1, 0, 1, 0, 0, - 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, - 0, 0, 0, 1, 0, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, - 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, - 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, - 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, - 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, - 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0}; - const uint32_t structural_or_whitespace[256] = { 0, 0, 0, 0, 0, 0, 0, 0, 0, 1, 1, 0, 0, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1, 0, 0, 0, diff --git a/src/westmere/bitmanipulation.h b/src/westmere/bitmanipulation.h index 928dbfd18..d221f971b 100644 --- a/src/westmere/bitmanipulation.h +++ b/src/westmere/bitmanipulation.h @@ -62,6 +62,7 @@ really_inline bool add_overflow(uint64_t value1, uint64_t value2, #endif } +#if 0 // Currently unused #if defined(SIMDJSON_REGULAR_VISUAL_STUDIO) || defined(SIMDJSON_IS_32BITS) #pragma intrinsic(_umul128) #endif @@ -76,6 +77,7 @@ really_inline bool mul_overflow(uint64_t value1, uint64_t value2, (unsigned long long *)result); #endif } +#endif // Currently unused } // namespace SIMDJSON_IMPLEMENTATION } // namespace { diff --git a/src/westmere/dom_parser_implementation.cpp b/src/westmere/dom_parser_implementation.cpp index 1f561c216..f15f67234 100644 --- a/src/westmere/dom_parser_implementation.cpp +++ b/src/westmere/dom_parser_implementation.cpp @@ -54,7 +54,7 @@ really_inline bool is_ascii(const simd8x64& input) { return input.reduce_or().is_ascii(); } -really_inline simd8 must_be_continuation(const simd8 prev1, const simd8 prev2, const simd8 prev3) { +UNUSED really_inline simd8 must_be_continuation(const simd8 prev1, const simd8 prev2, const simd8 prev3) { simd8 is_second_byte = prev1.saturating_sub(0b11000000u-1); // Only 11______ will be > 0 simd8 is_third_byte = prev2.saturating_sub(0b11100000u-1); // Only 111_____ will be > 0 simd8 is_fourth_byte = prev3.saturating_sub(0b11110000u-1); // Only 1111____ will be > 0 From b1478c37f657d8975309f6a6f876ae1e608f056d Mon Sep 17 00:00:00 2001 From: John Keiser Date: Mon, 27 Jul 2020 19:35:09 -0700 Subject: [PATCH 4/5] Fix arm64 build --- src/arm64/dom_parser_implementation.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/arm64/dom_parser_implementation.cpp b/src/arm64/dom_parser_implementation.cpp index d64103013..678e99bc3 100644 --- a/src/arm64/dom_parser_implementation.cpp +++ b/src/arm64/dom_parser_implementation.cpp @@ -140,7 +140,7 @@ WARN_UNUSED error_code dom_parser_implementation::stage1(const uint8_t *_buf, si } WARN_UNUSED bool implementation::validate_utf8(const char *buf, size_t len) const noexcept { - return simdjson::arm64::stage1::generic_validate_utf8(buf,len); + return arm64::stage1::generic_validate_utf8(buf,len); } WARN_UNUSED error_code dom_parser_implementation::stage2(dom::document &_doc) noexcept { From bc8a6dd2e35d644eb4e964a015b7b426f1870e3a Mon Sep 17 00:00:00 2001 From: John Keiser Date: Sat, 1 Aug 2020 14:42:38 -0700 Subject: [PATCH 5/5] Remove dead code --- src/arm64/bitmanipulation.h | 11 ----------- src/fallback/bitmanipulation.h | 36 ---------------------------------- src/haswell/bitmanipulation.h | 17 ---------------- src/westmere/bitmanipulation.h | 17 ---------------- 4 files changed, 81 deletions(-) diff --git a/src/arm64/bitmanipulation.h b/src/arm64/bitmanipulation.h index e0d380e7e..727ef7456 100644 --- a/src/arm64/bitmanipulation.h +++ b/src/arm64/bitmanipulation.h @@ -55,17 +55,6 @@ really_inline bool add_overflow(uint64_t value1, uint64_t value2, uint64_t *resu #endif } -#if 0 // Currently unused -really_inline bool mul_overflow(uint64_t value1, uint64_t value2, uint64_t *result) { -#ifdef SIMDJSON_REGULAR_VISUAL_STUDIO - *result = value1 * value2; - return !!__umulh(value1, value2); -#else - return __builtin_umulll_overflow(value1, value2, (unsigned long long *)result); -#endif -} -#endif // Currently unused - } // namespace arm64 } // namespace { diff --git a/src/fallback/bitmanipulation.h b/src/fallback/bitmanipulation.h index ab223bb3f..ad6c0749c 100644 --- a/src/fallback/bitmanipulation.h +++ b/src/fallback/bitmanipulation.h @@ -24,29 +24,6 @@ static unsigned char _BitScanReverse64(unsigned long* ret, uint64_t x) { } #endif -// -// These are currently unused, but one day will be. -// -#if 0 // Currently unused -NO_SANITIZE_UNDEFINED -really_inline int trailing_zeroes(uint64_t input_num) { -#ifdef _MSC_VER - unsigned long ret; - // Search the mask data from least significant bit (LSB) - // to the most significant bit (MSB) for a set bit (1). - _BitScanForward64(&ret, input_num); - return (int)ret; -#else // _MSC_VER - return __builtin_ctzll(input_num); -#endif // _MSC_VER -} - -/* result might be undefined when input_num is zero */ -really_inline uint64_t clear_lowest_bit(uint64_t input_num) { - return input_num & (input_num-1); -} -#endif // Currently unused - /* result might be undefined when input_num is zero */ really_inline int leading_zeroes(uint64_t input_num) { #ifdef _MSC_VER @@ -62,19 +39,6 @@ really_inline int leading_zeroes(uint64_t input_num) { #endif// _MSC_VER } -#if 0 // Currently unused -really_inline bool add_overflow(uint64_t value1, uint64_t value2, uint64_t *result) { - *result = value1 + value2; - return *result < value1; -} - -really_inline bool mul_overflow(uint64_t value1, uint64_t value2, uint64_t *result) { - *result = value1 * value2; - // TODO there must be a faster way - return value2 > 0 && value1 > std::numeric_limits::max() / value2; -} -#endif // Currently unused - } // namespace fallback } // namespace { diff --git a/src/haswell/bitmanipulation.h b/src/haswell/bitmanipulation.h index e7b0769c4..dc032b360 100644 --- a/src/haswell/bitmanipulation.h +++ b/src/haswell/bitmanipulation.h @@ -53,23 +53,6 @@ really_inline bool add_overflow(uint64_t value1, uint64_t value2, #endif } -#if 0 // Currently unused -#if defined(SIMDJSON_REGULAR_VISUAL_STUDIO) || defined(SIMDJSON_IS_32BITS) -#pragma intrinsic(_umul128) -#endif -really_inline bool mul_overflow(uint64_t value1, uint64_t value2, - uint64_t *result) { -#ifdef SIMDJSON_REGULAR_VISUAL_STUDIO - uint64_t high; - *result = _umul128(value1, value2, &high); - return high; -#else - return __builtin_umulll_overflow(value1, value2, - (unsigned long long *)result); -#endif -} -#endif // Currently unused - } // namespace SIMDJSON_IMPLEMENTATION } // namespace { diff --git a/src/westmere/bitmanipulation.h b/src/westmere/bitmanipulation.h index d221f971b..63e12691c 100644 --- a/src/westmere/bitmanipulation.h +++ b/src/westmere/bitmanipulation.h @@ -62,23 +62,6 @@ really_inline bool add_overflow(uint64_t value1, uint64_t value2, #endif } -#if 0 // Currently unused -#if defined(SIMDJSON_REGULAR_VISUAL_STUDIO) || defined(SIMDJSON_IS_32BITS) -#pragma intrinsic(_umul128) -#endif -really_inline bool mul_overflow(uint64_t value1, uint64_t value2, - uint64_t *result) { -#ifdef SIMDJSON_REGULAR_VISUAL_STUDIO - uint64_t high; - *result = _umul128(value1, value2, &high); - return high; -#else - return __builtin_umulll_overflow(value1, value2, - (unsigned long long *)result); -#endif -} -#endif // Currently unused - } // namespace SIMDJSON_IMPLEMENTATION } // namespace {