Skip to content

Commit

Permalink
Don't allow mutable references to JSON strings (#1466)
Browse files Browse the repository at this point in the history
Signed-off-by: Juan Cruz Viotti <[email protected]>
  • Loading branch information
jviotti authored Jan 22, 2025
1 parent 8edb565 commit ff62a78
Show file tree
Hide file tree
Showing 2 changed files with 0 additions and 19 deletions.
14 changes: 0 additions & 14 deletions src/json/include/sourcemeta/jsontoolkit/json_value.h
Original file line number Diff line number Diff line change
Expand Up @@ -521,20 +521,6 @@ class SOURCEMETA_JSONTOOLKIT_JSON_EXPORT JSON {
/// ```
[[nodiscard]] auto to_string() const noexcept -> const String &;

/// Convert a JSON instance into a standard string value. The result of this
/// method is undefined unless the JSON instance holds a string value. For
/// example:
///
/// ```cpp
/// #include <sourcemeta/jsontoolkit/json.h>
/// #include <cassert>
///
/// const sourcemeta::jsontoolkit::JSON document{"foo"};
/// assert(document.is_string());
/// assert(document.to_string() == "foo");
/// ```
[[nodiscard]] auto to_string() noexcept -> String &;

/// Get a standard input string stream from a JSON string. The result of this
/// method is undefined unless the JSON instance holds a string value. For
/// example:
Expand Down
5 changes: 0 additions & 5 deletions src/json/json_value.cc
Original file line number Diff line number Diff line change
Expand Up @@ -411,11 +411,6 @@ auto JSON::operator-=(const JSON &substractive) -> JSON & {
return this->data_string;
}

[[nodiscard]] auto JSON::to_string() noexcept -> JSON::String & {
assert(this->is_string());
return this->data_string;
}

[[nodiscard]] auto JSON::to_stringstream() const
-> std::basic_istringstream<Char, CharTraits, Allocator<Char>> {
return std::basic_istringstream<Char, CharTraits, Allocator<Char>>{
Expand Down

4 comments on commit ff62a78

@github-actions
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Benchmark (linux/llvm)

Benchmark suite Current: ff62a78 Previous: 8edb565 Ratio
JSON_Array_Of_Objects_Unique 389.94963978404485 ns/iter 388.3287682318284 ns/iter 1.00
JSON_Parse_1 30574.820265694958 ns/iter 29710.876140530036 ns/iter 1.03
JSON_Fast_Hash_Helm_Chart_Lock 58.57731016384112 ns/iter 55.32772995687293 ns/iter 1.06
JSON_Equality_Helm_Chart_Lock 141.66681447975222 ns/iter 146.7993868995464 ns/iter 0.97
Pointer_Object_Traverse 44.896972693702104 ns/iter 44.34786906303649 ns/iter 1.01
Pointer_Object_Try_Traverse 52.2659578395388 ns/iter 52.79718821375552 ns/iter 0.99
Pointer_Push_Back_Pointer_To_Weak_Pointer 352.7108512079953 ns/iter 352.6893851135672 ns/iter 1.00

This comment was automatically generated by workflow using github-action-benchmark.

@github-actions
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Benchmark (macos/llvm)

Benchmark suite Current: ff62a78 Previous: 8edb565 Ratio
JSON_Array_Of_Objects_Unique 446.7765628276582 ns/iter 404.5879576880687 ns/iter 1.10
JSON_Parse_1 30578.26607315221 ns/iter 25963.49335634936 ns/iter 1.18
JSON_Fast_Hash_Helm_Chart_Lock 60.70435698307583 ns/iter 58.6042859128079 ns/iter 1.04
JSON_Equality_Helm_Chart_Lock 199.2468931055563 ns/iter 155.1501908304665 ns/iter 1.28
Pointer_Object_Traverse 19.623484919393064 ns/iter 17.35014937208693 ns/iter 1.13
Pointer_Object_Try_Traverse 39.73530990263023 ns/iter 34.61084697883719 ns/iter 1.15
Pointer_Push_Back_Pointer_To_Weak_Pointer 215.2297021294033 ns/iter 201.40684990832398 ns/iter 1.07

This comment was automatically generated by workflow using github-action-benchmark.

@github-actions
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Benchmark (windows/msvc)

Benchmark suite Current: ff62a78 Previous: 8edb565 Ratio
JSON_Array_Of_Objects_Unique 451.8273879033866 ns/iter 452.26704291668545 ns/iter 1.00
JSON_Parse_1 82080.6749698765 ns/iter 79807.04432838164 ns/iter 1.03
JSON_Fast_Hash_Helm_Chart_Lock 69.34878000000708 ns/iter 63.3315446428538 ns/iter 1.10
JSON_Equality_Helm_Chart_Lock 204.27636141623003 ns/iter 206.06862499999323 ns/iter 0.99
Pointer_Object_Traverse 52.87754464286008 ns/iter 53.30046000000266 ns/iter 0.99
Pointer_Object_Try_Traverse 68.68697544642238 ns/iter 69.58261607143714 ns/iter 0.99
Pointer_Push_Back_Pointer_To_Weak_Pointer 187.49875781237705 ns/iter 183.22563243085665 ns/iter 1.02

This comment was automatically generated by workflow using github-action-benchmark.

@github-actions
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Benchmark (linux/gcc)

Benchmark suite Current: ff62a78 Previous: 8edb565 Ratio
Pointer_Object_Traverse 43.91532179708142 ns/iter 44.166187980592 ns/iter 0.99
Pointer_Object_Try_Traverse 22.099703708561712 ns/iter 22.07160036172714 ns/iter 1.00
Pointer_Push_Back_Pointer_To_Weak_Pointer 215.10525538705298 ns/iter 215.02989448112777 ns/iter 1.00
JSON_Array_Of_Objects_Unique 406.7870231312499 ns/iter 408.6653780302691 ns/iter 1.00
JSON_Parse_1 32418.949986030155 ns/iter 32712.209816236962 ns/iter 0.99
JSON_Fast_Hash_Helm_Chart_Lock 70.45223746212632 ns/iter 70.41757738204709 ns/iter 1.00
JSON_Equality_Helm_Chart_Lock 148.78966179411927 ns/iter 140.1503755859335 ns/iter 1.06

This comment was automatically generated by workflow using github-action-benchmark.

Please sign in to comment.