mirror of
https://github.com/nlohmann/json.git
synced 2026-09-30 14:05:18 +00:00
dump() writes doubles with the conversion of Zmij by Victor Zverovich (https://github.com/vitaut/zmij, MIT), ported to C++11 in detail/conversions/zmij.hpp: the shortest decimal in the rounding interval, the closest one if there are several. Grisu2 does not always find the shortest digits; about 0.14% of random doubles are now written differently (0.08% with fewer digits, 0.06% with the closest last digit); short decimals such as 0.1 or 2555.56 are not affected. float keeps Grisu2. The layout of doubles is unchanged, but written differently: the digits are converted eight at a time (the BCD conversion of Xiang JunBo, as in Zmij) and stored with one byte swap per eight digits; leading and trailing zeros are counted from those bytes; and the layouts of format_buffer() are written with fixed-size moves instead of per-digit loops and moves of the buffer (to_chars() uses a local buffer if the caller's is shorter than the 41 bytes this may write). The powers of ten come from the table for number parsing, adjusted where it holds them rounded up, and from the compressed tables of Zmij beyond 10^308. json::dump() gets faster on floats: canada -53%, numbers -46%, mesh -37%, marine_ik -30%. Tests: the powers of ten recomputed with a small big-integer; for random doubles, all powers of two and of ten and their neighbors, and boundary values: the output reads back as the same value, no decimal with one digit fewer does, the layout equals that of format_buffer() for the same digits, and (C++17) the digits equal those of std::to_chars. The size ratios of canada.json in unit-binary_formats.cpp and one expectation in unit-to_chars.cpp change with the shorter output. Signed-off-by: Niels Lohmann <mail@nlohmann.me>
112 lines
4.8 KiB
Python
112 lines
4.8 KiB
Python
load("@rules_cc//cc:cc_library.bzl", "cc_library")
|
|
load("@rules_license//rules:license.bzl", "license")
|
|
|
|
package(
|
|
default_applicable_licenses = [":license"],
|
|
)
|
|
|
|
exports_files([
|
|
"LICENSE.MIT",
|
|
])
|
|
|
|
license(
|
|
name = "license",
|
|
license_kinds = ["@rules_license//licenses/spdx:MIT"],
|
|
license_text = "LICENSE.MIT",
|
|
)
|
|
|
|
cc_library(
|
|
name = "json",
|
|
hdrs = [
|
|
"include/nlohmann/adl_serializer.hpp",
|
|
"include/nlohmann/byte_container_with_subtype.hpp",
|
|
"include/nlohmann/detail/abi_config.hpp",
|
|
"include/nlohmann/detail/abi_macros.hpp",
|
|
"include/nlohmann/detail/bit_ops.hpp",
|
|
"include/nlohmann/detail/conversions/from_json.hpp",
|
|
"include/nlohmann/detail/conversions/to_chars.hpp",
|
|
"include/nlohmann/detail/conversions/to_json.hpp",
|
|
"include/nlohmann/detail/conversions/zmij.hpp",
|
|
"include/nlohmann/detail/exceptions.hpp",
|
|
"include/nlohmann/detail/hash.hpp",
|
|
"include/nlohmann/detail/input/binary_reader.hpp",
|
|
"include/nlohmann/detail/input/input_adapters.hpp",
|
|
"include/nlohmann/detail/input/json_sax.hpp",
|
|
"include/nlohmann/detail/input/lexer.hpp",
|
|
"include/nlohmann/detail/input/number_parse.hpp",
|
|
"include/nlohmann/detail/input/parser.hpp",
|
|
"include/nlohmann/detail/input/position_t.hpp",
|
|
"include/nlohmann/detail/input/pow5_table.hpp",
|
|
"include/nlohmann/detail/input/string_scan.hpp",
|
|
"include/nlohmann/detail/iterators/internal_iterator.hpp",
|
|
"include/nlohmann/detail/iterators/iter_impl.hpp",
|
|
"include/nlohmann/detail/iterators/iteration_proxy.hpp",
|
|
"include/nlohmann/detail/iterators/iterator_traits.hpp",
|
|
"include/nlohmann/detail/iterators/json_reverse_iterator.hpp",
|
|
"include/nlohmann/detail/iterators/primitive_iterator.hpp",
|
|
"include/nlohmann/detail/json_custom_base_class.hpp",
|
|
"include/nlohmann/detail/json_pointer.hpp",
|
|
"include/nlohmann/detail/json_ref.hpp",
|
|
"include/nlohmann/detail/macro_scope.hpp",
|
|
"include/nlohmann/detail/macro_unscope.hpp",
|
|
"include/nlohmann/detail/meta/call_std/begin.hpp",
|
|
"include/nlohmann/detail/meta/call_std/end.hpp",
|
|
"include/nlohmann/detail/meta/cpp_future.hpp",
|
|
"include/nlohmann/detail/meta/detected.hpp",
|
|
"include/nlohmann/detail/meta/identity_tag.hpp",
|
|
"include/nlohmann/detail/meta/is_sax.hpp",
|
|
"include/nlohmann/detail/meta/logic.hpp",
|
|
"include/nlohmann/detail/meta/std_fs.hpp",
|
|
"include/nlohmann/detail/meta/type_traits.hpp",
|
|
"include/nlohmann/detail/meta/void_t.hpp",
|
|
"include/nlohmann/detail/output/binary_writer.hpp",
|
|
"include/nlohmann/detail/output/output_adapters.hpp",
|
|
"include/nlohmann/detail/output/serializer.hpp",
|
|
"include/nlohmann/detail/recursion_depth_limit.hpp",
|
|
"include/nlohmann/detail/string_concat.hpp",
|
|
"include/nlohmann/detail/string_escape.hpp",
|
|
"include/nlohmann/detail/string_utils.hpp",
|
|
"include/nlohmann/detail/value_t.hpp",
|
|
"include/nlohmann/detail/view/builder.hpp",
|
|
"include/nlohmann/detail/view/compare.hpp",
|
|
"include/nlohmann/detail/view/document_data.hpp",
|
|
"include/nlohmann/detail/view/edit.hpp",
|
|
"include/nlohmann/detail/view/edit_storage.hpp",
|
|
"include/nlohmann/detail/view/errors.hpp",
|
|
"include/nlohmann/detail/view/image.hpp",
|
|
"include/nlohmann/detail/view/input.hpp",
|
|
"include/nlohmann/detail/view/iterator.hpp",
|
|
"include/nlohmann/detail/view/lookup.hpp",
|
|
"include/nlohmann/detail/view/macro_scope.hpp",
|
|
"include/nlohmann/detail/view/macro_unscope.hpp",
|
|
"include/nlohmann/detail/view/materialize.hpp",
|
|
"include/nlohmann/detail/view/node.hpp",
|
|
"include/nlohmann/detail/view/number.hpp",
|
|
"include/nlohmann/detail/view/object_index.hpp",
|
|
"include/nlohmann/detail/view/pointer.hpp",
|
|
"include/nlohmann/detail/view/scan.hpp",
|
|
"include/nlohmann/detail/view/serializer.hpp",
|
|
"include/nlohmann/detail/view/simd.hpp",
|
|
"include/nlohmann/detail/view/string_ref.hpp",
|
|
"include/nlohmann/detail/view/value.hpp",
|
|
"include/nlohmann/json.hpp",
|
|
"include/nlohmann/json_fwd.hpp",
|
|
"include/nlohmann/json_view.hpp",
|
|
"include/nlohmann/ordered_map.hpp",
|
|
"include/nlohmann/thirdparty/hedley/hedley.hpp",
|
|
"include/nlohmann/thirdparty/hedley/hedley_undef.hpp",
|
|
],
|
|
includes = ["include"],
|
|
visibility = ["//visibility:public"],
|
|
)
|
|
|
|
cc_library(
|
|
name = "singleheader-json",
|
|
hdrs = [
|
|
"single_include/nlohmann/json.hpp",
|
|
"single_include/nlohmann/json_view.hpp",
|
|
],
|
|
includes = ["single_include"],
|
|
visibility = ["//visibility:public"],
|
|
)
|