From e8730e5e82493d82c9dae8bd73ae6eedc9267de5 Mon Sep 17 00:00:00 2001 From: Julian Becker Date: Sat, 29 Sep 2018 11:50:01 +0200 Subject: [PATCH] BSON: Reworked `binary_reader::get_bson_cstr()` --- .../nlohmann/detail/input/binary_reader.hpp | 31 +++++++------------ single_include/nlohmann/json.hpp | 31 +++++++------------ 2 files changed, 22 insertions(+), 40 deletions(-) diff --git a/include/nlohmann/detail/input/binary_reader.hpp b/include/nlohmann/detail/input/binary_reader.hpp index d68a6091..0b718dd4 100644 --- a/include/nlohmann/detail/input/binary_reader.hpp +++ b/include/nlohmann/detail/input/binary_reader.hpp @@ -125,36 +125,27 @@ class binary_reader private: - template - OutputIt generate_until(OutputIt&& d_first, UnaryPredicate&& pred, Gen&& gen) - { - for (auto x = gen(); !pred(x); x = gen()) - { - *d_first++ = x; - } - - return d_first; - } - /*! @return whether array creation completed */ bool get_bson_cstr(string_t& result) { - bool success = true; - generate_until(std::back_inserter(result), [&success](char c) - { - return c == 0x00 || !success; - }, [this, &success] + auto out = std::back_inserter(result); + while (true) { get(); if (JSON_UNLIKELY(not unexpect_eof())) { - success = false; + return false; } - return static_cast(current); - }); - return success; + if (current == 0x00) + { + return true; + } + *out++ = static_cast(current); + } + + return true; } bool parse_bson_entries(bool is_array) diff --git a/single_include/nlohmann/json.hpp b/single_include/nlohmann/json.hpp index ac11591a..a661ecb6 100644 --- a/single_include/nlohmann/json.hpp +++ b/single_include/nlohmann/json.hpp @@ -6109,36 +6109,27 @@ class binary_reader private: - template - OutputIt generate_until(OutputIt&& d_first, UnaryPredicate&& pred, Gen&& gen) - { - for (auto x = gen(); !pred(x); x = gen()) - { - *d_first++ = x; - } - - return d_first; - } - /*! @return whether array creation completed */ bool get_bson_cstr(string_t& result) { - bool success = true; - generate_until(std::back_inserter(result), [&success](char c) - { - return c == 0x00 || !success; - }, [this, &success] + auto out = std::back_inserter(result); + while (true) { get(); if (JSON_UNLIKELY(not unexpect_eof())) { - success = false; + return false; } - return static_cast(current); - }); - return success; + if (current == 0x00) + { + return true; + } + *out++ = static_cast(current); + } + + return true; } bool parse_bson_entries(bool is_array)