Skip to content

Commit eb147d9

Browse files
committed
Mark jsonformatutils.h/isadetection.h internal
- Move jsonformatutils.h to internal/jsonformatutils.h (it is used by document::print_json) - Move isadetection.h to src/ (it is only used internally)
1 parent f58a5d5 commit eb147d9

13 files changed

+42
-47
lines changed

Makefile

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -62,10 +62,10 @@ SRCHEADERS_GENERIC=src/generic/numberparsing.h src/generic/stage1_find_marks.h s
6262
SRCHEADERS_ARM64= src/arm64/bitmanipulation.h src/arm64/bitmask.h src/arm64/intrinsics.h src/arm64/numberparsing.h src/arm64/simd.h src/arm64/stage1_find_marks.h src/arm64/stage2_build_tape.h src/arm64/stringparsing.h
6363
SRCHEADERS_HASWELL= src/haswell/bitmanipulation.h src/haswell/bitmask.h src/haswell/intrinsics.h src/haswell/numberparsing.h src/haswell/simd.h src/haswell/stage1_find_marks.h src/haswell/stage2_build_tape.h src/haswell/stringparsing.h
6464
SRCHEADERS_WESTMERE=src/westmere/bitmanipulation.h src/westmere/bitmask.h src/westmere/intrinsics.h src/westmere/numberparsing.h src/westmere/simd.h src/westmere/stage1_find_marks.h src/westmere/stage2_build_tape.h src/westmere/stringparsing.h
65-
SRCHEADERS_SRC=src/jsoncharutils.h src/simdprune_tables.h src/error.cpp src/jsonioutil.cpp src/implementation.cpp src/stage1_find_marks.cpp src/stage2_build_tape.cpp src/inline/document_parser_callbacks.h
65+
SRCHEADERS_SRC=src/isadetection.h src/jsoncharutils.h src/simdprune_tables.h src/error.cpp src/jsonioutil.cpp src/implementation.cpp src/stage1_find_marks.cpp src/stage2_build_tape.cpp src/inline/document_parser_callbacks.h
6666
SRCHEADERS=$(SRCHEADERS_SRC) $(SRCHEADERS_GENERIC) $(SRCHEADERS_ARM64) $(SRCHEADERS_HASWELL) $(SRCHEADERS_WESTMERE)
6767

68-
INCLUDEHEADERS=include/simdjson.h include/simdjson/common_defs.h include/simdjson/isadetection.h include/simdjson/jsonformatutils.h include/simdjson/jsonioutil.h include/simdjson/jsonminifier.h include/simdjson/jsonparser.h include/simdjson/padded_string.h include/simdjson/document.h include/simdjson/inline/document.h include/simdjson/document_iterator.h include/simdjson/inline/document_iterator.h include/simdjson/implementation.h include/simdjson/parsedjson.h include/simdjson/jsonstream.h include/simdjson/portability.h include/simdjson/error.h include/simdjson/simdjson.h include/simdjson/simdjson_version.h
68+
INCLUDEHEADERS=include/simdjson.h include/simdjson/common_defs.h include/simdjson/internal/jsonformatutils.h include/simdjson/jsonioutil.h include/simdjson/jsonminifier.h include/simdjson/jsonparser.h include/simdjson/padded_string.h include/simdjson/document.h include/simdjson/inline/document.h include/simdjson/document_iterator.h include/simdjson/inline/document_iterator.h include/simdjson/implementation.h include/simdjson/parsedjson.h include/simdjson/jsonstream.h include/simdjson/portability.h include/simdjson/error.h include/simdjson/simdjson.h include/simdjson/simdjson_version.h
6969

7070
ifeq ($(SIMDJSON_TEST_AMALGAMATED_HEADERS),1)
7171
HEADERS=singleheader/simdjson.h

