mirror of
https://github.com/simdjson/simdjson
synced 2026-06-08 17:27:07 +00:00
Compare commits
56 Commits
| Author | SHA1 | Date | |
|---|---|---|---|
| e38fe3d361 | |||
| cc042c9936 | |||
| 599e3bc937 | |||
| 1fa0d940bc | |||
| 7dc4a9525b | |||
| b6f1f4ef64 | |||
| 3faae67663 | |||
| ccc94c9b05 | |||
| 1fd30db726 | |||
| 0ba76ac066 | |||
| 8b661fe556 | |||
| 077907b7c3 | |||
| 172d669780 | |||
| 6b85b9a416 | |||
| 5d3001279c | |||
| 4582a13360 | |||
| 3a064535ae | |||
| 444ec4ad27 | |||
| 94e910586d | |||
| bb5ce007e6 | |||
| deaa74d378 | |||
| 13e1794e91 | |||
| 67b3595008 | |||
| 6c33f518a8 | |||
| 88da62ba09 | |||
| b6997a56df | |||
| 74178fd1c2 | |||
| 34c59bfa90 | |||
| 2956bce047 | |||
| 41f33ecbb9 | |||
| 86241e2871 | |||
| 1e32897d3e | |||
| 1b63a9a9b5 | |||
| 4c9f11b78a | |||
| 32348c2b0b | |||
| 5e690c5d04 | |||
| 4ec56484a1 | |||
| 8f2a5649fe | |||
| c3b25e12a5 | |||
| 6d3e33d440 | |||
| c11f7ce54f | |||
| 84806cc174 | |||
| 16f12f7d59 | |||
| 8609b8e589 | |||
| 29e744fdbb | |||
| 515b87bcbe | |||
| 5fa9faca20 | |||
| a4ebdfd47c | |||
| 188d8d4b64 | |||
| ce5581d428 | |||
| 5b4acf14ea | |||
| 5fc6cb15b8 | |||
| f6e9a8eee4 | |||
| 6c0950cb2e | |||
| cb8a9ef2c0 | |||
| 470cbbe9ff |
@@ -20,6 +20,10 @@ environment:
|
||||
platform: Win32
|
||||
CMAKE_ARGS: -A %Platform% -DSIMDJSON_BUILD_STATIC=OFF -DSIMDJSON_ENABLE_THREADS=ON # This should be the default. Testing anyway.
|
||||
CTEST_ARGS: -E checkperf
|
||||
- job_name: VS2015
|
||||
image: Visual Studio 2015
|
||||
CMAKE_ARGS: -A %Platform% -DSIMDJSON_BUILD_STATIC=ON -DSIMDJSON_ENABLE_THREADS=OFF
|
||||
CTEST_ARGS: -E checkperf
|
||||
|
||||
build_script:
|
||||
- mkdir build
|
||||
|
||||
@@ -121,10 +121,10 @@ jobs:
|
||||
justlib-gcc10:
|
||||
description: Build just the library, install it and do a basic test
|
||||
executor: gcc10
|
||||
environment: { CMAKE_FLAGS: -SIMDJSON_JUST_LIBRARY=ON }
|
||||
environment: { CMAKE_FLAGS: -DSIMDJSON_JUST_LIBRARY=ON }
|
||||
steps: [ cmake_build, cmake_install_test ]
|
||||
gcc10:
|
||||
description: Build and run tests on GCC 10 and AVX 2 with a cmake static build
|
||||
description: Build and run tests on GCC 10 and AVX 2 with a cmake static build, this test performance regression
|
||||
executor: gcc10
|
||||
environment: { CMAKE_FLAGS: -DSIMDJSON_GOOGLE_BENCHMARKS=ON -DSIMDJSON_BUILD_STATIC=ON }
|
||||
steps: [ cmake_test_all, cmake_install_test ]
|
||||
@@ -219,7 +219,7 @@ workflows:
|
||||
jobs:
|
||||
# full multi-implementation tests
|
||||
- gcc7
|
||||
#- gcc10 # this gets tested a lot below
|
||||
- gcc10 # do not delete this as it tests our performance
|
||||
- clang6
|
||||
#- clang10 # this gets tested a lot below
|
||||
|
||||
|
||||
+65
@@ -1,4 +1,46 @@
|
||||
kind: pipeline
|
||||
name: i386-gcc # we do not support 32-bit systems, but we run tests
|
||||
platform: { os: linux, arch: amd64 }
|
||||
steps:
|
||||
- name: Build and Test
|
||||
image: i386/ubuntu
|
||||
environment:
|
||||
CC: gcc
|
||||
CXX: g++
|
||||
BUILD_FLAGS: -- -j
|
||||
CMAKE_FLAGS: -DSIMDJSON_BUILD_STATIC=ON
|
||||
CTEST_FLAGS: -j4 --output-on-failure -E checkperf
|
||||
commands:
|
||||
- apt-get update -qq
|
||||
- apt-get install -y g++ cmake gcc
|
||||
- mkdir build
|
||||
- cd build
|
||||
- cmake $CMAKE_FLAGS ..
|
||||
- cmake --build . $BUILD_FLAGS
|
||||
- ctest $CTEST_FLAGS
|
||||
---
|
||||
kind: pipeline
|
||||
name: i386-clang # we do not support 32-bit systems, but we run tests
|
||||
platform: { os: linux, arch: amd64 }
|
||||
steps:
|
||||
- name: Build and Test
|
||||
image: i386/ubuntu
|
||||
environment:
|
||||
CC: clang-6.0
|
||||
CXX: clang++-6.0
|
||||
BUILD_FLAGS: -- -j
|
||||
CMAKE_FLAGS: -DSIMDJSON_BUILD_STATIC=ON
|
||||
CTEST_FLAGS: -j4 --output-on-failure -E checkperf
|
||||
commands:
|
||||
- apt-get update -qq
|
||||
- apt-get install -y clang++-6.0 cmake
|
||||
- mkdir build
|
||||
- cd build
|
||||
- cmake $CMAKE_FLAGS ..
|
||||
- cmake --build . $BUILD_FLAGS
|
||||
- ctest $CTEST_FLAGS
|
||||
---
|
||||
kind: pipeline
|
||||
name: gcc9
|
||||
platform: { os: linux, arch: amd64 }
|
||||
steps:
|
||||
@@ -273,6 +315,29 @@ steps:
|
||||
- ASAN_OPTIONS="detect_leaks=0" ctest $CTEST_FLAGS -LE "acceptance|per_implementation" # Everything we haven't run yet, run now.
|
||||
---
|
||||
kind: pipeline
|
||||
name: ninja-clang9
|
||||
platform: { os: linux, arch: amd64 }
|
||||
steps:
|
||||
- name: Build and Test
|
||||
image: conanio/clang9
|
||||
user: root
|
||||
environment:
|
||||
CC: clang-9
|
||||
CXX: clang++-9
|
||||
BUILD_FLAGS: -- -j 4
|
||||
CMAKE_FLAGS: -GNinja -DSIMDJSON_BUILD_STATIC=ON
|
||||
CTEST_FLAGS: -j4 --output-on-failure
|
||||
CXXFLAGS: -stdlib=libc++
|
||||
commands:
|
||||
- apt-get update -qq
|
||||
- apt-get install -y cmake
|
||||
- mkdir build
|
||||
- cd build
|
||||
- cmake $CMAKE_FLAGS ..
|
||||
- cmake --build . $BUILD_FLAGS
|
||||
- ctest $CTEST_FLAGS
|
||||
---
|
||||
kind: pipeline
|
||||
name: libcpp-clang9
|
||||
platform: { os: linux, arch: amd64 }
|
||||
steps:
|
||||
|
||||
@@ -0,0 +1,54 @@
|
||||
name: MinGW32-CI
|
||||
|
||||
on: push
|
||||
|
||||
|
||||
# Important: scoop will either install 32-bit GCC or 64-bit GCC, not both.
|
||||
|
||||
# It is important to build static libraries because cmake is not smart enough under Windows/mingw to take care of the path. So
|
||||
# with a dynamic library, you could get failures due to the fact that the EXE can't find its DLL.
|
||||
|
||||
jobs:
|
||||
ci:
|
||||
name: windows-gcc
|
||||
runs-on: windows-2016
|
||||
|
||||
env:
|
||||
CMAKE_GENERATOR: Ninja # This is critical, try ' cmake -GNinja-DSIMDJSON_BUILD_STATIC=ON .. ' if using the command line
|
||||
CC: gcc
|
||||
CXX: g++
|
||||
|
||||
steps: # To reproduce what is below, start a powershell with administrative rights, using scoop *is* a good idea
|
||||
- uses: actions/checkout@v2
|
||||
|
||||
- uses: actions/cache@v2 # we cache the scoop setup with 32-bit GCC
|
||||
id: cache
|
||||
with:
|
||||
path: |
|
||||
C:\ProgramData\scoop
|
||||
key: scoop32 # static key: should be good forever
|
||||
- name: Setup Windows # This should almost never run if the cache works.
|
||||
if: steps.cache.outputs.cache-hit != 'true'
|
||||
shell: powershell
|
||||
run: |
|
||||
Invoke-Expression (New-Object System.Net.WebClient).DownloadString('https://get.scoop.sh')
|
||||
scoop install sudo --global
|
||||
sudo scoop install git --global
|
||||
sudo scoop install ninja --global
|
||||
sudo scoop install cmake --global
|
||||
sudo scoop install gcc --arch 32bit --global
|
||||
$env:path
|
||||
Write-Host 'Everything has been installed, you are good!'
|
||||
- name: Build and Test 32-bit x86
|
||||
shell: powershell
|
||||
run: |
|
||||
$ENV:PATH="$ENV:PATH;C:\ProgramData\scoop\apps\gcc\current\bin;C:\ProgramData\scoop\shims;C:\Users\runneradmin\scoop\shims"
|
||||
mkdir build32
|
||||
cd build32
|
||||
cmake -DSIMDJSON_BUILD_STATIC=ON -DSIMDJSON_COMPETITION=OFF -DSIMDJSON_GOOGLE_BENCHMARKS=OFF -DSIMDJSON_ENABLE_THREADS=OFF ..
|
||||
cmake --build . --target basictests numberparsingcheck stringparsingcheck errortests integer_tests pointercheck --verbose
|
||||
ctest . -R stringparsingcheck --output-on-failure
|
||||
ctest . -R numberparsingcheck --output-on-failure
|
||||
ctest . -R errortests --output-on-failure
|
||||
ctest . -R integer_tests --output-on-failure
|
||||
ctest . -R pointercheck --output-on-failure
|
||||
@@ -0,0 +1,56 @@
|
||||
name: MinGW64-CI
|
||||
|
||||
on: push
|
||||
|
||||
|
||||
# Important: scoop will either install 32-bit GCC or 64-bit GCC, not both.
|
||||
|
||||
# It is important to build static libraries because cmake is not smart enough under Windows/mingw to take care of the path. So
|
||||
# with a dynamic library, you could get failures due to the fact that the EXE can't find its DLL.
|
||||
|
||||
jobs:
|
||||
ci:
|
||||
name: windows-gcc
|
||||
runs-on: windows-2016
|
||||
|
||||
env:
|
||||
CMAKE_GENERATOR: Ninja # This is critical, try ' cmake -GNinja-DSIMDJSON_BUILD_STATIC=ON .. ' if using the command line
|
||||
CC: gcc
|
||||
CXX: g++
|
||||
|
||||
steps: # To reproduce what is below, start a powershell with administrative rights, using scoop *is* a good idea
|
||||
- uses: actions/checkout@v2
|
||||
|
||||
|
||||
- uses: actions/cache@v2 # we cache the scoop setup with 64-bit GCC
|
||||
id: cache
|
||||
with:
|
||||
path: |
|
||||
C:\ProgramData\scoop
|
||||
key: scoop64 # static key: should be good forever
|
||||
- name: Setup Windows # This should almost never run if the cache works.
|
||||
if: steps.cache.outputs.cache-hit != 'true'
|
||||
shell: powershell
|
||||
run: |
|
||||
Invoke-Expression (New-Object System.Net.WebClient).DownloadString('https://get.scoop.sh')
|
||||
scoop install sudo --global
|
||||
sudo scoop install git --global
|
||||
sudo scoop install ninja --global
|
||||
sudo scoop install cmake --global
|
||||
sudo scoop install gcc --arch 64bit --global
|
||||
$env:path
|
||||
Write-Host 'Everything has been installed, you are good!'
|
||||
- name: Build and Test 64-bit x64
|
||||
shell: powershell
|
||||
run: |
|
||||
$ENV:PATH="$ENV:PATH;C:\ProgramData\scoop\apps\gcc\current\bin;C:\ProgramData\scoop\shims;C:\Users\runneradmin\scoop\shims"
|
||||
mkdir build64
|
||||
cd build64
|
||||
cmake -DSIMDJSON_BUILD_STATIC=ON -DSIMDJSON_COMPETITION=OFF -DSIMDJSON_GOOGLE_BENCHMARKS=OFF -DSIMDJSON_ENABLE_THREADS=OFF ..
|
||||
cmake --build . --target basictests numberparsingcheck stringparsingcheck errortests integer_tests pointercheck --verbose
|
||||
ctest . -R stringparsingcheck --output-on-failure
|
||||
ctest . -R numberparsingcheck --output-on-failure
|
||||
ctest . -R errortests --output-on-failure
|
||||
ctest . -R integer_tests --output-on-failure
|
||||
ctest . -R pointercheck --output-on-failure
|
||||
|
||||
+12
-6
@@ -7,17 +7,23 @@ project(simdjson
|
||||
|
||||
set(PROJECT_VERSION_MAJOR 0)
|
||||
set(PROJECT_VERSION_MINOR 4)
|
||||
set(PROJECT_VERSION_PATCH 0)
|
||||
set(SIMDJSON_LIB_VERSION "0.4.0" CACHE STRING "simdjson library version")
|
||||
set(PROJECT_VERSION_PATCH 4)
|
||||
set(SIMDJSON_LIB_VERSION "0.4.4" CACHE STRING "simdjson library version")
|
||||
set(SIMDJSON_LIB_SOVERSION "2" CACHE STRING "simdjson library soversion")
|
||||
set(SIMDJSON_GITHUB_REPOSITORY https://github.com/simdjson/simdjson)
|
||||
|
||||
# The SIMDJSON_LIB_SOVERSION is 0 for versions before 0.3.0.
|
||||
# The SIMDJSON_LIB_SOVERSION is 1 for version 0.3.
|
||||
# The SIMDJSON_LIB_SOVERSION is 2 for version 0.4.
|
||||
|
||||
include(GNUInstallDirs)
|
||||
include(cmake/simdjson-flags.cmake)
|
||||
include(cmake/simdjson-user-cmakecache.cmake)
|
||||
|
||||
|
||||
|
||||
if(SIMDJSON_JUST_LIBRARY)
|
||||
MESSAGE( STATUS "Building just the library, omitting all tests, tools and benchmarks." )
|
||||
message( STATUS "Building just the library, omitting all tests, tools and benchmarks." )
|
||||
endif()
|
||||
|
||||
#
|
||||
@@ -39,15 +45,15 @@ add_subdirectory(include)
|
||||
add_subdirectory(src)
|
||||
add_subdirectory(windows)
|
||||
if(NOT(SIMDJSON_JUST_LIBRARY))
|
||||
add_subdirectory(tools)
|
||||
add_subdirectory(singleheader)
|
||||
add_subdirectory(dependencies) ## This needs to be before tools because of cxxopts
|
||||
add_subdirectory(tools) ## This needs to be before tests because of cxxopts
|
||||
endif()
|
||||
add_subdirectory(singleheader)
|
||||
|
||||
#
|
||||
# Compile tools / tests / benchmarks
|
||||
#
|
||||
if(NOT(SIMDJSON_JUST_LIBRARY))
|
||||
add_subdirectory(dependencies)
|
||||
add_subdirectory(tests)
|
||||
add_subdirectory(examples)
|
||||
add_subdirectory(benchmark)
|
||||
|
||||
@@ -34,5 +34,6 @@ Dušan Jovanović
|
||||
Matjaž Ostroveršnik
|
||||
Nong Li
|
||||
Furkan Taşkale
|
||||
Brendan Knapp
|
||||
# if you have contributed to the project and your name does not
|
||||
# appear in this list, please let us know!
|
||||
|
||||
@@ -38,7 +38,7 @@ PROJECT_NAME = simdjson
|
||||
# could be handy for archiving the generated documentation or if some version
|
||||
# control system is used.
|
||||
|
||||
PROJECT_NUMBER = "0.4.0"
|
||||
PROJECT_NUMBER = "0.4.4"
|
||||
|
||||
# Using the PROJECT_BRIEF tag one can provide an optional one line description
|
||||
# for a project that appears at the top of each page and should give viewer a
|
||||
@@ -1026,7 +1026,7 @@ FILTER_SOURCE_PATTERNS =
|
||||
# (index.html). This can be useful if you have a project on for instance GitHub
|
||||
# and want to reuse the introduction page also for the doxygen output.
|
||||
|
||||
USE_MDFILE_AS_MAINPAGE = doc/basics.md
|
||||
USE_MDFILE_AS_MAINPAGE = doc/basics_doxygen.md
|
||||
|
||||
#---------------------------------------------------------------------------
|
||||
# Configuration options related to source browsing
|
||||
|
||||
@@ -1,8 +1,10 @@
|
||||
[](https://cloud.drone.io/simdjson/simdjson)
|
||||
[](https://bugs.chromium.org/p/oss-fuzz/issues/list?sort=-opened&q=proj%3Asimdjson&can=2)
|
||||
[](https://ci.appveyor.com/project/lemire/simdjson-jmmti/branch/master)
|
||||
[](https://circleci.com/gh/simdjson/simdjson)
|
||||
[](https://cirrus-ci.com/github/simdjson/simdjson)
|
||||
[![][license img]][license] [](https://simdjson.org/api/0.3.1/index.html)
|
||||

|
||||
[![][license img]][license] [](https://simdjson.org/api/0.4.0/index.html)
|
||||
|
||||
simdjson : Parsing gigabytes of JSON per second
|
||||
===============================================
|
||||
|
||||
@@ -14,13 +14,13 @@ target_compile_definitions(parse_nonumberparsing PRIVATE SIMDJSON_SKIPNUMBERPARS
|
||||
add_executable(parse_nostringparsing parse.cpp)
|
||||
target_compile_definitions(parse_nostringparsing PRIVATE SIMDJSON_SKIPSTRINGPARSING)
|
||||
|
||||
if (SIMDJSON_GOOGLE_BENCHMARKS)
|
||||
if (TARGET benchmark::benchmark)
|
||||
link_libraries(benchmark::benchmark)
|
||||
add_executable(bench_parse_call bench_parse_call.cpp)
|
||||
add_executable(bench_dom_api bench_dom_api.cpp)
|
||||
endif()
|
||||
|
||||
if (SIMDJSON_COMPETITION)
|
||||
if (TARGET competition-all)
|
||||
add_executable(distinctuseridcompetition distinctuseridcompetition.cpp)
|
||||
target_link_libraries(distinctuseridcompetition competition-core)
|
||||
add_executable(minifiercompetition minifiercompetition.cpp)
|
||||
|
||||
@@ -7,7 +7,8 @@
|
||||
|
||||
# Clone the repository if it's not there
|
||||
find_package(Git QUIET)
|
||||
if (Git_FOUND)
|
||||
if (SIMDJSON_IS_UNDER_GIT AND Git_FOUND AND (GIT_VERSION_STRING VERSION_GREATER "2.1.4") AND (NOT CMAKE_GENERATOR MATCHES Ninja) ) # We use "-C" which requires a recent git
|
||||
message(STATUS "Git is available and it is recent. We are enabling checkperf targets.")
|
||||
# sync_git_repository(myrepo ...) creates two targets:
|
||||
# myrepo - if the repo does not exist, creates and syncs it against the origin branch
|
||||
# update_myrepo - will update the repo against the origin branch (and create if needed)
|
||||
@@ -91,5 +92,10 @@ if (Git_FOUND)
|
||||
set_property(TEST checkperf APPEND PROPERTY LABELS per_implementation)
|
||||
set_property(TEST checkperf APPEND PROPERTY DEPENDS parse perfdiff ${SIMDJSON_USER_CMAKECACHE})
|
||||
set_property(TEST checkperf PROPERTY RUN_SERIAL TRUE)
|
||||
|
||||
endif (Git_FOUND)
|
||||
else()
|
||||
if (CMAKE_GENERATOR MATCHES Ninja)
|
||||
message(STATUS "We disable the checkperf targets under Ninja.")
|
||||
else()
|
||||
message(STATUS "Either git is unavailable or else it is too old. We are disabling checkperf targets.")
|
||||
endif()
|
||||
endif ()
|
||||
|
||||
@@ -1,4 +1,21 @@
|
||||
option(SIMDJSON_JUST_LIBRARY "Build just the library, omit tests, tools and benchmarks" OFF)
|
||||
|
||||
if(CMAKE_SOURCE_DIR STREQUAL CMAKE_CURRENT_SOURCE_DIR)
|
||||
message (STATUS "The simdjson repository appears to be standalone.")
|
||||
option(SIMDJSON_JUST_LIBRARY "Build just the library, omit tests, tools and benchmarks" OFF)
|
||||
message (STATUS "By default, we attempt to build everything.")
|
||||
else()
|
||||
message (STATUS "The simdjson repository appears to be used as a subdirectory.")
|
||||
option(SIMDJSON_JUST_LIBRARY "Build just the library, omit tests, tools and benchmarks" ON)
|
||||
message (STATUS "By default, we just build the library.")
|
||||
endif()
|
||||
|
||||
if(EXISTS ${CMAKE_CURRENT_SOURCE_DIR}/.git)
|
||||
set(SIMDJSON_IS_UNDER_GIT ON CACHE BOOL "Whether cmake is under git control")
|
||||
message( STATUS "The simdjson repository appears to be under git." )
|
||||
else()
|
||||
set(SIMDJSON_IS_UNDER_GIT OFF CACHE BOOL "Whether cmake is under git control")
|
||||
message( STATUS "The simdjson repository does not appear to be under git." )
|
||||
endif()
|
||||
|
||||
#
|
||||
# Flags used by exes and by the simdjson library (project-wide flags)
|
||||
@@ -36,6 +53,9 @@ endif()
|
||||
option(SIMDJSON_COMPETITION "Compile competitive benchmarks" ON)
|
||||
|
||||
option(SIMDJSON_GOOGLE_BENCHMARKS "compile the Google Benchmark benchmarks" ON)
|
||||
if(SIMDJSON_COMPETITION)
|
||||
message(STATUS "Using SIMDJSON_GOOGLE_BENCHMARKS")
|
||||
endif()
|
||||
|
||||
set(CMAKE_MODULE_PATH "${CMAKE_CURRENT_SOURCE_DIR}/tools/cmake")
|
||||
|
||||
@@ -57,7 +77,13 @@ set(THREADS_PREFER_PTHREAD_FLAG ON)
|
||||
|
||||
|
||||
if(MSVC)
|
||||
if("${MSVC_TOOLSET_VERSION}" STREQUAL "140")
|
||||
# Visual Studio 2015 issues warnings and we tolerate it, cmake -G"Visual Studio 14" ..
|
||||
target_compile_options(simdjson-internal-flags INTERFACE /W0 /sdl)
|
||||
else()
|
||||
# Recent version of Visual Studio expected (2017, 2019...). Prior versions are unsupported.
|
||||
target_compile_options(simdjson-internal-flags INTERFACE /WX /W3 /sdl)
|
||||
endif()
|
||||
else()
|
||||
target_compile_options(simdjson-internal-flags INTERFACE -fPIC)
|
||||
target_compile_options(simdjson-internal-flags INTERFACE -Werror -Wall -Wextra -Weffc++)
|
||||
@@ -88,7 +114,7 @@ if(NOT SIMDJSON_EXCEPTIONS)
|
||||
target_compile_definitions(simdjson-internal-flags INTERFACE SIMDJSON_EXCEPTIONS=0)
|
||||
endif()
|
||||
|
||||
option(SIMDJSON_ENABLE_THREADS "Enable threaded operation" ON)
|
||||
option(SIMDJSON_ENABLE_THREADS "Link with thread support" ON)
|
||||
if(SIMDJSON_ENABLE_THREADS)
|
||||
set(CMAKE_THREAD_PREFER_PTHREAD TRUE)
|
||||
set(THREADS_PREFER_PTHREAD_FLAG TRUE)
|
||||
@@ -96,7 +122,18 @@ if(SIMDJSON_ENABLE_THREADS)
|
||||
target_link_libraries(simdjson-flags INTERFACE Threads::Threads)
|
||||
target_link_libraries(simdjson-flags INTERFACE ${CMAKE_THREAD_LIBS_INIT})
|
||||
target_compile_options(simdjson-flags INTERFACE ${CMAKE_THREAD_LIBS_INIT})
|
||||
target_compile_definitions(simdjson-flags INTERFACE SIMDJSON_THREADS_ENABLED=1)
|
||||
target_compile_definitions(simdjson-flags INTERFACE SIMDJSON_THREADS_ENABLED=1) # This will be set in the code automatically.
|
||||
endif()
|
||||
|
||||
# Some users compile simdjson with thread support but still do not want simdjson to use threads.
|
||||
#
|
||||
# Important : Expect this option to disappear in the future.
|
||||
#
|
||||
option(SIMDJSON_DO_NOT_USE_THREADS_NO_MATTER_WHAT "Whether we enabled thread support or not (SIMDJSON_ENABLE_THREADS), do not use threads.\
|
||||
This option does nothing when thread support is not enabled. We reserve the right to remove this option in a future release in\
|
||||
favor of a runtime approach." OFF)
|
||||
if(SIMDJSON_DO_NOT_USE_THREADS_NO_MATTER_WHAT)
|
||||
target_compile_definitions(simdjson-flags INTERFACE SIMDJSON_DO_NOT_USE_THREADS_NO_MATTER_WHAT=1)
|
||||
endif()
|
||||
|
||||
if(SIMDJSON_USE_LIBCPP)
|
||||
|
||||
Vendored
+73
-58
@@ -1,74 +1,89 @@
|
||||
# Initializes a git submodule if it hasn't been initialized before
|
||||
# Does NOT attempt to update or otherwise modify git submodules that are already initialized.
|
||||
function(initialize_submodule DIRECTORY)
|
||||
if(NOT EXISTS ${CMAKE_CURRENT_SOURCE_DIR}/${DIRECTORY}/.git)
|
||||
find_package(Git QUIET REQUIRED)
|
||||
message(STATUS "${CMAKE_CURRENT_SOURCE_DIR}/${DIRECTORY}/.git does not exist. Initializing ${DIRECTORY} submodule ...")
|
||||
execute_process(COMMAND ${GIT_EXECUTABLE} submodule update --init ${CMAKE_CURRENT_SOURCE_DIR}/${DIRECTORY}
|
||||
WORKING_DIRECTORY ${CMAKE_SOURCE_DIR}
|
||||
RESULT_VARIABLE GIT_EXIT_CODE)
|
||||
if(NOT GIT_EXIT_CODE EQUAL "0")
|
||||
message(FATAL_ERROR "${GIT_EXECUTABLE} submodule update --init dependencies/${DIRECTORY} failed with exit code ${GIT_EXIT_CODE}, please checkout submodules")
|
||||
|
||||
|
||||
find_package(Git QUIET) # We want the library to build even if git is missing
|
||||
if ((Git_FOUND) AND (SIMDJSON_IS_UNDER_GIT))
|
||||
message(STATUS "Git is available.")
|
||||
# Does NOT attempt to update or otherwise modify git submodules that are already initialized.
|
||||
function(initialize_submodule DIRECTORY)
|
||||
if(NOT EXISTS ${CMAKE_CURRENT_SOURCE_DIR}/${DIRECTORY}/.git)
|
||||
message(STATUS "${CMAKE_CURRENT_SOURCE_DIR}/${DIRECTORY}/.git does not exist. Initializing ${DIRECTORY} submodule ...")
|
||||
execute_process(COMMAND ${GIT_EXECUTABLE} submodule update --init ${CMAKE_CURRENT_SOURCE_DIR}/${DIRECTORY}
|
||||
WORKING_DIRECTORY ${CMAKE_SOURCE_DIR}
|
||||
RESULT_VARIABLE GIT_EXIT_CODE)
|
||||
if(NOT GIT_EXIT_CODE EQUAL "0")
|
||||
message(FATAL_ERROR "${GIT_EXECUTABLE} submodule update --init dependencies/${DIRECTORY} failed with exit code ${GIT_EXIT_CODE}, please checkout submodules")
|
||||
endif()
|
||||
endif()
|
||||
endfunction(initialize_submodule)
|
||||
|
||||
if (SIMDJSON_GOOGLE_BENCHMARKS)
|
||||
message (STATUS "'SIMDJSON_GOOGLE_BENCHMARKS' is requested, configuring..." )
|
||||
option(BENCHMARK_ENABLE_TESTING OFF)
|
||||
set(BENCHMARK_ENABLE_TESTING OFF)
|
||||
option(BENCHMARK_ENABLE_INSTALL OFF)
|
||||
set(BENCHMARK_ENABLE_INSTALL OFF)
|
||||
initialize_submodule(benchmark)
|
||||
add_subdirectory(benchmark)
|
||||
endif()
|
||||
endfunction(initialize_submodule)
|
||||
|
||||
if (SIMDJSON_GOOGLE_BENCHMARKS)
|
||||
option(BENCHMARK_ENABLE_TESTING OFF)
|
||||
set(BENCHMARK_ENABLE_TESTING OFF)
|
||||
option(BENCHMARK_ENABLE_INSTALL OFF)
|
||||
set(BENCHMARK_ENABLE_INSTALL OFF)
|
||||
initialize_submodule(benchmark)
|
||||
add_subdirectory(benchmark)
|
||||
endif()
|
||||
if (SIMDJSON_COMPETITION)
|
||||
initialize_submodule(cJSON)
|
||||
add_library(competition-cJSON INTERFACE)
|
||||
target_include_directories(competition-cJSON INTERFACE cJSON)
|
||||
|
||||
if (SIMDJSON_COMPETITION)
|
||||
initialize_submodule(cJSON)
|
||||
add_library(competition-cJSON INTERFACE)
|
||||
target_include_directories(competition-cJSON INTERFACE cJSON)
|
||||
initialize_submodule(fastjson)
|
||||
add_library(competition-fastjson INTERFACE)
|
||||
target_include_directories(competition-fastjson INTERFACE fastjson/src fastjson/include)
|
||||
|
||||
initialize_submodule(fastjson)
|
||||
add_library(competition-fastjson INTERFACE)
|
||||
target_include_directories(competition-fastjson INTERFACE fastjson/src fastjson/include)
|
||||
initialize_submodule(gason)
|
||||
add_library(competition-gason INTERFACE)
|
||||
target_include_directories(competition-gason INTERFACE gason/src)
|
||||
|
||||
initialize_submodule(gason)
|
||||
add_library(competition-gason INTERFACE)
|
||||
target_include_directories(competition-gason INTERFACE gason/src)
|
||||
initialize_submodule(jsmn)
|
||||
add_library(competition-jsmn INTERFACE)
|
||||
target_include_directories(competition-jsmn INTERFACE jsmn)
|
||||
|
||||
initialize_submodule(jsmn)
|
||||
add_library(competition-jsmn INTERFACE)
|
||||
target_include_directories(competition-jsmn INTERFACE jsmn)
|
||||
initialize_submodule(json)
|
||||
add_library(competition-json INTERFACE)
|
||||
target_include_directories(competition-json INTERFACE json/single_include)
|
||||
|
||||
initialize_submodule(json)
|
||||
add_library(competition-json INTERFACE)
|
||||
target_include_directories(competition-json INTERFACE json/single_include)
|
||||
initialize_submodule(json11)
|
||||
add_library(competition-json11 INTERFACE)
|
||||
target_include_directories(competition-json11 INTERFACE json11)
|
||||
|
||||
initialize_submodule(json11)
|
||||
add_library(competition-json11 INTERFACE)
|
||||
target_include_directories(competition-json11 INTERFACE json11)
|
||||
add_library(competition-jsoncppdist INTERFACE)
|
||||
target_include_directories(competition-jsoncppdist INTERFACE jsoncppdist)
|
||||
|
||||
add_library(competition-jsoncppdist INTERFACE)
|
||||
target_include_directories(competition-jsoncppdist INTERFACE jsoncppdist)
|
||||
initialize_submodule(rapidjson)
|
||||
add_library(competition-rapidjson INTERFACE)
|
||||
target_include_directories(competition-rapidjson INTERFACE rapidjson/include)
|
||||
|
||||
initialize_submodule(rapidjson)
|
||||
add_library(competition-rapidjson INTERFACE)
|
||||
target_include_directories(competition-rapidjson INTERFACE rapidjson/include)
|
||||
initialize_submodule(sajson)
|
||||
add_library(competition-sajson INTERFACE)
|
||||
target_include_directories(competition-sajson INTERFACE sajson/include)
|
||||
|
||||
initialize_submodule(sajson)
|
||||
add_library(competition-sajson INTERFACE)
|
||||
target_include_directories(competition-sajson INTERFACE sajson/include)
|
||||
initialize_submodule(ujson4c)
|
||||
add_library(competition-ujson4c ujson4c/src/ujdecode.c)
|
||||
target_include_directories(competition-ujson4c PUBLIC ujson4c/3rdparty ujson4c/src)
|
||||
|
||||
initialize_submodule(ujson4c)
|
||||
add_library(competition-ujson4c ujson4c/src/ujdecode.c)
|
||||
target_include_directories(competition-ujson4c PUBLIC ujson4c/3rdparty ujson4c/src)
|
||||
add_library(competition-core INTERFACE)
|
||||
target_link_libraries(competition-core INTERFACE competition-json competition-rapidjson competition-sajson competition-cJSON competition-jsmn)
|
||||
|
||||
add_library(competition-core INTERFACE)
|
||||
target_link_libraries(competition-core INTERFACE competition-json competition-rapidjson competition-sajson competition-cJSON competition-jsmn)
|
||||
add_library(competition-all INTERFACE)
|
||||
target_link_libraries(competition-all INTERFACE competition-core competition-jsoncppdist competition-json11 competition-fastjson competition-gason competition-ujson4c)
|
||||
endif()
|
||||
|
||||
add_library(competition-all INTERFACE)
|
||||
target_link_libraries(competition-all INTERFACE competition-core competition-jsoncppdist competition-json11 competition-fastjson competition-gason competition-ujson4c)
|
||||
endif()
|
||||
|
||||
initialize_submodule(cxxopts)
|
||||
add_library(cxxopts INTERFACE)
|
||||
target_include_directories(cxxopts INTERFACE cxxopts/include)
|
||||
initialize_submodule(cxxopts)
|
||||
message(STATUS "We acquired cxxopts and we are adding it as a library and target.")
|
||||
add_library(cxxopts INTERFACE)
|
||||
target_include_directories(cxxopts INTERFACE cxxopts/include)
|
||||
else()
|
||||
message(STATUS "Git is unavailable.")
|
||||
if(SIMDJSON_COMPETITION)
|
||||
message (STATUS "'SIMDJSON_COMPETITION' is requested, but we cannot download the remote repositories." )
|
||||
endif()
|
||||
if(SIMDJSON_GOOGLE_BENCHMARKS)
|
||||
message (STATUS "'SIMDJSON_GOOGLE_BENCHMARKS' is requested, but we cannot download the remote repositories." )
|
||||
endif()
|
||||
endif()
|
||||
+25
-12
@@ -8,6 +8,7 @@ An overview of what you need to know to use simdjson, with examples.
|
||||
* [Using simdjson as a CMake dependency](#using-simdjson-as-a-cmake-dependency)
|
||||
* [The Basics: Loading and Parsing JSON Documents](#the-basics-loading-and-parsing-json-documents)
|
||||
* [Using the Parsed JSON](#using-the-parsed-json)
|
||||
* [C++11 Support and string_view](#c++11-support-and-string_view)
|
||||
* [C++17 Support](#c++17-support)
|
||||
* [Minifying JSON strings without parsing](#minifying-json-strings-without-parsing)
|
||||
* [UTF-8 validation (alone)](#utf-8-validation-alone)
|
||||
@@ -24,7 +25,7 @@ Requirements
|
||||
------------------
|
||||
|
||||
- A recent compiler (LLVM clang6 or better, GNU GCC 7 or better) on a 64-bit (ARM or x64 Intel/AMD) POSIX systems such as macOS, freeBSD or Linux. We require that the compiler supports the C++11 standard or better.
|
||||
- Visual Studio 2017 or better under 64-bit Windows. Users should target a 64-bit build (x64) instead of a 32-bit build (x86). We support the LLVM clang compiler under Visual Studio (clangcl) as well as as the regular Visual Studio compiler.
|
||||
- Visual Studio 2017 or better under 64-bit Windows. Users should target a 64-bit build (x64) instead of a 32-bit build (x86). We support the LLVM clang compiler under Visual Studio (clangcl) as well as as the regular Visual Studio compiler. We also support MinGW 64-bit under Windows.
|
||||
|
||||
Including simdjson
|
||||
------------------
|
||||
@@ -90,7 +91,7 @@ The parsed document resulting from the `parser.load` and `parser.parse` calls de
|
||||
|
||||
During the`load` or `parse` calls, neither the input file nor the input string are ever modified. After calling `load` or `parse`, the source (either a file or a string) can be safely discarded. All of the JSON data is stored in the `parser` instance. The parsed document is also immutable in simdjson: you do not modify it by accessing it.
|
||||
|
||||
For best performance, a `parser` instance should be reused over several files: otherwise you will needlessly reallocate memory, an expensive process. It is also possible to avoid entirely memory allocations during parsing when using simdjson. [See our performance notes for details](https://github.com/simdjson/simdjson/blob/master/doc/performance.md).
|
||||
For best performance, a `parser` instance should be reused over several files: otherwise you will needlessly reallocate memory, an expensive process. It is also possible to avoid entirely memory allocations during parsing when using simdjson. [See our performance notes for details](performance.md).
|
||||
|
||||
|
||||
Using the Parsed JSON
|
||||
@@ -192,6 +193,27 @@ And another one:
|
||||
cout << "number: " << v << endl;
|
||||
```
|
||||
|
||||
|
||||
C++11 Support and string_view
|
||||
-------------
|
||||
|
||||
The simdjson library builds on compilers supporting the [C++11 standard](https://en.wikipedia.org/wiki/C%2B%2B11). It is also a strict requirement: we have no plan to support older C++ compilers.
|
||||
|
||||
We represent parsed strings in simdjson using the `std::string_view` class. It avoids
|
||||
the need to copy the data, as would be necessary with the `std::string` class. It also
|
||||
avoids the pitfalls of null-terminated C strings.
|
||||
|
||||
The `std::string_view` class has become standard as part of C++17 but it is not always available
|
||||
on compilers which only supports C++11. When we detect that `string_view` is natively
|
||||
available, we define the macro `SIMDJSON_HAS_STRING_VIEW`.
|
||||
|
||||
When we detect that it is unavailable,
|
||||
we use [string-view-lite](https://github.com/martinmoene/string-view-lite) as a
|
||||
substitute. In such cases, we use the type alias `using string_view = nonstd::string_view;` to
|
||||
offer the same API, irrespective of the compiler and standard library. The macro
|
||||
`SIMDJSON_HAS_STRING_VIEW` will be *undefined* to indicate that we emulate `string_view`.
|
||||
|
||||
|
||||
C++17 Support
|
||||
-------------
|
||||
|
||||
@@ -534,7 +556,7 @@ Thread Safety
|
||||
|
||||
We built simdjson with thread safety in mind.
|
||||
|
||||
The simdjson library is single-threaded except for [`parse_many`](https://github.com/simdjson/simdjson/blob/master/doc/parse_many.md) which may use secondary threads under its control when the library is compiled with thread support.
|
||||
The simdjson library is single-threaded except for [`parse_many`](parse_many.md) which may use secondary threads under its control when the library is compiled with thread support.
|
||||
|
||||
|
||||
We recommend using one `dom::parser` object per thread in which case the library is thread-safe.
|
||||
@@ -550,12 +572,3 @@ Backwards Compatibility
|
||||
The only header file supported by simdjson is `simdjson.h`. Older versions of simdjson published a
|
||||
number of other include files such as `document.h` or `ParsedJson.h` alongside `simdjson.h`; these headers
|
||||
may be moved or removed in future versions.
|
||||
|
||||
|
||||
|
||||
Further Reading
|
||||
-------------
|
||||
|
||||
* [Performance](doc/performance.md) shows some more advanced scenarios and how to tune for them.
|
||||
* [Implementation Selection](doc/implementation-selection.md) describes runtime CPU detection and
|
||||
how you can work with it.
|
||||
|
||||
@@ -0,0 +1,556 @@
|
||||
The Basics
|
||||
==========
|
||||
|
||||
An overview of what you need to know to use simdjson, with examples.
|
||||
|
||||
|
||||
Requirements
|
||||
------------------
|
||||
|
||||
- A recent compiler (LLVM clang6 or better, GNU GCC 7 or better) on a 64-bit (ARM or x64 Intel/AMD) POSIX systems such as macOS, freeBSD or Linux. We require that the compiler supports the C++11 standard or better.
|
||||
- Visual Studio 2017 or better under 64-bit Windows. Users should target a 64-bit build (x64) instead of a 32-bit build (x86). We support the LLVM clang compiler under Visual Studio (clangcl) as well as as the regular Visual Studio compiler.
|
||||
|
||||
Including simdjson
|
||||
------------------
|
||||
|
||||
To include simdjson, copy the simdjson.h and simdjson.cpp files from the singleheader directory
|
||||
into your project. Then include the header file in your project with:
|
||||
|
||||
```
|
||||
#include "simdjson.h"
|
||||
using namespace simdjson; // optional
|
||||
```
|
||||
|
||||
You can compile with:
|
||||
|
||||
```
|
||||
c++ myproject.cpp simdjson.cpp
|
||||
```
|
||||
|
||||
Note:
|
||||
- Users on macOS and other platforms were default compilers do not provide C++11 compliant by default should request it with the appropriate flag (e.g., `c++ myproject.cpp simdjson.cpp`).
|
||||
- Visual Studio users should compile with the `_CRT_SECURE_NO_WARNINGS` flag to avoid warnings with respect to our use of standard C functions such as `fopen`.
|
||||
|
||||
Using simdjson as a CMake dependency
|
||||
------------------
|
||||
|
||||
You can include the simdjson repository as a folder in your CMake project. In the parent
|
||||
`CMakeLists.txt`, include the following lines:
|
||||
|
||||
```
|
||||
set(SIMDJSON_JUST_LIBRARY ON CACHE STRING "Build just the library, nothing else." FORCE)
|
||||
add_subdirectory(simdjson EXCLUDE_FROM_ALL)
|
||||
```
|
||||
|
||||
Elsewhere in your project, you can declare dependencies on simdjson with lines such as these:
|
||||
|
||||
```
|
||||
add_executable(myprogram myprogram.cpp)
|
||||
target_link_libraries(myprogram simdjson)
|
||||
```
|
||||
|
||||
See [our CMake demonstration](https://github.com/simdjson/cmakedemo).
|
||||
|
||||
The Basics: Loading and Parsing JSON Documents
|
||||
----------------------------------------------
|
||||
|
||||
The simdjson library offers a simple DOM tree API, which you can access by creating a
|
||||
`dom::parser` and calling the `load()` method:
|
||||
|
||||
```
|
||||
dom::parser parser;
|
||||
dom::element doc = parser.load(filename); // load and parse a file
|
||||
```
|
||||
|
||||
Or by creating a padded string (for efficiency reasons, simdjson requires a string with
|
||||
SIMDJSON_PADDING bytes at the end) and calling `parse()`:
|
||||
|
||||
```
|
||||
dom::parser parser;
|
||||
dom::element doc = parser.parse("[1,2,3]"_padded); // parse a string
|
||||
```
|
||||
|
||||
The parsed document resulting from the `parser.load` and `parser.parse` calls depends on the `parser` instance. Thus the `parser` instance must remain in scope. Furthermore, you must have at most one parsed document in play per `parser` instance.
|
||||
|
||||
During the`load` or `parse` calls, neither the input file nor the input string are ever modified. After calling `load` or `parse`, the source (either a file or a string) can be safely discarded. All of the JSON data is stored in the `parser` instance. The parsed document is also immutable in simdjson: you do not modify it by accessing it.
|
||||
|
||||
For best performance, a `parser` instance should be reused over several files: otherwise you will needlessly reallocate memory, an expensive process. It is also possible to avoid entirely memory allocations during parsing when using simdjson.
|
||||
|
||||
|
||||
Using the Parsed JSON
|
||||
---------------------
|
||||
|
||||
Once you have an element, you can navigate it with idiomatic C++ iterators, operators and casts.
|
||||
|
||||
* **Extracting Values (with exceptions):** You can cast a JSON element to a native type: `double(element)` or
|
||||
`double x = json_element`. This works for double, uint64_t, int64_t, bool,
|
||||
dom::object and dom::array. An exception is thrown if the cast is not possible.
|
||||
* **Extracting Values (without expceptions):** You can use a variant usage of `get()` with error codes to avoid exceptions. You first declare the variable of the appropriate type (`double`, `uint64_t`, `int64_t`, `bool`,
|
||||
`dom::object` and `dom::array`) and pass it by reference to `get()` which gives you back an error code: e.g.,
|
||||
```
|
||||
simdjson::error_code error;
|
||||
simdjson::padded_string numberstring = "1.2"_padded; // our JSON input ("1.2")
|
||||
simdjson::dom::parser parser;
|
||||
double value; // variable where we store the value to be parsed
|
||||
error = parser.parse(numberstring).get(value);
|
||||
if (error) { std::cerr << error << std::endl; return EXIT_FAILURE; }
|
||||
std::cout << "I parsed " << value << " from " << numberstring.data() << std::endl;
|
||||
```
|
||||
* **Field Access:** To get the value of the "foo" field in an object, use `object["foo"]`.
|
||||
* **Array Iteration:** To iterate through an array, use `for (auto value : array) { ... }`. If you
|
||||
know the type of the value, you can cast it right there, too! `for (double value : array) { ... }`
|
||||
* **Object Iteration:** You can iterate through an object's fields, too: `for (auto [key, value] : object)`
|
||||
* **Array Index:** To get at an array value by index, use the at() method: `array.at(0)` gets the
|
||||
first element.
|
||||
> Note that array[0] does not compile, because implementing [] gives the impression indexing is a
|
||||
> O(1) operation, which it is not presently in simdjson. Instead, you should iterate over the elements
|
||||
> using a for-loop, as in our examples.
|
||||
* **Array and Object size** Given an array or an object, you can get its size (number of elements or keys)
|
||||
with the `size()` method.
|
||||
* **Checking an Element Type:** You can check an element's type with `element.type()`. It
|
||||
returns an `element_type`.
|
||||
|
||||
|
||||
Here are some examples of all of the above:
|
||||
|
||||
```
|
||||
auto cars_json = R"( [
|
||||
{ "make": "Toyota", "model": "Camry", "year": 2018, "tire_pressure": [ 40.1, 39.9, 37.7, 40.4 ] },
|
||||
{ "make": "Kia", "model": "Soul", "year": 2012, "tire_pressure": [ 30.1, 31.0, 28.6, 28.7 ] },
|
||||
{ "make": "Toyota", "model": "Tercel", "year": 1999, "tire_pressure": [ 29.8, 30.0, 30.2, 30.5 ] }
|
||||
] )"_padded;
|
||||
dom::parser parser;
|
||||
|
||||
// Iterating through an array of objects
|
||||
for (dom::object car : parser.parse(cars_json)) {
|
||||
// Accessing a field by name
|
||||
cout << "Make/Model: " << car["make"] << "/" << car["model"] << endl;
|
||||
|
||||
// Casting a JSON element to an integer
|
||||
uint64_t year = car["year"];
|
||||
cout << "- This car is " << 2020 - year << "years old." << endl;
|
||||
|
||||
// Iterating through an array of floats
|
||||
double total_tire_pressure = 0;
|
||||
for (double tire_pressure : car["tire_pressure"]) {
|
||||
total_tire_pressure += tire_pressure;
|
||||
}
|
||||
cout << "- Average tire pressure: " << (total_tire_pressure / 4) << endl;
|
||||
|
||||
// Writing out all the information about the car
|
||||
for (auto field : car) {
|
||||
cout << "- " << field.key << ": " << field.value << endl;
|
||||
}
|
||||
}
|
||||
```
|
||||
|
||||
Here is a different example illustrating the same ideas:
|
||||
|
||||
```
|
||||
auto abstract_json = R"( [
|
||||
{ "12345" : {"a":12.34, "b":56.78, "c": 9998877} },
|
||||
{ "12545" : {"a":11.44, "b":12.78, "c": 11111111} }
|
||||
] )"_padded;
|
||||
dom::parser parser;
|
||||
|
||||
// Parse and iterate through an array of objects
|
||||
for (dom::object obj : parser.parse(abstract_json)) {
|
||||
for(const auto& key_value : obj) {
|
||||
cout << "key: " << key_value.key << " : ";
|
||||
dom::object innerobj = key_value.value;
|
||||
cout << "a: " << double(innerobj["a"]) << ", ";
|
||||
cout << "b: " << double(innerobj["b"]) << ", ";
|
||||
cout << "c: " << int64_t(innerobj["c"]) << endl;
|
||||
}
|
||||
}
|
||||
```
|
||||
|
||||
And another one:
|
||||
|
||||
|
||||
```
|
||||
auto abstract_json = R"(
|
||||
{ "str" : { "123" : {"abc" : 3.14 } } } )"_padded;
|
||||
dom::parser parser;
|
||||
double v = parser.parse(abstract_json)["str"]["123"]["abc"];
|
||||
cout << "number: " << v << endl;
|
||||
```
|
||||
|
||||
|
||||
C++11 Support and string_view
|
||||
-------------
|
||||
|
||||
The simdjson library builds on compilers supporting the [C++11 standard](https://en.wikipedia.org/wiki/C%2B%2B11). It is also a strict requirement: we have no plan to support older C++ compilers.
|
||||
|
||||
We represent parsed strings in simdjson using the `std::string_view` class. It avoids
|
||||
the need to copy the data, as would be necessary with the `std::string` class. It also
|
||||
avoids the pitfalls of null-terminated C strings.
|
||||
|
||||
The `std::string_view` class has become standard as part of C++17 but it is not always available
|
||||
on compilers which only supports C++11. When we detect that `string_view` is natively
|
||||
available, we define the macro `SIMDJSON_HAS_STRING_VIEW`.
|
||||
|
||||
When we detect that it is unavailable,
|
||||
we use [string-view-lite](https://github.com/martinmoene/string-view-lite) as a
|
||||
substitute. In such cases, we use the type alias `using string_view = nonstd::string_view;` to
|
||||
offer the same API, irrespective of the compiler and standard library. The macro
|
||||
`SIMDJSON_HAS_STRING_VIEW` will be *undefined* to indicate that we emulate `string_view`.
|
||||
|
||||
|
||||
C++17 Support
|
||||
-------------
|
||||
|
||||
While the simdjson library can be used in any project using C++ 11 and above, field iteration has special support C++ 17's destructuring syntax. For example:
|
||||
|
||||
```
|
||||
padded_string json = R"( { "foo": 1, "bar": 2 } )"_padded;
|
||||
dom::parser parser;
|
||||
dom::object object;
|
||||
auto error = parser.parse(json).get(object);
|
||||
if (error) { cerr << error << endl; return; }
|
||||
for (auto [key, value] : object) {
|
||||
cout << key << " = " << value << endl;
|
||||
}
|
||||
```
|
||||
|
||||
For comparison, here is the C++ 11 version of the same code:
|
||||
|
||||
```
|
||||
// C++ 11 version for comparison
|
||||
padded_string json = R"( { "foo": 1, "bar": 2 } )"_padded;
|
||||
dom::parser parser;
|
||||
dom::object object;
|
||||
auto error = parser.parse(json).get(object);
|
||||
if (!error) { cerr << error << endl; return; }
|
||||
for (dom::key_value_pair field : object) {
|
||||
cout << field.key << " = " << field.value << endl;
|
||||
}
|
||||
```
|
||||
|
||||
Minifying JSON strings without parsing
|
||||
----------------------
|
||||
|
||||
In some cases, you may have valid JSON strings that you do not wish to parse but that you wish to minify. That is, you wish to remove all unnecessary spaces. We have a fast function for this purpose (`minify`). This function does not validate your content, and it does not parse it. Instead, it assumes that your string is valid UTF-8. It is much faster than parsing the string and re-serializing it in minified form. Usage is relatively simple. You must pass an input pointer with a length parameter, as well as an output pointer and an output length parameter (by reference). The output length parameter is not read, but written to. The output pointer should point to a valid memory region that is slightly overallocated (by `simdjson::SIMDJSON_PADDING`) compared to the original string length. The input pointer and input length are read, but not written to.
|
||||
|
||||
```
|
||||
// Starts with a valid JSON document as a string.
|
||||
// It does not have to be null-terminated.
|
||||
const char * some_string = "[ 1, 2, 3, 4] ";
|
||||
size_t length = strlen(some_string);
|
||||
// Create a buffer to receive the minified string. Make sure that there is enough room,
|
||||
// including some padding (simdjson::SIMDJSON_PADDING).
|
||||
std::unique_ptr<char[]> buffer{new(std::nothrow) char[length + simdjson::SIMDJSON_PADDING]};
|
||||
size_t new_length{}; // It will receive the minified length.
|
||||
auto error = simdjson::minify(some_string, length, buffer.get(), new_length);
|
||||
// The buffer variable now has "[1,2,3,4]" and new_length has value 9.
|
||||
```
|
||||
|
||||
Though it does not validate the JSON input, it will detect when the document ends with an unterminated string. E.g., it would refuse to minify the string `"this string is not terminated` because of the missing final quote.
|
||||
|
||||
|
||||
UTF-8 validation (alone)
|
||||
----------------------
|
||||
|
||||
The simdjson library has fast functions to validate UTF-8 strings. They are many times faster than most functions commonly found in libraries. You can use our fast functions, even if you do not care about JSON.
|
||||
|
||||
```
|
||||
const char * some_string = "[ 1, 2, 3, 4] ";
|
||||
size_t length = strlen(some_string);
|
||||
bool is_ok = simdjson::validate_utf8(some_string, length);
|
||||
```
|
||||
|
||||
The UTF-8 validation function merely checks that the input is valid UTF-8: it works with strings in general, not just JSON strings.
|
||||
|
||||
Your input string does not need any padding. Any string will do. The `validate_utf8` function does not do any memory allocation on the heap, and it does not throw exceptions.
|
||||
|
||||
JSON Pointer
|
||||
------------
|
||||
|
||||
The simdjson library also supports [JSON pointer](https://tools.ietf.org/html/rfc6901) through the
|
||||
at() method, letting you reach further down into the document in a single call:
|
||||
|
||||
```
|
||||
auto cars_json = R"( [
|
||||
{ "make": "Toyota", "model": "Camry", "year": 2018, "tire_pressure": [ 40.1, 39.9, 37.7, 40.4 ] },
|
||||
{ "make": "Kia", "model": "Soul", "year": 2012, "tire_pressure": [ 30.1, 31.0, 28.6, 28.7 ] },
|
||||
{ "make": "Toyota", "model": "Tercel", "year": 1999, "tire_pressure": [ 29.8, 30.0, 30.2, 30.5 ] }
|
||||
] )"_padded;
|
||||
dom::parser parser;
|
||||
dom::element cars = parser.parse(cars_json);
|
||||
cout << cars.at("0/tire_pressure/1") << endl; // Prints 39.9
|
||||
```
|
||||
|
||||
Error Handling
|
||||
--------------
|
||||
|
||||
All simdjson APIs that can fail return `simdjson_result<T>`, which is a <value, error_code>
|
||||
pair. You can retrieve the value with .get(), like so:
|
||||
|
||||
```
|
||||
dom::element doc;
|
||||
auto error = parser.parse(json).get(doc);
|
||||
if (error) { cerr << error << endl; exit(1); }
|
||||
```
|
||||
|
||||
When you use the code this way, it is your responsibility to check for error before using the
|
||||
result: if there is an error, the result value will not be valid and using it will caused undefined
|
||||
behavior.
|
||||
|
||||
We can write a "quick start" example where we attempt to parse a file and access some data, without triggering exceptions:
|
||||
|
||||
```
|
||||
#include "simdjson.h"
|
||||
|
||||
int main(void) {
|
||||
simdjson::dom::parser parser;
|
||||
|
||||
simdjson::dom::element tweets;
|
||||
auto error = parser.load("twitter.json").get(tweets);
|
||||
if (error) { std::cerr << error << std::endl; return EXIT_FAILURE; }
|
||||
|
||||
simdjson::dom::element res;
|
||||
if ((error = tweets["search_metadata"]["count"].get(res))) {
|
||||
std::cerr << "could not access keys" << std::endl;
|
||||
return EXIT_FAILURE;
|
||||
}
|
||||
std::cout << res << " results." << std::endl;
|
||||
}
|
||||
```
|
||||
|
||||
### Error Handling Example
|
||||
|
||||
This is how the example in "Using the Parsed JSON" could be written using only error code checking:
|
||||
|
||||
```
|
||||
auto cars_json = R"( [
|
||||
{ "make": "Toyota", "model": "Camry", "year": 2018, "tire_pressure": [ 40.1, 39.9, 37.7, 40.4 ] },
|
||||
{ "make": "Kia", "model": "Soul", "year": 2012, "tire_pressure": [ 30.1, 31.0, 28.6, 28.7 ] },
|
||||
{ "make": "Toyota", "model": "Tercel", "year": 1999, "tire_pressure": [ 29.8, 30.0, 30.2, 30.5 ] }
|
||||
] )"_padded;
|
||||
dom::parser parser;
|
||||
dom::array cars;
|
||||
auto error = parser.parse(cars_json).get(cars);
|
||||
if (error) { cerr << error << endl; exit(1); }
|
||||
|
||||
// Iterating through an array of objects
|
||||
for (dom::element car_element : cars) {
|
||||
dom::object car;
|
||||
if ((error = car_element.get(car))) { cerr << error << endl; exit(1); }
|
||||
|
||||
// Accessing a field by name
|
||||
std::string_view make, model;
|
||||
if ((error = car["make"].get(make))) { cerr << error << endl; exit(1); }
|
||||
if ((error = car["model"].get(model))) { cerr << error << endl; exit(1); }
|
||||
cout << "Make/Model: " << make << "/" << model << endl;
|
||||
|
||||
// Casting a JSON element to an integer
|
||||
uint64_t year;
|
||||
if ((error = car["year"].get(year))) { cerr << error << endl; exit(1); }
|
||||
cout << "- This car is " << 2020 - year << "years old." << endl;
|
||||
|
||||
// Iterating through an array of floats
|
||||
double total_tire_pressure = 0;
|
||||
dom::array tire_pressure_array;
|
||||
if ((error = car["tire_pressure"].get(tire_pressure_array))) { cerr << error << endl; exit(1); }
|
||||
for (dom::element tire_pressure_element : tire_pressure_array) {
|
||||
double tire_pressure;
|
||||
if ((error = tire_pressure_element.get(tire_pressure))) { cerr << error << endl; exit(1); }
|
||||
total_tire_pressure += tire_pressure;
|
||||
}
|
||||
cout << "- Average tire pressure: " << (total_tire_pressure / 4) << endl;
|
||||
|
||||
// Writing out all the information about the car
|
||||
for (auto field : car) {
|
||||
cout << "- " << field.key << ": " << field.value << endl;
|
||||
}
|
||||
}
|
||||
```
|
||||
|
||||
Here is another example:
|
||||
|
||||
```
|
||||
auto abstract_json = R"( [
|
||||
{ "12345" : {"a":12.34, "b":56.78, "c": 9998877} },
|
||||
{ "12545" : {"a":11.44, "b":12.78, "c": 11111111} }
|
||||
] )"_padded;
|
||||
dom::parser parser;
|
||||
dom::array array;
|
||||
auto error = parser.parse(abstract_json).get(array);
|
||||
if (error) { cerr << error << endl; exit(1); }
|
||||
// Iterate through an array of objects
|
||||
for (dom::element elem : array) {
|
||||
dom::object obj;
|
||||
if ((error = elem.get(obj))) { cerr << error << endl; exit(1); }
|
||||
for (auto & key_value : obj) {
|
||||
cout << "key: " << key_value.key << " : ";
|
||||
dom::object innerobj;
|
||||
if ((error = key_value.value.get(innerobj))) { cerr << error << endl; exit(1); }
|
||||
|
||||
double va, vb;
|
||||
if ((error = innerobj["a"].get(va))) { cerr << error << endl; exit(1); }
|
||||
cout << "a: " << va << ", ";
|
||||
if ((error = innerobj["b"].get(vc))) { cerr << error << endl; exit(1); }
|
||||
cout << "b: " << vb << ", ";
|
||||
|
||||
int64_t vc;
|
||||
if ((error = innerobj["c"].get(vc))) { cerr << error << endl; exit(1); }
|
||||
cout << "c: " << vc << endl;
|
||||
}
|
||||
}
|
||||
```
|
||||
|
||||
And another one:
|
||||
|
||||
```
|
||||
auto abstract_json = R"(
|
||||
{ "str" : { "123" : {"abc" : 3.14 } } } )"_padded;
|
||||
dom::parser parser;
|
||||
double v;
|
||||
auto error = parser.parse(abstract_json)["str"]["123"]["abc"].get(v);
|
||||
if (error) { cerr << error << endl; exit(1); }
|
||||
cout << "number: " << v << endl;
|
||||
```
|
||||
|
||||
Notice how we can string several operations (`parser.parse(abstract_json)["str"]["123"]["abc"].get(v)`) and only check for the error once, a strategy we call *error chaining*.
|
||||
|
||||
The next two functions will take as input a JSON document containing an array with a single element, either a string or a number. They return true upon success.
|
||||
|
||||
```
|
||||
simdjson::dom::parser parser{};
|
||||
|
||||
bool parse_double(const char *j, double &d) {
|
||||
auto error = parser.parse(j, std::strlen(j))
|
||||
.at(0)
|
||||
.get(d, error);
|
||||
if (error) { return false; }
|
||||
return true;
|
||||
}
|
||||
|
||||
bool parse_string(const char *j, std::string &s) {
|
||||
std::string_view answer;
|
||||
auto error = parser.parse(j,strlen(j))
|
||||
.at(0)
|
||||
.get(answer, error);
|
||||
if (error) { return false; }
|
||||
s.assign(answer.data(), answer.size());
|
||||
return true;
|
||||
}
|
||||
```
|
||||
|
||||
### Exceptions
|
||||
|
||||
Users more comfortable with an exception flow may choose to directly cast the `simdjson_result<T>` to the desired type:
|
||||
|
||||
```
|
||||
dom::element doc = parser.parse(json); // Throws an exception if there was an error!
|
||||
```
|
||||
|
||||
When used this way, a `simdjson_error` exception will be thrown if an error occurs, preventing the
|
||||
program from continuing if there was an error.
|
||||
|
||||
Tree Walking and JSON Element Types
|
||||
-----------------------------------
|
||||
|
||||
Sometimes you don't necessarily have a document with a known type, and are trying to generically
|
||||
inspect or walk over JSON elements. To do that, you can use iterators and the type() method. For
|
||||
example, here's a quick and dirty recursive function that verbosely prints the JSON document as JSON
|
||||
(* ignoring nuances like trailing commas and escaping strings, for brevity's sake):
|
||||
|
||||
```
|
||||
void print_json(dom::element element) {
|
||||
switch (element.type()) {
|
||||
case dom::element_type::ARRAY:
|
||||
cout << "[";
|
||||
for (dom::element child : dom::array(element)) {
|
||||
print_json(child);
|
||||
cout << ",";
|
||||
}
|
||||
cout << "]";
|
||||
break;
|
||||
case dom::element_type::OBJECT:
|
||||
cout << "{";
|
||||
for (dom::key_value_pair field : dom::object(element)) {
|
||||
cout << "\"" << field.key << "\": ";
|
||||
print_json(field.value);
|
||||
}
|
||||
cout << "}";
|
||||
break;
|
||||
case dom::element_type::INT64:
|
||||
cout << int64_t(element) << endl;
|
||||
break;
|
||||
case dom::element_type::UINT64:
|
||||
cout << uint64_t(element) << endl;
|
||||
break;
|
||||
case dom::element_type::DOUBLE:
|
||||
cout << double(element) << endl;
|
||||
break;
|
||||
case dom::element_type::STRING:
|
||||
cout << std::string_view(element) << endl;
|
||||
break;
|
||||
case dom::element_type::BOOL:
|
||||
cout << bool(element) << endl;
|
||||
break;
|
||||
case dom::element_type::NULL_VALUE:
|
||||
cout << "null" << endl;
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
void basics_treewalk_1() {
|
||||
dom::parser parser;
|
||||
print_json(parser.load("twitter.json"));
|
||||
}
|
||||
```
|
||||
|
||||
Newline-Delimited JSON (ndjson) and JSON lines
|
||||
----------------------------------------------
|
||||
|
||||
The simdjson library also support multithreaded JSON streaming through a large file containing many
|
||||
smaller JSON documents in either [ndjson](http://ndjson.org) or [JSON lines](http://jsonlines.org)
|
||||
format. If your JSON documents all contain arrays or objects, we even support direct file
|
||||
concatenation without whitespace. The concatenated file has no size restrictions (including larger
|
||||
than 4GB), though each individual document must be no larger than 4 GB.
|
||||
|
||||
Here is a simple example, given "x.json" with this content:
|
||||
|
||||
```json
|
||||
{ "foo": 1 }
|
||||
{ "foo": 2 }
|
||||
{ "foo": 3 }
|
||||
```
|
||||
|
||||
```
|
||||
dom::parser parser;
|
||||
dom::document_stream docs = parser.load_many(filename);
|
||||
for (dom::element doc : docs) {
|
||||
cout << doc["foo"] << endl;
|
||||
}
|
||||
// Prints 1 2 3
|
||||
```
|
||||
|
||||
In-memory ndjson strings can be parsed as well, with `parser.parse_many(string)`.
|
||||
|
||||
Both `load_many` and `parse_many` take an optional parameter `size_t batch_size` which defines the window processing size. It is set by default to a large value (`1000000` corresponding to 1 MB). None of your JSON documents should exceed this window size, or else you will get the error `simdjson::CAPACITY`. You cannot set this window size larger than 4 GB: you will get the error `simdjson::CAPACITY`. The smaller the window size is, the less memory the function will use. Setting the window size too small (e.g., less than 100 kB) may also impact performance negatively. Leaving it to 1 MB is expected to be a good choice, unless you have some larger documents.
|
||||
|
||||
|
||||
Thread Safety
|
||||
-------------
|
||||
|
||||
We built simdjson with thread safety in mind.
|
||||
|
||||
The simdjson library is single-threaded except for `parse_many` which may use secondary threads under its control when the library is compiled with thread support.
|
||||
|
||||
|
||||
We recommend using one `dom::parser` object per thread in which case the library is thread-safe.
|
||||
It is unsafe to reuse a `dom::parser` object between different threads.
|
||||
The parsed results (`dom::document`, `dom::element`, `array`, `object`) depend on the `dom::parser`, etc. therefore it is also potentially unsafe to use the result of the parsing between different threads.
|
||||
|
||||
The CPU detection, which runs the first time parsing is attempted and switches to the fastest
|
||||
parser for your CPU, is transparent and thread-safe.
|
||||
|
||||
Backwards Compatibility
|
||||
-----------------------
|
||||
|
||||
The only header file supported by simdjson is `simdjson.h`. Older versions of simdjson published a
|
||||
number of other include files such as `document.h` or `ParsedJson.h` alongside `simdjson.h`; these headers
|
||||
may be moved or removed in future versions.
|
||||
@@ -47,7 +47,7 @@ Inspecting the Detected Implementation
|
||||
You can check what implementation is running with `active_implementation`:
|
||||
|
||||
```c++
|
||||
cout << "simdjson v" << #SIMDJSON_VERSION << endl;
|
||||
cout << "simdjson v" << STRINGIFY(SIMDJSON_VERSION) << endl;
|
||||
cout << "Detected the best implementation for your machine: " << simdjson::active_implementation->name();
|
||||
cout << "(" << simdjson::active_implementation->description() << ")" << endl;
|
||||
```
|
||||
@@ -81,11 +81,3 @@ can select the CPU architecture yourself:
|
||||
// Use the fallback implementation, even though my machine is fast enough for anything
|
||||
simdjson::active_implementation = simdjson::available_implementations["fallback"];
|
||||
```
|
||||
|
||||
|
||||
Further Reading
|
||||
-------------
|
||||
|
||||
* [Performance](doc/performance.md) shows some more advanced scenarios and how to tune for them.
|
||||
* [Implementation Selection](doc/implementation-selection.md) describes runtime CPU detection and
|
||||
how you can work with it.
|
||||
|
||||
+10
-18
@@ -1,7 +1,7 @@
|
||||
parse_many
|
||||
==========
|
||||
|
||||
An interface providing features to work with files or streams containing multiple JSON documents.
|
||||
An interface providing features to work with files or streams containing multiple JSON documents.
|
||||
As fast and convenient as possible.
|
||||
|
||||
Contents
|
||||
@@ -26,7 +26,7 @@ values as an array, or a possibly indeterminate-length or never-
|
||||
ending sequence of values, JSON becomes difficult to work with.
|
||||
|
||||
Consider a sequence of one million values, each possibly one kilobyte
|
||||
when encoded -- roughly one gigabyte. It is often desirable to process such a dataset incrementally
|
||||
when encoded -- roughly one gigabyte. It is often desirable to process such a dataset incrementally
|
||||
without having to first read all of it before beginning to produce results.
|
||||
|
||||
Performance
|
||||
@@ -109,7 +109,7 @@ format, we support any file that contains any amount of valid JSON document, **s
|
||||
or more character that is considered whitespace** by the JSON spec. Anything that is
|
||||
not whitespace will be parsed as a JSON document and could lead to failure.
|
||||
|
||||
Whitespace Characters:
|
||||
Whitespace Characters:
|
||||
- **Space**
|
||||
- **Linefeed**
|
||||
- **Carriage return**
|
||||
@@ -137,16 +137,16 @@ From [jsonlines.org](http://jsonlines.org/examples/):
|
||||
["Gilbert", "2013", 24, true]
|
||||
["Alexa", "2013", 29, true]
|
||||
["May", "2012B", 14, false]
|
||||
["Deloise", "2012A", 19, true]
|
||||
["Deloise", "2012A", 19, true]
|
||||
```
|
||||
CSV seems so easy that many programmers have written code to generate it themselves, and almost every implementation is
|
||||
different. Handling broken CSV files is a common and frustrating task. CSV has no standard encoding, no standard column
|
||||
CSV seems so easy that many programmers have written code to generate it themselves, and almost every implementation is
|
||||
different. Handling broken CSV files is a common and frustrating task. CSV has no standard encoding, no standard column
|
||||
separator and multiple character escaping standards. String is the only type supported for cell values, so some programs
|
||||
attempt to guess the correct types.
|
||||
|
||||
|
||||
JSON Lines handles tabular data cleanly and without ambiguity. Cells may use the standard JSON types.
|
||||
|
||||
The biggest missing piece is an import/export filter for popular spreadsheet programs so that non-programmers can use
|
||||
|
||||
The biggest missing piece is an import/export filter for popular spreadsheet programs so that non-programmers can use
|
||||
this format.
|
||||
|
||||
- **Easy Nested Data**
|
||||
@@ -156,13 +156,5 @@ From [jsonlines.org](http://jsonlines.org/examples/):
|
||||
{"name": "May", "wins": []}
|
||||
{"name": "Deloise", "wins": [["three of a kind", "5♣"]]}
|
||||
```
|
||||
JSON Lines' biggest strength is in handling lots of similar nested data structures. One .jsonl file is easier to
|
||||
JSON Lines' biggest strength is in handling lots of similar nested data structures. One .jsonl file is easier to
|
||||
work with than a directory full of XML files.
|
||||
|
||||
|
||||
Further Reading
|
||||
-------------
|
||||
|
||||
* [Performance](doc/performance.md) shows some more advanced scenarios and how to tune for them.
|
||||
* [Implementation Selection](doc/implementation-selection.md) describes runtime CPU detection and
|
||||
how you can work with it.
|
||||
|
||||
@@ -170,10 +170,3 @@ On some Intel processors, using SIMD instructions in a sustained manner on the s
|
||||
- Whenever heavy 256-bit or wider instructions are used. Heavy instructions are those involving floating point operations or integer multiplications (since these execute on the floating point unit).
|
||||
|
||||
The simdjson library does not currently support AVX-512 instructions and it does not make use of heavy 256-bit instructions. Thus there should be no downclocking due to simdjson on recent processors. You may still be worried about which SIMD instruction set is used by simdjson. Thankfully, [you can always determine and change which architecture-specific implementation is used](implementation-selection.md). Thus even if your CPU supports AVX2, you do not need to use AVX2. You are in control.
|
||||
|
||||
|
||||
Further Reading
|
||||
-------------
|
||||
|
||||
* [Implementation Selection](doc/implementation-selection.md) describes runtime CPU detection and
|
||||
how you can work with it.
|
||||
@@ -81,12 +81,15 @@ constexpr size_t DEFAULT_MAX_DEPTH = 1024;
|
||||
#define SIMDJSON_PUSH_DISABLE_ALL_WARNINGS __pragma(warning( push, 0 ))
|
||||
#define SIMDJSON_DISABLE_VS_WARNING(WARNING_NUMBER) __pragma(warning( disable : WARNING_NUMBER ))
|
||||
// Get rid of Intellisense-only warnings (Code Analysis)
|
||||
// Though __has_include is C++17, it looks like it is supported in Visual Studio 2017 or better.
|
||||
// We are probably not supporting earlier version of Visual Studio in any case.
|
||||
// Though __has_include is C++17, it is supported in Visual Studio 2017 or better (_MSC_VER>=1910).
|
||||
#if defined(_MSC_VER) && (_MSC_VER>=1910)
|
||||
#if __has_include(<CppCoreCheck\Warnings.h>)
|
||||
#include <CppCoreCheck\Warnings.h>
|
||||
#define SIMDJSON_DISABLE_UNDESIRED_WARNINGS SIMDJSON_DISABLE_VS_WARNING(ALL_CPPCORECHECK_WARNINGS)
|
||||
#else
|
||||
#endif
|
||||
#endif
|
||||
|
||||
#ifndef SIMDJSON_DISABLE_UNDESIRED_WARNINGS
|
||||
#define SIMDJSON_DISABLE_UNDESIRED_WARNINGS
|
||||
#endif
|
||||
|
||||
|
||||
@@ -62,21 +62,42 @@ public:
|
||||
*/
|
||||
inline simdjson_result<object> get_object() const noexcept;
|
||||
/**
|
||||
* Cast this element to a string.
|
||||
* Cast this element to a null-terminated C string.
|
||||
*
|
||||
* The string is guaranteed to be valid UTF-8.
|
||||
*
|
||||
* Equivalent to get<const char *>().
|
||||
* The get_c_str() function is equivalent to get<const char *>().
|
||||
*
|
||||
* The length of the string is given by get_string_length(). Because JSON strings
|
||||
* may contain null characters, it may be incorrect to use strlen to determine the
|
||||
* string length.
|
||||
*
|
||||
* @returns An pointer to a null-terminated string. This string is stored in the parser and will
|
||||
* It is possible to get a single string_view instance which represents both the string
|
||||
* content and its length: see get_string().
|
||||
*
|
||||
* @returns A pointer to a null-terminated UTF-8 string. This string is stored in the parser and will
|
||||
* be invalidated the next time it parses a document or when it is destroyed.
|
||||
* Returns INCORRECT_TYPE if the JSON element is not a string.
|
||||
*/
|
||||
inline simdjson_result<const char *> get_c_str() const noexcept;
|
||||
/**
|
||||
* Cast this element to a string.
|
||||
* Gives the length in bytes of the string.
|
||||
*
|
||||
* It is possible to get a single string_view instance which represents both the string
|
||||
* content and its length: see get_string().
|
||||
*
|
||||
* @returns A string length in bytes.
|
||||
* Returns INCORRECT_TYPE if the JSON element is not a string.
|
||||
*/
|
||||
inline simdjson_result<size_t> get_string_length() const noexcept;
|
||||
/**
|
||||
* Cast this element to a string.
|
||||
*
|
||||
* The string is guaranteed to be valid UTF-8.
|
||||
*
|
||||
* Equivalent to get<std::string_view>().
|
||||
*
|
||||
* @returns A string. The string is stored in the parser and will be invalidated the next time it
|
||||
* @returns An UTF-8 string. The string is stored in the parser and will be invalidated the next time it
|
||||
* parses a document or when it is destroyed.
|
||||
* Returns INCORRECT_TYPE if the JSON element is not a string.
|
||||
*/
|
||||
@@ -253,7 +274,9 @@ public:
|
||||
inline operator bool() const noexcept(false);
|
||||
|
||||
/**
|
||||
* Read this element as a null-terminated string.
|
||||
* Read this element as a null-terminated UTF-8 string.
|
||||
*
|
||||
* Be mindful that JSON allows strings to contain null characters.
|
||||
*
|
||||
* Does *not* convert other types to a string; requires that the JSON type of the element was
|
||||
* an actual string.
|
||||
@@ -264,7 +287,7 @@ public:
|
||||
inline explicit operator const char*() const noexcept(false);
|
||||
|
||||
/**
|
||||
* Read this element as a null-terminated string.
|
||||
* Read this element as a null-terminated UTF-8 string.
|
||||
*
|
||||
* Does *not* convert other types to a string; requires that the JSON type of the element was
|
||||
* an actual string.
|
||||
@@ -464,6 +487,7 @@ public:
|
||||
really_inline simdjson_result<dom::array> get_array() const noexcept;
|
||||
really_inline simdjson_result<dom::object> get_object() const noexcept;
|
||||
really_inline simdjson_result<const char *> get_c_str() const noexcept;
|
||||
really_inline simdjson_result<size_t> get_string_length() const noexcept;
|
||||
really_inline simdjson_result<std::string_view> get_string() const noexcept;
|
||||
really_inline simdjson_result<int64_t> get_int64() const noexcept;
|
||||
really_inline simdjson_result<uint64_t> get_uint64() const noexcept;
|
||||
|
||||
@@ -391,7 +391,12 @@ private:
|
||||
/**
|
||||
* The loaded buffer (reused each time load() is called)
|
||||
*/
|
||||
#if defined(_MSC_VER) && _MSC_VER < 1910
|
||||
// older versions of Visual Studio lack proper support for unique_ptr.
|
||||
std::unique_ptr<char[]> loaded_bytes;
|
||||
#else
|
||||
std::unique_ptr<char[], decltype(&aligned_free_char)> loaded_bytes;
|
||||
#endif
|
||||
|
||||
/** Capacity of loaded_bytes buffer. */
|
||||
size_t _loaded_bytes_capacity{0};
|
||||
|
||||
@@ -3,7 +3,6 @@
|
||||
|
||||
#include "simdjson/common_defs.h"
|
||||
#include "simdjson/internal/dom_parser_implementation.h"
|
||||
#include <optional>
|
||||
#include <string>
|
||||
#include <atomic>
|
||||
#include <vector>
|
||||
|
||||
@@ -50,6 +50,10 @@ really_inline simdjson_result<const char *> simdjson_result<dom::element>::get_c
|
||||
if (error()) { return error(); }
|
||||
return first.get_c_str();
|
||||
}
|
||||
really_inline simdjson_result<size_t> simdjson_result<dom::element>::get_string_length() const noexcept {
|
||||
if (error()) { return error(); }
|
||||
return first.get_string_length();
|
||||
}
|
||||
really_inline simdjson_result<std::string_view> simdjson_result<dom::element>::get_string() const noexcept {
|
||||
if (error()) { return error(); }
|
||||
return first.get_string();
|
||||
@@ -190,6 +194,15 @@ inline simdjson_result<const char *> element::get_c_str() const noexcept {
|
||||
return INCORRECT_TYPE;
|
||||
}
|
||||
}
|
||||
inline simdjson_result<size_t> element::get_string_length() const noexcept {
|
||||
switch (tape.tape_ref_type()) {
|
||||
case internal::tape_type::STRING: {
|
||||
return tape.get_string_length();
|
||||
}
|
||||
default:
|
||||
return INCORRECT_TYPE;
|
||||
}
|
||||
}
|
||||
inline simdjson_result<std::string_view> element::get_string() const noexcept {
|
||||
switch (tape.tape_ref_type()) {
|
||||
case internal::tape_type::STRING:
|
||||
|
||||
@@ -21,7 +21,12 @@ inline char *allocate_padded_buffer(size_t length) noexcept {
|
||||
// return (char *) malloc(length + SIMDJSON_PADDING);
|
||||
// However, we might as well align to cache lines...
|
||||
size_t totalpaddedlength = length + SIMDJSON_PADDING;
|
||||
#if defined(_MSC_VER) && _MSC_VER < 1910
|
||||
// For legacy Visual Studio 2015 since it does not have proper C++11 support
|
||||
char *padded_buffer = new[totalpaddedlength];
|
||||
#else
|
||||
char *padded_buffer = aligned_malloc_char(64, totalpaddedlength);
|
||||
#endif
|
||||
#ifndef NDEBUG
|
||||
if (padded_buffer == nullptr) {
|
||||
return nullptr;
|
||||
|
||||
@@ -15,10 +15,18 @@ namespace dom {
|
||||
//
|
||||
// parser inline implementation
|
||||
//
|
||||
#if defined(_MSC_VER) && _MSC_VER < 1910
|
||||
// older versions of Visual Studio lack proper support for unique_ptr.
|
||||
really_inline parser::parser(size_t max_capacity) noexcept
|
||||
: _max_capacity{max_capacity},
|
||||
loaded_bytes(nullptr) {
|
||||
}
|
||||
#else
|
||||
really_inline parser::parser(size_t max_capacity) noexcept
|
||||
: _max_capacity{max_capacity},
|
||||
loaded_bytes(nullptr, &aligned_free_char) {
|
||||
}
|
||||
#endif
|
||||
really_inline parser::parser(parser &&other) noexcept = default;
|
||||
really_inline parser &parser::operator=(parser &&other) noexcept = default;
|
||||
|
||||
|
||||
@@ -81,14 +81,14 @@ really_inline T tape_ref::next_tape_value() const noexcept {
|
||||
}
|
||||
|
||||
really_inline uint32_t internal::tape_ref::get_string_length() const noexcept {
|
||||
uint64_t string_buf_index = size_t(tape_value());
|
||||
size_t string_buf_index = size_t(tape_value());
|
||||
uint32_t len;
|
||||
memcpy(&len, &doc->string_buf[string_buf_index], sizeof(len));
|
||||
return len;
|
||||
}
|
||||
|
||||
really_inline const char * internal::tape_ref::get_c_str() const noexcept {
|
||||
uint64_t string_buf_index = size_t(tape_value());
|
||||
size_t string_buf_index = size_t(tape_value());
|
||||
return reinterpret_cast<const char *>(&doc->string_buf[string_buf_index + sizeof(uint32_t)]);
|
||||
}
|
||||
|
||||
|
||||
@@ -4,7 +4,8 @@
|
||||
#include <cstddef>
|
||||
#include <cstdint>
|
||||
#include <cstdlib>
|
||||
|
||||
#include <cfloat>
|
||||
#include <cassert>
|
||||
|
||||
#ifdef _MSC_VER
|
||||
#define SIMDJSON_VISUAL_STUDIO 1
|
||||
@@ -37,24 +38,28 @@
|
||||
|
||||
#if defined(__x86_64__) || defined(_M_AMD64)
|
||||
#define SIMDJSON_IS_X86_64 1
|
||||
#endif
|
||||
#if defined(__aarch64__) || defined(_M_ARM64)
|
||||
#elif defined(__aarch64__) || defined(_M_ARM64)
|
||||
#define SIMDJSON_IS_ARM64 1
|
||||
#else
|
||||
#define SIMDJSON_IS_32BITS 1
|
||||
|
||||
// We do not support 32-bit platforms, but it can be
|
||||
// handy to identify them.
|
||||
#if defined(_M_IX86) || defined(__i386__)
|
||||
#define SIMDJSON_IS_X86_32BITS 1
|
||||
#elif defined(__arm__) || defined(_M_ARM)
|
||||
#define SIMDJSON_IS_ARM_32BITS 1
|
||||
#endif
|
||||
|
||||
#if (!defined(SIMDJSON_IS_X86_64)) && (!defined(SIMDJSON_IS_ARM64))
|
||||
#ifdef SIMDJSON_REGULAR_VISUAL_STUDIO
|
||||
#pragma message("The simdjson library is designed\
|
||||
for 64-bit processors and it seems that you are not \
|
||||
#endif // defined(__x86_64__) || defined(_M_AMD64)
|
||||
|
||||
#ifdef SIMDJSON_IS_32BITS
|
||||
#pragma message("The simdjson library is designed \
|
||||
for 64-bit processors and it seems that you are not \
|
||||
compiling for a known 64-bit platform. All fast kernels \
|
||||
will be disabled and performance may be poor. Please \
|
||||
use a 64-bit target such as x64 or 64-bit ARM.")
|
||||
#else
|
||||
#error "The simdjson library is designed\
|
||||
for 64-bit processors. It seems that you are not \
|
||||
compiling for a known 64-bit platform."
|
||||
#endif
|
||||
#endif // (!defined(SIMDJSON_IS_X86_64)) && (!defined(SIMDJSON_IS_ARM64))
|
||||
#endif // SIMDJSON_IS_32BITS
|
||||
|
||||
// this is almost standard?
|
||||
#undef STRINGIFY_IMPLEMENTATION_
|
||||
@@ -74,6 +79,15 @@ compiling for a known 64-bit platform."
|
||||
#define SIMDJSON_IMPLEMENTATION_WESTMERE 0
|
||||
#endif // SIMDJSON_IS_ARM64
|
||||
|
||||
// Our fast kernels require 64-bit systems.
|
||||
//
|
||||
// On 32-bit x86, we lack 64-bit popcnt, lzcnt, blsr instructions.
|
||||
// Furthermore, the number of SIMD registers is reduced.
|
||||
//
|
||||
// On 32-bit ARM, we would have smaller registers.
|
||||
//
|
||||
// The simdjson users should still have the fallback kernel. It is
|
||||
// slower, but it should run everywhere.
|
||||
#if SIMDJSON_IS_X86_64
|
||||
#ifndef SIMDJSON_IMPLEMENTATION_HASWELL
|
||||
#define SIMDJSON_IMPLEMENTATION_HASWELL 1
|
||||
@@ -84,7 +98,7 @@ compiling for a known 64-bit platform."
|
||||
#define SIMDJSON_IMPLEMENTATION_ARM64 0
|
||||
#endif // SIMDJSON_IS_X86_64
|
||||
|
||||
// we are going to use runtime dispatch
|
||||
// We are going to use runtime dispatch.
|
||||
#ifdef SIMDJSON_IS_X86_64
|
||||
#ifdef __clang__
|
||||
// clang does not have GCC push pop
|
||||
@@ -122,7 +136,6 @@ compiling for a known 64-bit platform."
|
||||
#endif
|
||||
#endif
|
||||
|
||||
|
||||
// workaround for large stack sizes under -O0.
|
||||
// https://github.com/simdjson/simdjson/issues/691
|
||||
#ifdef __APPLE__
|
||||
@@ -136,6 +149,13 @@ compiling for a known 64-bit platform."
|
||||
#endif
|
||||
#endif
|
||||
|
||||
|
||||
#if SIMDJSON_DO_NOT_USE_THREADS_NO_MATTER_WHAT
|
||||
// No matter what happened, we undefine SIMDJSON_THREADS_ENABLED and so disable threads.
|
||||
#undef SIMDJSON_THREADS_ENABLED
|
||||
#endif
|
||||
|
||||
|
||||
#if defined(__clang__)
|
||||
#define NO_SANITIZE_UNDEFINED __attribute__((no_sanitize("undefined")))
|
||||
#elif defined(__GNUC__)
|
||||
@@ -212,7 +232,6 @@ static inline void aligned_free_char(char *mem_block) {
|
||||
|
||||
#else // NDEBUG
|
||||
|
||||
#include <cassert>
|
||||
#define SIMDJSON_UNREACHABLE() assert(0);
|
||||
#define SIMDJSON_ASSUME(COND) assert(COND)
|
||||
|
||||
|
||||
@@ -4,7 +4,7 @@
|
||||
#define SIMDJSON_SIMDJSON_VERSION_H
|
||||
|
||||
/** The version of simdjson being used (major.minor.revision) */
|
||||
#define SIMDJSON_VERSION 0.4.0
|
||||
#define SIMDJSON_VERSION 0.4.4
|
||||
|
||||
namespace simdjson {
|
||||
enum {
|
||||
@@ -19,7 +19,7 @@ enum {
|
||||
/**
|
||||
* The revision (major.minor.REVISION) of simdjson being used.
|
||||
*/
|
||||
SIMDJSON_VERSION_REVISION = 0
|
||||
SIMDJSON_VERSION_REVISION = 4
|
||||
};
|
||||
} // namespace simdjson
|
||||
|
||||
|
||||
@@ -20,7 +20,10 @@ set_source_files_properties(${SINGLEHEADER_FILES} PROPERTIES GENERATED TRUE)
|
||||
|
||||
find_program(BASH bash)
|
||||
|
||||
if (BASH)
|
||||
# Under Windows, exectuting a bash script works, except that you cannot generally
|
||||
# do bash C:/path to my script. You need a "mounted" path: /mnt/c/path
|
||||
|
||||
if (BASH AND (NOT WIN32))
|
||||
add_custom_command(
|
||||
OUTPUT ${SINGLEHEADER_FILES}
|
||||
COMMAND ${CMAKE_COMMAND} -E env
|
||||
@@ -69,7 +72,7 @@ if (BASH)
|
||||
# add_custom_target(amalgamate DEPENDS ${CMAKE_CURRENT_SOURCE_DIR}/simdjson.cpp ${CMAKE_CURRENT_SOURCE_DIR}/simdjson.h ${CMAKE_CURRENT_SOURCE_DIR}/amalgamate_demo.cpp ${CMAKE_CURRENT_SOURCE_DIR}/README.md)
|
||||
##
|
||||
|
||||
else(BASH)
|
||||
else()
|
||||
|
||||
# We do not have bash, so we use existing amalgamated files instead of generating them ...
|
||||
# (Do not do this if the source and destination are the same!)
|
||||
@@ -83,7 +86,7 @@ else(BASH)
|
||||
)
|
||||
endif()
|
||||
|
||||
endif(BASH)
|
||||
endif()
|
||||
|
||||
#
|
||||
# Do not depend on singleheader files directly: depend on this target instead.
|
||||
|
||||
@@ -132,6 +132,7 @@ cat <<< '
|
||||
int main(int argc, char *argv[]) {
|
||||
if(argc < 2) {
|
||||
std::cerr << "Please specify at least one file name. " << std::endl;
|
||||
return EXIT_FAILURE;
|
||||
}
|
||||
const char * filename = argv[1];
|
||||
simdjson::dom::parser parser;
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
/* auto-generated on Tue 23 Jun 2020 20:51:12 EDT. Do not edit! */
|
||||
/* auto-generated on Tue 30 Jun 2020 09:41:13 EDT. Do not edit! */
|
||||
|
||||
#include <iostream>
|
||||
#include "simdjson.h"
|
||||
@@ -6,6 +6,7 @@
|
||||
int main(int argc, char *argv[]) {
|
||||
if(argc < 2) {
|
||||
std::cerr << "Please specify at least one file name. " << std::endl;
|
||||
return EXIT_FAILURE;
|
||||
}
|
||||
const char * filename = argv[1];
|
||||
simdjson::dom::parser parser;
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
/* auto-generated on Tue 23 Jun 2020 20:51:12 EDT. Do not edit! */
|
||||
/* auto-generated on Tue 30 Jun 2020 09:41:13 EDT. Do not edit! */
|
||||
/* begin file src/simdjson.cpp */
|
||||
#include "simdjson.h"
|
||||
|
||||
@@ -213,6 +213,10 @@ static inline uint32_t detect_supported_architectures() {
|
||||
/* begin file src/simdprune_tables.h */
|
||||
#ifndef SIMDJSON_SIMDPRUNE_TABLES_H
|
||||
#define SIMDJSON_SIMDPRUNE_TABLES_H
|
||||
|
||||
|
||||
#if SIMDJSON_IMPLEMENTATION_ARM64 || SIMDJSON_IMPLEMENTATION_HASWELL || SIMDJSON_IMPLEMENTATION_WESTMERE
|
||||
|
||||
#include <cstdint>
|
||||
|
||||
namespace simdjson { // table modified and copied from
|
||||
@@ -340,6 +344,8 @@ static const uint64_t thintable_epi8[256] = {
|
||||
|
||||
} // namespace simdjson
|
||||
|
||||
|
||||
#endif // SIMDJSON_IMPLEMENTATION_ARM64 || SIMDJSON_IMPLEMENTATION_HASWELL || SIMDJSON_IMPLEMENTATION_WESTMERE
|
||||
#endif // SIMDJSON_SIMDPRUNE_TABLES_H
|
||||
/* end file src/simdprune_tables.h */
|
||||
|
||||
@@ -934,9 +940,8 @@ struct value128 {
|
||||
uint64_t high;
|
||||
};
|
||||
|
||||
#if defined(SIMDJSON_REGULAR_VISUAL_STUDIO) && \
|
||||
!defined(_M_X64) && !defined(_M_ARM64)// _umul128 for x86, arm
|
||||
// this is a slow emulation routine for 32-bit Windows
|
||||
#ifdef SIMDJSON_IS_32BITS // _umul128 for x86, arm
|
||||
// this is a slow emulation routine for 32-bit
|
||||
//
|
||||
static inline uint64_t __emulu(uint32_t x, uint32_t y) {
|
||||
return x * (uint64_t)y;
|
||||
@@ -955,7 +960,7 @@ static inline uint64_t _umul128(uint64_t ab, uint64_t cd, uint64_t *hi) {
|
||||
|
||||
really_inline value128 full_multiplication(uint64_t value1, uint64_t value2) {
|
||||
value128 answer;
|
||||
#ifdef SIMDJSON_REGULAR_VISUAL_STUDIO
|
||||
#if defined(SIMDJSON_REGULAR_VISUAL_STUDIO) || defined(SIMDJSON_IS_32BITS)
|
||||
#ifdef _M_ARM64
|
||||
// ARM64 has native support for 64-bit multiplications, no need to emultate
|
||||
answer.high = __umulh(value1, value2);
|
||||
@@ -963,7 +968,7 @@ really_inline value128 full_multiplication(uint64_t value1, uint64_t value2) {
|
||||
#else
|
||||
answer.low = _umul128(value1, value2, &answer.high); // _umul128 not available on ARM64
|
||||
#endif // _M_ARM64
|
||||
#else // SIMDJSON_REGULAR_VISUAL_STUDIO
|
||||
#else // defined(SIMDJSON_REGULAR_VISUAL_STUDIO) || defined(SIMDJSON_IS_32BITS)
|
||||
__uint128_t r = ((__uint128_t)value1) * value2;
|
||||
answer.low = uint64_t(r);
|
||||
answer.high = uint64_t(r >> 64);
|
||||
@@ -4038,7 +4043,15 @@ really_inline double compute_float_64(int64_t power, uint64_t i, bool negative,
|
||||
// It was described in
|
||||
// Clinger WD. How to read floating point numbers accurately.
|
||||
// ACM SIGPLAN Notices. 1990
|
||||
#ifndef FLT_EVAL_METHOD
|
||||
#error "FLT_EVAL_METHOD should be defined, please include cfloat."
|
||||
#endif
|
||||
#if (FLT_EVAL_METHOD != 1) && (FLT_EVAL_METHOD != 0)
|
||||
// We cannot be certain that x/y is rounded to nearest.
|
||||
if (0 <= power && power <= 22 && i <= 9007199254740991) {
|
||||
#else
|
||||
if (-22 <= power && power <= 22 && i <= 9007199254740991) {
|
||||
#endif
|
||||
// convert the integer into a double. This is lossless since
|
||||
// 0 <= i <= 2^53 - 1.
|
||||
double d = double(i);
|
||||
@@ -6195,7 +6208,15 @@ really_inline double compute_float_64(int64_t power, uint64_t i, bool negative,
|
||||
// It was described in
|
||||
// Clinger WD. How to read floating point numbers accurately.
|
||||
// ACM SIGPLAN Notices. 1990
|
||||
#ifndef FLT_EVAL_METHOD
|
||||
#error "FLT_EVAL_METHOD should be defined, please include cfloat."
|
||||
#endif
|
||||
#if (FLT_EVAL_METHOD != 1) && (FLT_EVAL_METHOD != 0)
|
||||
// We cannot be certain that x/y is rounded to nearest.
|
||||
if (0 <= power && power <= 22 && i <= 9007199254740991) {
|
||||
#else
|
||||
if (-22 <= power && power <= 22 && i <= 9007199254740991) {
|
||||
#endif
|
||||
// convert the integer into a double. This is lossless since
|
||||
// 0 <= i <= 2^53 - 1.
|
||||
double d = double(i);
|
||||
@@ -7826,7 +7847,7 @@ really_inline bool add_overflow(uint64_t value1, uint64_t value2,
|
||||
#endif
|
||||
}
|
||||
|
||||
#ifdef SIMDJSON_REGULAR_VISUAL_STUDIO
|
||||
#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,
|
||||
@@ -9499,7 +9520,15 @@ really_inline double compute_float_64(int64_t power, uint64_t i, bool negative,
|
||||
// It was described in
|
||||
// Clinger WD. How to read floating point numbers accurately.
|
||||
// ACM SIGPLAN Notices. 1990
|
||||
#ifndef FLT_EVAL_METHOD
|
||||
#error "FLT_EVAL_METHOD should be defined, please include cfloat."
|
||||
#endif
|
||||
#if (FLT_EVAL_METHOD != 1) && (FLT_EVAL_METHOD != 0)
|
||||
// We cannot be certain that x/y is rounded to nearest.
|
||||
if (0 <= power && power <= 22 && i <= 9007199254740991) {
|
||||
#else
|
||||
if (-22 <= power && power <= 22 && i <= 9007199254740991) {
|
||||
#endif
|
||||
// convert the integer into a double. This is lossless since
|
||||
// 0 <= i <= 2^53 - 1.
|
||||
double d = double(i);
|
||||
@@ -11114,7 +11143,7 @@ really_inline bool add_overflow(uint64_t value1, uint64_t value2,
|
||||
#endif
|
||||
}
|
||||
|
||||
#ifdef SIMDJSON_REGULAR_VISUAL_STUDIO
|
||||
#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,
|
||||
@@ -12777,7 +12806,15 @@ really_inline double compute_float_64(int64_t power, uint64_t i, bool negative,
|
||||
// It was described in
|
||||
// Clinger WD. How to read floating point numbers accurately.
|
||||
// ACM SIGPLAN Notices. 1990
|
||||
#ifndef FLT_EVAL_METHOD
|
||||
#error "FLT_EVAL_METHOD should be defined, please include cfloat."
|
||||
#endif
|
||||
#if (FLT_EVAL_METHOD != 1) && (FLT_EVAL_METHOD != 0)
|
||||
// We cannot be certain that x/y is rounded to nearest.
|
||||
if (0 <= power && power <= 22 && i <= 9007199254740991) {
|
||||
#else
|
||||
if (-22 <= power && power <= 22 && i <= 9007199254740991) {
|
||||
#endif
|
||||
// convert the integer into a double. This is lossless since
|
||||
// 0 <= i <= 2^53 - 1.
|
||||
double d = double(i);
|
||||
|
||||
+108
-32
@@ -1,4 +1,4 @@
|
||||
/* auto-generated on Tue 23 Jun 2020 20:51:12 EDT. Do not edit! */
|
||||
/* auto-generated on Tue 30 Jun 2020 09:41:13 EDT. Do not edit! */
|
||||
/* begin file include/simdjson.h */
|
||||
#ifndef SIMDJSON_H
|
||||
#define SIMDJSON_H
|
||||
@@ -58,7 +58,8 @@
|
||||
#include <cstddef>
|
||||
#include <cstdint>
|
||||
#include <cstdlib>
|
||||
|
||||
#include <cfloat>
|
||||
#include <cassert>
|
||||
|
||||
#ifdef _MSC_VER
|
||||
#define SIMDJSON_VISUAL_STUDIO 1
|
||||
@@ -91,24 +92,28 @@
|
||||
|
||||
#if defined(__x86_64__) || defined(_M_AMD64)
|
||||
#define SIMDJSON_IS_X86_64 1
|
||||
#endif
|
||||
#if defined(__aarch64__) || defined(_M_ARM64)
|
||||
#elif defined(__aarch64__) || defined(_M_ARM64)
|
||||
#define SIMDJSON_IS_ARM64 1
|
||||
#else
|
||||
#define SIMDJSON_IS_32BITS 1
|
||||
|
||||
// We do not support 32-bit platforms, but it can be
|
||||
// handy to identify them.
|
||||
#if defined(_M_IX86) || defined(__i386__)
|
||||
#define SIMDJSON_IS_X86_32BITS 1
|
||||
#elif defined(__arm__) || defined(_M_ARM)
|
||||
#define SIMDJSON_IS_ARM_32BITS 1
|
||||
#endif
|
||||
|
||||
#if (!defined(SIMDJSON_IS_X86_64)) && (!defined(SIMDJSON_IS_ARM64))
|
||||
#ifdef SIMDJSON_REGULAR_VISUAL_STUDIO
|
||||
#pragma message("The simdjson library is designed\
|
||||
for 64-bit processors and it seems that you are not \
|
||||
#endif // defined(__x86_64__) || defined(_M_AMD64)
|
||||
|
||||
#ifdef SIMDJSON_IS_32BITS
|
||||
#pragma message("The simdjson library is designed \
|
||||
for 64-bit processors and it seems that you are not \
|
||||
compiling for a known 64-bit platform. All fast kernels \
|
||||
will be disabled and performance may be poor. Please \
|
||||
use a 64-bit target such as x64 or 64-bit ARM.")
|
||||
#else
|
||||
#error "The simdjson library is designed\
|
||||
for 64-bit processors. It seems that you are not \
|
||||
compiling for a known 64-bit platform."
|
||||
#endif
|
||||
#endif // (!defined(SIMDJSON_IS_X86_64)) && (!defined(SIMDJSON_IS_ARM64))
|
||||
#endif // SIMDJSON_IS_32BITS
|
||||
|
||||
// this is almost standard?
|
||||
#undef STRINGIFY_IMPLEMENTATION_
|
||||
@@ -128,6 +133,15 @@ compiling for a known 64-bit platform."
|
||||
#define SIMDJSON_IMPLEMENTATION_WESTMERE 0
|
||||
#endif // SIMDJSON_IS_ARM64
|
||||
|
||||
// Our fast kernels require 64-bit systems.
|
||||
//
|
||||
// On 32-bit x86, we lack 64-bit popcnt, lzcnt, blsr instructions.
|
||||
// Furthermore, the number of SIMD registers is reduced.
|
||||
//
|
||||
// On 32-bit ARM, we would have smaller registers.
|
||||
//
|
||||
// The simdjson users should still have the fallback kernel. It is
|
||||
// slower, but it should run everywhere.
|
||||
#if SIMDJSON_IS_X86_64
|
||||
#ifndef SIMDJSON_IMPLEMENTATION_HASWELL
|
||||
#define SIMDJSON_IMPLEMENTATION_HASWELL 1
|
||||
@@ -138,7 +152,7 @@ compiling for a known 64-bit platform."
|
||||
#define SIMDJSON_IMPLEMENTATION_ARM64 0
|
||||
#endif // SIMDJSON_IS_X86_64
|
||||
|
||||
// we are going to use runtime dispatch
|
||||
// We are going to use runtime dispatch.
|
||||
#ifdef SIMDJSON_IS_X86_64
|
||||
#ifdef __clang__
|
||||
// clang does not have GCC push pop
|
||||
@@ -176,7 +190,6 @@ compiling for a known 64-bit platform."
|
||||
#endif
|
||||
#endif
|
||||
|
||||
|
||||
// workaround for large stack sizes under -O0.
|
||||
// https://github.com/simdjson/simdjson/issues/691
|
||||
#ifdef __APPLE__
|
||||
@@ -190,6 +203,13 @@ compiling for a known 64-bit platform."
|
||||
#endif
|
||||
#endif
|
||||
|
||||
|
||||
#if SIMDJSON_DO_NOT_USE_THREADS_NO_MATTER_WHAT
|
||||
// No matter what happened, we undefine SIMDJSON_THREADS_ENABLED and so disable threads.
|
||||
#undef SIMDJSON_THREADS_ENABLED
|
||||
#endif
|
||||
|
||||
|
||||
#if defined(__clang__)
|
||||
#define NO_SANITIZE_UNDEFINED __attribute__((no_sanitize("undefined")))
|
||||
#elif defined(__GNUC__)
|
||||
@@ -266,7 +286,6 @@ static inline void aligned_free_char(char *mem_block) {
|
||||
|
||||
#else // NDEBUG
|
||||
|
||||
#include <cassert>
|
||||
#define SIMDJSON_UNREACHABLE() assert(0);
|
||||
#define SIMDJSON_ASSUME(COND) assert(COND)
|
||||
|
||||
@@ -353,12 +372,15 @@ constexpr size_t DEFAULT_MAX_DEPTH = 1024;
|
||||
#define SIMDJSON_PUSH_DISABLE_ALL_WARNINGS __pragma(warning( push, 0 ))
|
||||
#define SIMDJSON_DISABLE_VS_WARNING(WARNING_NUMBER) __pragma(warning( disable : WARNING_NUMBER ))
|
||||
// Get rid of Intellisense-only warnings (Code Analysis)
|
||||
// Though __has_include is C++17, it looks like it is supported in Visual Studio 2017 or better.
|
||||
// We are probably not supporting earlier version of Visual Studio in any case.
|
||||
// Though __has_include is C++17, it is supported in Visual Studio 2017 or better (_MSC_VER>=1910).
|
||||
#if defined(_MSC_VER) && (_MSC_VER>=1910)
|
||||
#if __has_include(<CppCoreCheck\Warnings.h>)
|
||||
#include <CppCoreCheck\Warnings.h>
|
||||
#define SIMDJSON_DISABLE_UNDESIRED_WARNINGS SIMDJSON_DISABLE_VS_WARNING(ALL_CPPCORECHECK_WARNINGS)
|
||||
#else
|
||||
#endif
|
||||
#endif
|
||||
|
||||
#ifndef SIMDJSON_DISABLE_UNDESIRED_WARNINGS
|
||||
#define SIMDJSON_DISABLE_UNDESIRED_WARNINGS
|
||||
#endif
|
||||
|
||||
@@ -2018,7 +2040,7 @@ SIMDJSON_DISABLE_UNDESIRED_WARNINGS
|
||||
#define SIMDJSON_SIMDJSON_VERSION_H
|
||||
|
||||
/** The version of simdjson being used (major.minor.revision) */
|
||||
#define SIMDJSON_VERSION 0.4.0
|
||||
#define SIMDJSON_VERSION 0.4.4
|
||||
|
||||
namespace simdjson {
|
||||
enum {
|
||||
@@ -2033,7 +2055,7 @@ enum {
|
||||
/**
|
||||
* The revision (major.minor.REVISION) of simdjson being used.
|
||||
*/
|
||||
SIMDJSON_VERSION_REVISION = 0
|
||||
SIMDJSON_VERSION_REVISION = 4
|
||||
};
|
||||
} // namespace simdjson
|
||||
|
||||
@@ -2632,7 +2654,6 @@ inline error_code dom_parser_implementation::allocate(size_t capacity, size_t ma
|
||||
|
||||
#endif // SIMDJSON_INTERNAL_DOM_PARSER_IMPLEMENTATION_H
|
||||
/* end file include/simdjson/internal/dom_parser_implementation.h */
|
||||
#include <optional>
|
||||
#include <string>
|
||||
#include <atomic>
|
||||
#include <vector>
|
||||
@@ -3654,7 +3675,12 @@ private:
|
||||
/**
|
||||
* The loaded buffer (reused each time load() is called)
|
||||
*/
|
||||
#if defined(_MSC_VER) && _MSC_VER < 1910
|
||||
// older versions of Visual Studio lack proper support for unique_ptr.
|
||||
std::unique_ptr<char[]> loaded_bytes;
|
||||
#else
|
||||
std::unique_ptr<char[], decltype(&aligned_free_char)> loaded_bytes;
|
||||
#endif
|
||||
|
||||
/** Capacity of loaded_bytes buffer. */
|
||||
size_t _loaded_bytes_capacity{0};
|
||||
@@ -4008,21 +4034,42 @@ public:
|
||||
*/
|
||||
inline simdjson_result<object> get_object() const noexcept;
|
||||
/**
|
||||
* Cast this element to a string.
|
||||
* Cast this element to a null-terminated C string.
|
||||
*
|
||||
* The string is guaranteed to be valid UTF-8.
|
||||
*
|
||||
* Equivalent to get<const char *>().
|
||||
* The get_c_str() function is equivalent to get<const char *>().
|
||||
*
|
||||
* The length of the string is given by get_string_length(). Because JSON strings
|
||||
* may contain null characters, it may be incorrect to use strlen to determine the
|
||||
* string length.
|
||||
*
|
||||
* @returns An pointer to a null-terminated string. This string is stored in the parser and will
|
||||
* It is possible to get a single string_view instance which represents both the string
|
||||
* content and its length: see get_string().
|
||||
*
|
||||
* @returns A pointer to a null-terminated UTF-8 string. This string is stored in the parser and will
|
||||
* be invalidated the next time it parses a document or when it is destroyed.
|
||||
* Returns INCORRECT_TYPE if the JSON element is not a string.
|
||||
*/
|
||||
inline simdjson_result<const char *> get_c_str() const noexcept;
|
||||
/**
|
||||
* Cast this element to a string.
|
||||
* Gives the length in bytes of the string.
|
||||
*
|
||||
* It is possible to get a single string_view instance which represents both the string
|
||||
* content and its length: see get_string().
|
||||
*
|
||||
* @returns A string length in bytes.
|
||||
* Returns INCORRECT_TYPE if the JSON element is not a string.
|
||||
*/
|
||||
inline simdjson_result<size_t> get_string_length() const noexcept;
|
||||
/**
|
||||
* Cast this element to a string.
|
||||
*
|
||||
* The string is guaranteed to be valid UTF-8.
|
||||
*
|
||||
* Equivalent to get<std::string_view>().
|
||||
*
|
||||
* @returns A string. The string is stored in the parser and will be invalidated the next time it
|
||||
* @returns An UTF-8 string. The string is stored in the parser and will be invalidated the next time it
|
||||
* parses a document or when it is destroyed.
|
||||
* Returns INCORRECT_TYPE if the JSON element is not a string.
|
||||
*/
|
||||
@@ -4199,7 +4246,9 @@ public:
|
||||
inline operator bool() const noexcept(false);
|
||||
|
||||
/**
|
||||
* Read this element as a null-terminated string.
|
||||
* Read this element as a null-terminated UTF-8 string.
|
||||
*
|
||||
* Be mindful that JSON allows strings to contain null characters.
|
||||
*
|
||||
* Does *not* convert other types to a string; requires that the JSON type of the element was
|
||||
* an actual string.
|
||||
@@ -4210,7 +4259,7 @@ public:
|
||||
inline explicit operator const char*() const noexcept(false);
|
||||
|
||||
/**
|
||||
* Read this element as a null-terminated string.
|
||||
* Read this element as a null-terminated UTF-8 string.
|
||||
*
|
||||
* Does *not* convert other types to a string; requires that the JSON type of the element was
|
||||
* an actual string.
|
||||
@@ -4410,6 +4459,7 @@ public:
|
||||
really_inline simdjson_result<dom::array> get_array() const noexcept;
|
||||
really_inline simdjson_result<dom::object> get_object() const noexcept;
|
||||
really_inline simdjson_result<const char *> get_c_str() const noexcept;
|
||||
really_inline simdjson_result<size_t> get_string_length() const noexcept;
|
||||
really_inline simdjson_result<std::string_view> get_string() const noexcept;
|
||||
really_inline simdjson_result<int64_t> get_int64() const noexcept;
|
||||
really_inline simdjson_result<uint64_t> get_uint64() const noexcept;
|
||||
@@ -5820,6 +5870,10 @@ really_inline simdjson_result<const char *> simdjson_result<dom::element>::get_c
|
||||
if (error()) { return error(); }
|
||||
return first.get_c_str();
|
||||
}
|
||||
really_inline simdjson_result<size_t> simdjson_result<dom::element>::get_string_length() const noexcept {
|
||||
if (error()) { return error(); }
|
||||
return first.get_string_length();
|
||||
}
|
||||
really_inline simdjson_result<std::string_view> simdjson_result<dom::element>::get_string() const noexcept {
|
||||
if (error()) { return error(); }
|
||||
return first.get_string();
|
||||
@@ -5960,6 +6014,15 @@ inline simdjson_result<const char *> element::get_c_str() const noexcept {
|
||||
return INCORRECT_TYPE;
|
||||
}
|
||||
}
|
||||
inline simdjson_result<size_t> element::get_string_length() const noexcept {
|
||||
switch (tape.tape_ref_type()) {
|
||||
case internal::tape_type::STRING: {
|
||||
return tape.get_string_length();
|
||||
}
|
||||
default:
|
||||
return INCORRECT_TYPE;
|
||||
}
|
||||
}
|
||||
inline simdjson_result<std::string_view> element::get_string() const noexcept {
|
||||
switch (tape.tape_ref_type()) {
|
||||
case internal::tape_type::STRING:
|
||||
@@ -6723,7 +6786,12 @@ inline char *allocate_padded_buffer(size_t length) noexcept {
|
||||
// return (char *) malloc(length + SIMDJSON_PADDING);
|
||||
// However, we might as well align to cache lines...
|
||||
size_t totalpaddedlength = length + SIMDJSON_PADDING;
|
||||
#if defined(_MSC_VER) && _MSC_VER < 1910
|
||||
// For legacy Visual Studio 2015 since it does not have proper C++11 support
|
||||
char *padded_buffer = new[totalpaddedlength];
|
||||
#else
|
||||
char *padded_buffer = aligned_malloc_char(64, totalpaddedlength);
|
||||
#endif
|
||||
#ifndef NDEBUG
|
||||
if (padded_buffer == nullptr) {
|
||||
return nullptr;
|
||||
@@ -7345,10 +7413,18 @@ namespace dom {
|
||||
//
|
||||
// parser inline implementation
|
||||
//
|
||||
#if defined(_MSC_VER) && _MSC_VER < 1910
|
||||
// older versions of Visual Studio lack proper support for unique_ptr.
|
||||
really_inline parser::parser(size_t max_capacity) noexcept
|
||||
: _max_capacity{max_capacity},
|
||||
loaded_bytes(nullptr) {
|
||||
}
|
||||
#else
|
||||
really_inline parser::parser(size_t max_capacity) noexcept
|
||||
: _max_capacity{max_capacity},
|
||||
loaded_bytes(nullptr, &aligned_free_char) {
|
||||
}
|
||||
#endif
|
||||
really_inline parser::parser(parser &&other) noexcept = default;
|
||||
really_inline parser &parser::operator=(parser &&other) noexcept = default;
|
||||
|
||||
@@ -7610,14 +7686,14 @@ really_inline T tape_ref::next_tape_value() const noexcept {
|
||||
}
|
||||
|
||||
really_inline uint32_t internal::tape_ref::get_string_length() const noexcept {
|
||||
uint64_t string_buf_index = size_t(tape_value());
|
||||
size_t string_buf_index = size_t(tape_value());
|
||||
uint32_t len;
|
||||
memcpy(&len, &doc->string_buf[string_buf_index], sizeof(len));
|
||||
return len;
|
||||
}
|
||||
|
||||
really_inline const char * internal::tape_ref::get_c_str() const noexcept {
|
||||
uint64_t string_buf_index = size_t(tape_value());
|
||||
size_t string_buf_index = size_t(tape_value());
|
||||
return reinterpret_cast<const char *>(&doc->string_buf[string_buf_index + sizeof(uint32_t)]);
|
||||
}
|
||||
|
||||
|
||||
@@ -13,7 +13,15 @@ really_inline double compute_float_64(int64_t power, uint64_t i, bool negative,
|
||||
// It was described in
|
||||
// Clinger WD. How to read floating point numbers accurately.
|
||||
// ACM SIGPLAN Notices. 1990
|
||||
#ifndef FLT_EVAL_METHOD
|
||||
#error "FLT_EVAL_METHOD should be defined, please include cfloat."
|
||||
#endif
|
||||
#if (FLT_EVAL_METHOD != 1) && (FLT_EVAL_METHOD != 0)
|
||||
// We cannot be certain that x/y is rounded to nearest.
|
||||
if (0 <= power && power <= 22 && i <= 9007199254740991) {
|
||||
#else
|
||||
if (-22 <= power && power <= 22 && i <= 9007199254740991) {
|
||||
#endif
|
||||
// convert the integer into a double. This is lossless since
|
||||
// 0 <= i <= 2^53 - 1.
|
||||
double d = double(i);
|
||||
|
||||
@@ -58,7 +58,7 @@ really_inline bool add_overflow(uint64_t value1, uint64_t value2,
|
||||
#endif
|
||||
}
|
||||
|
||||
#ifdef SIMDJSON_REGULAR_VISUAL_STUDIO
|
||||
#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,
|
||||
|
||||
+4
-5
@@ -317,9 +317,8 @@ struct value128 {
|
||||
uint64_t high;
|
||||
};
|
||||
|
||||
#if defined(SIMDJSON_REGULAR_VISUAL_STUDIO) && \
|
||||
!defined(_M_X64) && !defined(_M_ARM64)// _umul128 for x86, arm
|
||||
// this is a slow emulation routine for 32-bit Windows
|
||||
#ifdef SIMDJSON_IS_32BITS // _umul128 for x86, arm
|
||||
// this is a slow emulation routine for 32-bit
|
||||
//
|
||||
static inline uint64_t __emulu(uint32_t x, uint32_t y) {
|
||||
return x * (uint64_t)y;
|
||||
@@ -338,7 +337,7 @@ static inline uint64_t _umul128(uint64_t ab, uint64_t cd, uint64_t *hi) {
|
||||
|
||||
really_inline value128 full_multiplication(uint64_t value1, uint64_t value2) {
|
||||
value128 answer;
|
||||
#ifdef SIMDJSON_REGULAR_VISUAL_STUDIO
|
||||
#if defined(SIMDJSON_REGULAR_VISUAL_STUDIO) || defined(SIMDJSON_IS_32BITS)
|
||||
#ifdef _M_ARM64
|
||||
// ARM64 has native support for 64-bit multiplications, no need to emultate
|
||||
answer.high = __umulh(value1, value2);
|
||||
@@ -346,7 +345,7 @@ really_inline value128 full_multiplication(uint64_t value1, uint64_t value2) {
|
||||
#else
|
||||
answer.low = _umul128(value1, value2, &answer.high); // _umul128 not available on ARM64
|
||||
#endif // _M_ARM64
|
||||
#else // SIMDJSON_REGULAR_VISUAL_STUDIO
|
||||
#else // defined(SIMDJSON_REGULAR_VISUAL_STUDIO) || defined(SIMDJSON_IS_32BITS)
|
||||
__uint128_t r = ((__uint128_t)value1) * value2;
|
||||
answer.low = uint64_t(r);
|
||||
answer.high = uint64_t(r >> 64);
|
||||
|
||||
@@ -1,5 +1,9 @@
|
||||
#ifndef SIMDJSON_SIMDPRUNE_TABLES_H
|
||||
#define SIMDJSON_SIMDPRUNE_TABLES_H
|
||||
|
||||
|
||||
#if SIMDJSON_IMPLEMENTATION_ARM64 || SIMDJSON_IMPLEMENTATION_HASWELL || SIMDJSON_IMPLEMENTATION_WESTMERE
|
||||
|
||||
#include <cstdint>
|
||||
|
||||
namespace simdjson { // table modified and copied from
|
||||
@@ -127,4 +131,6 @@ static const uint64_t thintable_epi8[256] = {
|
||||
|
||||
} // namespace simdjson
|
||||
|
||||
|
||||
#endif // SIMDJSON_IMPLEMENTATION_ARM64 || SIMDJSON_IMPLEMENTATION_HASWELL || SIMDJSON_IMPLEMENTATION_WESTMERE
|
||||
#endif // SIMDJSON_SIMDPRUNE_TABLES_H
|
||||
|
||||
@@ -66,7 +66,7 @@ really_inline bool add_overflow(uint64_t value1, uint64_t value2,
|
||||
#endif
|
||||
}
|
||||
|
||||
#ifdef SIMDJSON_REGULAR_VISUAL_STUDIO
|
||||
#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,
|
||||
|
||||
@@ -62,9 +62,12 @@ add_cpp_test(unicode_tests LABELS acceptance per_implementation)
|
||||
|
||||
find_program(BASH bash)
|
||||
|
||||
# Below we skip anything on Windows, not just visual studio, because running bash under Windows requires you to
|
||||
# map app paths to their "mounted" equivalent (e.g., /mnt/c/...). So even if you have bash under Windows, extra work would be
|
||||
# required to make things work robustly. Simply put: bash is not quite portable.
|
||||
|
||||
# Script tests
|
||||
if (BASH AND (NOT MSVC)) # The scripts are not robust enough to run under Windows even if bash is available
|
||||
if (BASH AND (NOT WIN32) AND (TARGET json2json)) # The scripts are not robust enough to run under Windows even if bash is available
|
||||
#
|
||||
# json2json test
|
||||
#
|
||||
|
||||
+20
-4
@@ -18,6 +18,7 @@
|
||||
#include "test_macros.h"
|
||||
|
||||
const size_t AMAZON_CELLPHONES_NDJSON_DOC_COUNT = 793;
|
||||
#define SIMDJSON_SHOW_DEFINE(x) printf("%s=%s\n", #x, STRINGIFY(x))
|
||||
|
||||
namespace number_tests {
|
||||
|
||||
@@ -68,7 +69,9 @@ namespace number_tests {
|
||||
uint64_t ulp = f64_ulp_dist(actual,expected);
|
||||
if(ulp > maxulp) maxulp = ulp;
|
||||
if(ulp > 0) {
|
||||
std::cerr << "JSON '" << buf << " parsed to " << actual << " instead of " << expected << std::endl;
|
||||
std::cerr << "JSON '" << buf << " parsed to ";
|
||||
fprintf( stderr," %18.18g instead of %18.18g\n", actual, expected); // formatting numbers is easier with printf
|
||||
SIMDJSON_SHOW_DEFINE(FLT_EVAL_METHOD);
|
||||
return false;
|
||||
}
|
||||
}
|
||||
@@ -152,18 +155,25 @@ namespace number_tests {
|
||||
std::cout << __func__ << std::endl;
|
||||
char buf[1024];
|
||||
simdjson::dom::parser parser;
|
||||
for (int i = -1000000; i <= 308; ++i) {// large negative values should be zero.
|
||||
|
||||
bool is_pow_correct{1e-308 == std::pow(10,-308)};
|
||||
int start_point = is_pow_correct ? -10000 : -307;
|
||||
if(!is_pow_correct) {
|
||||
std::cout << "On your system, the pow function is busted. Sorry about that. " << std::endl;
|
||||
}
|
||||
for (int i = start_point; i <= 308; ++i) {// large negative values should be zero.
|
||||
size_t n = snprintf(buf, sizeof(buf), "1e%d", i);
|
||||
if (n >= sizeof(buf)) { abort(); }
|
||||
fflush(NULL);
|
||||
|
||||
double actual;
|
||||
auto error = parser.parse(buf, n).get(actual);
|
||||
if (error) { std::cerr << error << std::endl; return false; }
|
||||
double expected = ((i >= -307) ? testing_power_of_ten[i + 307]: std::pow(10, i));
|
||||
int ulp = (int) f64_ulp_dist(actual, expected);
|
||||
if(ulp > 0) {
|
||||
std::cerr << "JSON '" << buf << " parsed to " << actual << " instead of " << expected << std::endl;
|
||||
std::cerr << "JSON '" << buf << " parsed to ";
|
||||
fprintf( stderr," %18.18g instead of %18.18g\n", actual, expected); // formatting numbers is easier with printf
|
||||
SIMDJSON_SHOW_DEFINE(FLT_EVAL_METHOD);
|
||||
return false;
|
||||
}
|
||||
}
|
||||
@@ -1924,6 +1934,7 @@ namespace format_tests {
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
int main(int argc, char *argv[]) {
|
||||
std::cout << std::unitbuf;
|
||||
int c;
|
||||
@@ -1949,6 +1960,11 @@ int main(int argc, char *argv[]) {
|
||||
if (simdjson::active_implementation->name() == "unsupported") {
|
||||
printf("unsupported CPU\n");
|
||||
}
|
||||
// We want to know what we are testing.
|
||||
std::cout << "Running tests against this implementation: " << simdjson::active_implementation->name();
|
||||
std::cout << "(" << simdjson::active_implementation->description() << ")" << std::endl;
|
||||
std::cout << "------------------------------------------------------------" << std::endl;
|
||||
|
||||
std::cout << "Running basic tests." << std::endl;
|
||||
if (validate_tests::run() &&
|
||||
minify_tests::run() &&
|
||||
|
||||
+1
-1
@@ -1,5 +1,5 @@
|
||||
#include <cstring>
|
||||
#ifndef _MSC_VER
|
||||
#if (!(_MSC_VER) && !(__MINGW32__) && !(__MINGW64__))
|
||||
#include <dirent.h>
|
||||
#else
|
||||
// Microsoft can't be bothered to provide standard utils.
|
||||
|
||||
@@ -9,7 +9,7 @@
|
||||
#define JSON_TEST_NUMBERS
|
||||
#endif
|
||||
|
||||
#ifndef _MSC_VER
|
||||
#if (!(_MSC_VER) && !(__MINGW32__) && !(__MINGW64__))
|
||||
#include <dirent.h>
|
||||
#else
|
||||
#include <dirent_portable.h>
|
||||
@@ -87,7 +87,11 @@ void found_integer(int64_t result, const uint8_t *buf) {
|
||||
char *endptr;
|
||||
long long expected = strtoll((const char *)buf, &endptr, 10);
|
||||
if ((endptr == (const char *)buf) || (expected != result)) {
|
||||
#if (!(__MINGW32__) && !(__MINGW64__))
|
||||
fprintf(stderr, "Error: parsed %" PRId64 " out of %.32s, ", result, buf);
|
||||
#else // mingw is busted since we include #include <inttypes.h>
|
||||
fprintf(stderr, "Error: parsed %lld out of %.32s, ", (long long)result, buf);
|
||||
#endif
|
||||
fprintf(stderr, " while parsing %s \n", fullpath);
|
||||
parse_error |= PARSE_ERROR;
|
||||
}
|
||||
@@ -98,7 +102,11 @@ void found_unsigned_integer(uint64_t result, const uint8_t *buf) {
|
||||
char *endptr;
|
||||
unsigned long long expected = strtoull((const char *)buf, &endptr, 10);
|
||||
if ((endptr == (const char *)buf) || (expected != result)) {
|
||||
#if (!(__MINGW32__) && !(__MINGW64__))
|
||||
fprintf(stderr, "Error: parsed %" PRIu64 " out of %.32s, ", result, buf);
|
||||
#else // mingw is busted since we include #include <inttypes.h>
|
||||
fprintf(stderr, "Error: parsed %llu out of %.32s, ", (unsigned long long)result, buf);
|
||||
#endif
|
||||
fprintf(stderr, " while parsing %s \n", fullpath);
|
||||
parse_error |= PARSE_ERROR;
|
||||
}
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
#include <cstring>
|
||||
#ifndef _MSC_VER
|
||||
#if (!(_MSC_VER) && !(__MINGW32__) && !(__MINGW64__))
|
||||
#include <dirent.h>
|
||||
#else
|
||||
// Microsoft can't be bothered to provide standard utils.
|
||||
|
||||
@@ -12,7 +12,7 @@
|
||||
#define JSON_TEST_STRINGS
|
||||
#endif
|
||||
|
||||
#ifndef _MSC_VER
|
||||
#if (!(_MSC_VER) && !(__MINGW32__) && !(__MINGW64__))
|
||||
#include <dirent.h>
|
||||
#else
|
||||
#include <dirent_portable.h>
|
||||
|
||||
@@ -1,5 +1,9 @@
|
||||
link_libraries(simdjson simdjson-internal-flags simdjson-windows-headers cxxopts)
|
||||
|
||||
add_executable(json2json json2json.cpp)
|
||||
add_executable(jsonstats jsonstats.cpp)
|
||||
add_executable(minify minify.cpp)
|
||||
if(TARGET cxxopts) # we only build the tools if cxxopts is available
|
||||
message(STATUS "We have cxxopts as a dependency and we are buiding the tools (e.g., json2json).")
|
||||
link_libraries(simdjson simdjson-internal-flags simdjson-windows-headers cxxopts)
|
||||
add_executable(json2json json2json.cpp)
|
||||
add_executable(jsonstats jsonstats.cpp)
|
||||
add_executable(minify minify.cpp)
|
||||
else()
|
||||
message(STATUS "We are missing cxxopts as a dependency so the tools (e.g., json2json) are omitted.")
|
||||
endif()
|
||||
+1
-1
@@ -1,5 +1,5 @@
|
||||
#include <iostream>
|
||||
#ifndef _MSC_VER
|
||||
#if (!(_MSC_VER) && !(__MINGW32__) && !(__MINGW64__))
|
||||
#include <dirent.h>
|
||||
#endif
|
||||
#include <unistd.h>
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
add_library(simdjson-windows-headers INTERFACE)
|
||||
if(MSVC)
|
||||
if(MSVC OR MINGW)
|
||||
target_include_directories(simdjson-windows-headers INTERFACE .)
|
||||
# getopt.h triggers bogus CRT_SECURE warnings. If you include them, you need this.
|
||||
target_compile_definitions(simdjson-windows-headers INTERFACE _CRT_SECURE_NO_WARNINGS)
|
||||
|
||||
@@ -1,7 +1,7 @@
|
||||
#ifndef SIMDBJSON_DIRENT_PORTABLE_INC_
|
||||
#define SIMDBJSON_DIRENT_PORTABLE_INC_
|
||||
|
||||
#if (!defined(_WIN32) && !defined(_WIN64))
|
||||
#if (!defined(_WIN32) && !defined(_WIN64) && !(__MINGW32__) && !(__MINGW64__))
|
||||
#include <dirent.h>
|
||||
#else
|
||||
#include "toni_ronnko_dirent.h"
|
||||
|
||||
+6
-2
@@ -1,4 +1,5 @@
|
||||
#ifndef __GETOPT_H__
|
||||
/** This file has been modified by D. Lemire for use in simdjson. **/
|
||||
/* From https://github.com/skandhurkat/Getopt-for-Visual-Studio/blob/master/getopt.h */
|
||||
/**
|
||||
* DISCLAIMER
|
||||
@@ -56,8 +57,9 @@
|
||||
* ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
|
||||
* POSSIBILITY OF SUCH DAMAGE.
|
||||
*/
|
||||
|
||||
#ifdef _MSC_VER
|
||||
#pragma warning(disable:4996)
|
||||
#endif
|
||||
|
||||
#define __GETOPT_H__
|
||||
|
||||
@@ -110,7 +112,9 @@ char *optarg; /* argument associated with option */
|
||||
extern char __declspec(dllimport) *__progname;
|
||||
#endif
|
||||
|
||||
#if defined(__CYGWIN__) || defined(__clang__) // D. Lemire (April 2020): adding __clang__
|
||||
// D. Lemire (April 2020): adding __clang__
|
||||
// D. Lemire (June 2020): adding __MINGW32__ and __MINGW64__
|
||||
#if defined(__CYGWIN__) || defined(__clang__) || defined(__MINGW32__) || defined(__MINGW64__)
|
||||
static char EMSG[] = "";
|
||||
#else
|
||||
#define EMSG ""
|
||||
|
||||
Reference in New Issue
Block a user