minor tweak

This commit is contained in:
Daniel Lemire
2025-09-05 08:01:04 -04:00
parent e2ea5fb8de
commit 7f68baec1e
4 changed files with 19 additions and 4 deletions
+1 -1
View File
@@ -3114,7 +3114,7 @@ Performance tips
simdjson::ondemand::document doc = parser.iterate(json);
for(auto keyvalue : doc.get_object()) {
std::string_view key = keyvalue.escaped_key();
simdjson::ondemand::raw_json_string key = keyvalue.key();
switch(key[0]) {
case 'p': // price
if (key == "price") {
@@ -15,8 +15,13 @@ namespace ondemand {
simdjson_inline raw_json_string::raw_json_string(const uint8_t * _buf) noexcept : buf{_buf} {}
simdjson_inline const char * raw_json_string::raw() const noexcept { return reinterpret_cast<const char *>(buf); }
simdjson_inline const char * raw_json_string::raw() const noexcept {
return reinterpret_cast<const char *>(buf);
}
simdjson_inline char raw_json_string::operator[](size_t i) const noexcept {
return reinterpret_cast<const char *>(buf)[i];
}
simdjson_inline bool raw_json_string::is_free_from_unescaped_quote(std::string_view target) noexcept {
size_t pos{0};
@@ -193,6 +198,10 @@ simdjson_inline simdjson_result<const char *> simdjson_result<SIMDJSON_IMPLEMENT
if (error()) { return error(); }
return first.raw();
}
simdjson_inline char simdjson_result<SIMDJSON_IMPLEMENTATION::ondemand::raw_json_string>::operator[](size_t i) const noexcept {
if (error()) { return error(); }
return first[i];
}
simdjson_inline simdjson_warn_unused simdjson_result<std::string_view> simdjson_result<SIMDJSON_IMPLEMENTATION::ondemand::raw_json_string>::unescape(SIMDJSON_IMPLEMENTATION::ondemand::json_iterator &iter, bool allow_replacement) const noexcept {
if (error()) { return error(); }
return first.unescape(iter, allow_replacement);
@@ -58,6 +58,12 @@ public:
*/
simdjson_inline const char * raw() const noexcept;
/**
* Get the character at index i. This is unchecked.
* [0] when the string is of length 0 returns the final quote (").
*/
simdjson_inline char operator[](size_t i) const noexcept;
/**
* This compares the current instance to the std::string_view target: returns true if
* they are byte-by-byte equal (no escaping is done) on target.size() characters,
@@ -197,10 +203,10 @@ public:
simdjson_inline ~simdjson_result() noexcept = default; ///< @private
simdjson_inline simdjson_result<const char *> raw() const noexcept;
simdjson_inline char operator[](size_t) const noexcept;
simdjson_inline simdjson_warn_unused simdjson_result<std::string_view> unescape(SIMDJSON_IMPLEMENTATION::ondemand::json_iterator &iter, bool allow_replacement) const noexcept;
simdjson_inline simdjson_warn_unused simdjson_result<std::string_view> unescape_wobbly(SIMDJSON_IMPLEMENTATION::ondemand::json_iterator &iter) const noexcept;
};
} // namespace simdjson
#endif // SIMDJSON_GENERIC_ONDEMAND_RAW_JSON_STRING_H
+1 -1
View File
@@ -1451,7 +1451,7 @@ bool simple_error_example() {
simdjson::ondemand::document doc = parser.iterate(json);
for(auto keyvalue : doc.get_object()) {
std::string_view key = keyvalue.escaped_key();
simdjson::ondemand::raw_json_string key = keyvalue.key();
switch(key[0]) {
case 'p': // price
if (key == "price") {