include/CMakeLists.txt

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -8,8 +8,7 @@ set(SIMDJSON_INCLUDE
88
${SIMDJSON_INCLUDE_DIR}/simdjson/implementation.h
99
${SIMDJSON_INCLUDE_DIR}/simdjson/inline/document.h
1010
${SIMDJSON_INCLUDE_DIR}/simdjson/inline/document_iterator.h
11-
${SIMDJSON_INCLUDE_DIR}/simdjson/isadetection.h
12-
${SIMDJSON_INCLUDE_DIR}/simdjson/jsonformatutils.h
11+
${SIMDJSON_INCLUDE_DIR}/simdjson/internal/jsonformatutils.h
1312
${SIMDJSON_INCLUDE_DIR}/simdjson/jsonioutil.h
1413
${SIMDJSON_INCLUDE_DIR}/simdjson/jsonminifier.h
1514
${SIMDJSON_INCLUDE_DIR}/simdjson/jsonparser.h

include/simdjson/document_iterator.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@
99
#include <stdexcept>
1010

1111
#include "simdjson/document.h"
12-
#include "simdjson/jsonformatutils.h"
12+
#include "simdjson/internal/jsonformatutils.h"
1313

1414
namespace simdjson {
1515

include/simdjson/inline/document.h

Lines changed: 5 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,15 +1,13 @@
11
#ifndef SIMDJSON_INLINE_DOCUMENT_H
22
#define SIMDJSON_INLINE_DOCUMENT_H
33

4-
5-
// Inline implementations go in here if they aren't small enough to go in the class itself or if
6-
// there are complex header file dependencies that need to be broken by externalizing the
7-
// implementation.
4+
// Inline implementations go in here.
85

96
#include "simdjson/document.h"
107
#include "simdjson/implementation.h"
11-
#include "simdjson/jsonformatutils.h"
8+
#include "simdjson/internal/jsonformatutils.h"
129
#include <iostream>
10+
1311
namespace simdjson {
1412

1513
//
@@ -278,7 +276,7 @@ inline bool document::print_json(std::ostream &os, size_t max_depth) const noexc
278276
case '"': // we have a string
279277
os << '"';
280278
memcpy(&string_length, string_buf.get() + payload, sizeof(uint32_t));
281-
print_with_escapes(
279+
internal::print_with_escapes(
282280
(const unsigned char *)(string_buf.get() + payload + sizeof(uint32_t)),
283281
os, string_length);
284282
os << '"';
@@ -368,7 +366,7 @@ inline bool document::dump_raw_tape(std::ostream &os) const noexcept {
368366
case '"': // we have a string
369367
os << "string \"";
370368
memcpy(&string_length, string_buf.get() + payload, sizeof(uint32_t));
371-
print_with_escapes(
369+
internal::print_with_escapes(
372370
(const unsigned char *)(string_buf.get() + payload + sizeof(uint32_t)),
373371
os,
374372
string_length);

include/simdjson/inline/document_iterator.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -276,7 +276,7 @@ bool document_iterator<max_depth>::print(std::ostream &os, bool escape_strings)
276276
case '"': // we have a string
277277
os << '"';
278278
if (escape_strings) {
279-
print_with_escapes(get_string(), os, get_string_length());
279+
internal::print_with_escapes(get_string(), os, get_string_length());
280280
} else {
281281
// was: os << get_string();, but given that we can include null chars, we
282282
// have to do something crazier:

include/simdjson/jsonformatutils.h renamed to include/simdjson/internal/jsonformatutils.h

Lines changed: 8 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1,15 +1,13 @@
1-
#ifndef SIMDJSON_JSONFORMATUTILS_H
2-
#define SIMDJSON_JSONFORMATUTILS_H
1+
#ifndef SIMDJSON_INTERNAL_JSONFORMATUTILS_H
2+
#define SIMDJSON_INTERNAL_JSONFORMATUTILS_H
33

44
#include <iomanip>
55
#include <iostream>
66

7-
namespace simdjson {
8-
7+
namespace simdjson::internal {
98

109
// ends with zero char
11-
static inline void print_with_escapes(const unsigned char *src,
12-
std::ostream &os) {
10+
static inline void print_with_escapes(const unsigned char *src, std::ostream &os) {
1311
while (*src) {
1412
switch (*src) {
1513
case '\b':
@@ -107,10 +105,10 @@ static inline void print_with_escapes(const char *src, std::ostream &os) {
107105
print_with_escapes(reinterpret_cast<const unsigned char *>(src), os);
108106
}
109107

110-
static inline void print_with_escapes(const char *src, std::ostream &os,
111-
size_t len) {
108+
static inline void print_with_escapes(const char *src, std::ostream &os, size_t len) {
112109
print_with_escapes(reinterpret_cast<const unsigned char *>(src), os, len);
113110
}
114-
} // namespace simdjson
115111

116-
#endif
112+
} // namespace simdjson::internal
113+
114+
#endif // SIMDJSON_INTERNAL_JSONFORMATUTILS_H

include/simdjson/jsonstream.h

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,6 @@
55
#include <limits>
66
#include <stdexcept>
77
#include <thread>
8-
#include "simdjson/isadetection.h"
98
#include "simdjson/padded_string.h"
109
#include "simdjson/simdjson.h"
1110
#include "jsoncharutils.h"

src/CMakeLists.txt

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,7 @@ set(SIMDJSON_SRC
2929
set(SIMDJSON_SRC_HEADERS
3030
error.cpp
3131
implementation.cpp
32+
isadetection.h
3233
jsoncharutils.h
3334
jsonioutil.cpp
3435
jsonminifier.cpp

src/arm64/implementation.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@
66
#ifdef IS_ARM64
77

88
#include "simdjson/implementation.h"
9-
#include "simdjson/isadetection.h"
9+
#include "isadetection.h"
1010

1111
namespace simdjson::arm64 {
1212

src/haswell/implementation.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@
66
#ifdef IS_X86_64
77

88
#include "simdjson/implementation.h"
9-
#include "simdjson/isadetection.h"
9+
#include "isadetection.h"
1010

1111
namespace simdjson::haswell {
1212

src/implementation.cpp

Lines changed: 15 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
#include "simdjson/portability.h"
2-
#include "simdjson/isadetection.h"
2+
#include "isadetection.h"
33
#include "simdjson/implementation.h"
44
#include <initializer_list>
55

@@ -11,10 +11,10 @@
1111
#include "haswell/implementation.h"
1212
#include "westmere/implementation.h"
1313

14-
namespace simdjson {
15-
const haswell::implementation haswell_singleton{};
16-
const westmere::implementation westmere_singleton{};
17-
constexpr const std::initializer_list<const implementation *> available_implementation_pointers { &haswell_singleton, &westmere_singleton };
14+
namespace simdjson::internal {
15+
const haswell::implementation haswell_singleton{};
16+
const westmere::implementation westmere_singleton{};
17+
constexpr const std::initializer_list<const implementation *> available_implementation_pointers { &haswell_singleton, &westmere_singleton };
1818
}
1919

2020
#endif
@@ -23,19 +23,20 @@ namespace simdjson {
2323

2424
#include "arm64/implementation.h"
2525

26-
namespace simdjson {
27-
const arm64::implementation arm64_singleton{};
28-
constexpr const std::initializer_list<const implementation *> available_implementation_pointers { &arm64_singleton };
26+
namespace simdjson::internal {
27+
const arm64::implementation arm64_singleton{};
28+
constexpr const std::initializer_list<const implementation *> available_implementation_pointers { &arm64_singleton };
2929
}
3030

3131
#endif
3232

33-
namespace simdjson {
33+
34+
namespace simdjson::internal {
3435

3536
// So we can return UNSUPPORTED_ARCHITECTURE from the parser when there is no support
3637
class unsupported_implementation final : public implementation {
3738
public:
38-
WARN_UNUSED virtual error_code parse(const uint8_t *, size_t, document::parser &) const noexcept final {
39+
WARN_UNUSED error_code parse(const uint8_t *, size_t, document::parser &) const noexcept final {
3940
return UNSUPPORTED_ARCHITECTURE;
4041
}
4142
WARN_UNUSED error_code stage1(const uint8_t *, size_t, document::parser &, bool) const noexcept final {
@@ -53,21 +54,19 @@ class unsupported_implementation final : public implementation {
5354

5455
const unsupported_implementation unsupported_singleton{};
5556

56-
namespace internal {
57-
5857
size_t available_implementation_list::size() const noexcept {
59-
return available_implementation_pointers.size();
58+
return internal::available_implementation_pointers.size();
6059
}
6160
const implementation * const *available_implementation_list::begin() const noexcept {
62-
return available_implementation_pointers.begin();
61+
return internal::available_implementation_pointers.begin();
6362
}
6463
const implementation * const *available_implementation_list::end() const noexcept {
65-
return available_implementation_pointers.end();
64+
return internal::available_implementation_pointers.end();
6665
}
6766
const implementation *available_implementation_list::detect_best_supported() const noexcept {
6867
// They are prelisted in priority order, so we just go down the list
6968
uint32_t supported_instruction_sets = detect_supported_architectures();
70-
for (const implementation *impl : available_implementation_pointers) {
69+
for (const implementation *impl : internal::available_implementation_pointers) {
7170
uint32_t required_instruction_sets = impl->required_instruction_sets();
7271
if ((supported_instruction_sets & required_instruction_sets) == required_instruction_sets) { return impl; }
7372
}
@@ -78,6 +77,4 @@ const implementation *detect_best_supported_implementation_on_first_use::set_bes
7877
return active_implementation = available_implementations.detect_best_supported();
7978
}
8079

81-
} // namespace simdjson::internal
82-
8380
} // namespace simdjson

include/simdjson/isadetection.h renamed to src/isadetection.h

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -55,6 +55,7 @@ POSSIBILITY OF SUCH DAMAGE.
5555
#endif
5656

5757
namespace simdjson {
58+
5859
// Can be found on Intel ISA Reference for CPUID
5960
constexpr uint32_t cpuid_avx2_bit = 1 << 5; // Bit 5 of EBX for EAX=0x7
6061
constexpr uint32_t cpuid_bmi1_bit = 1 << 3; // bit 3 of EBX for EAX=0x7
@@ -148,5 +149,7 @@ static inline uint32_t detect_supported_architectures() {
148149
}
149150

150151
#endif // end SIMD extension detection code
151-
} // namespace simdjson
152-
#endif
152+
153+
} // namespace simdjson::internal
154+
155+
#endif // SIMDJSON_ISADETECTION_H

src/westmere/implementation.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@
66
#ifdef IS_X86_64
77

88
#include "simdjson/implementation.h"
9-
#include "simdjson/isadetection.h"
9+
#include "isadetection.h"
1010

1111
namespace simdjson::westmere {
1212

0 commit comments

Comments
 (0)