⚗️ add Hedley annotations

This commit is contained in:
Niels Lohmann 2019-06-30 22:14:02 +02:00
parent 9a775bcb14
commit 1720bfedd1
No known key found for this signature in database
GPG key ID: 7F3CEA63AE251B69
19 changed files with 3689 additions and 642 deletions

View file

@ -8,6 +8,7 @@
#include <string> // string
#include <nlohmann/detail/input/binary_reader.hpp>
#include <nlohmann/detail/macro_scope.hpp>
#include <nlohmann/detail/output/output_adapters.hpp>
namespace nlohmann
@ -714,7 +715,7 @@ class binary_writer
static std::size_t calc_bson_entry_header_size(const string_t& name)
{
const auto it = name.find(static_cast<typename string_t::value_type>(0));
if (JSON_UNLIKELY(it != BasicJsonType::string_t::npos))
if (HEDLEY_UNLIKELY(it != BasicJsonType::string_t::npos))
{
JSON_THROW(out_of_range::create(409,
"BSON key cannot contain code point U+0000 (at byte " + std::to_string(it) + ")"));

View file

@ -8,6 +8,7 @@
#include <ostream> // basic_ostream
#include <string> // basic_string
#include <vector> // vector
#include <nlohmann/detail/macro_scope.hpp>
namespace nlohmann
{
@ -39,6 +40,7 @@ class output_vector_adapter : public output_adapter_protocol<CharType>
v.push_back(c);
}
HEDLEY_NON_NULL(2)
void write_characters(const CharType* s, std::size_t length) override
{
std::copy(s, s + length, std::back_inserter(v));
@ -62,6 +64,7 @@ class output_stream_adapter : public output_adapter_protocol<CharType>
stream.put(c);
}
HEDLEY_NON_NULL(2)
void write_characters(const CharType* s, std::size_t length) override
{
stream.write(s, static_cast<std::streamsize>(length));
@ -85,6 +88,7 @@ class output_string_adapter : public output_adapter_protocol<CharType>
str.push_back(c);
}
HEDLEY_NON_NULL(2)
void write_characters(const CharType* s, std::size_t length) override
{
str.append(s, length);

View file

@ -110,7 +110,7 @@ class serializer
// variable to hold indentation for recursive calls
const auto new_indent = current_indent + indent_step;
if (JSON_UNLIKELY(indent_string.size() < new_indent))
if (HEDLEY_UNLIKELY(indent_string.size() < new_indent))
{
indent_string.resize(indent_string.size() * 2, ' ');
}
@ -183,7 +183,7 @@ class serializer
// variable to hold indentation for recursive calls
const auto new_indent = current_indent + indent_step;
if (JSON_UNLIKELY(indent_string.size() < new_indent))
if (HEDLEY_UNLIKELY(indent_string.size() < new_indent))
{
indent_string.resize(indent_string.size() * 2, ' ');
}
@ -498,7 +498,7 @@ class serializer
}
// we finished processing the string
if (JSON_LIKELY(state == UTF8_ACCEPT))
if (HEDLEY_LIKELY(state == UTF8_ACCEPT))
{
// write buffer
if (bytes > 0)