You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Copy file name to clipboardExpand all lines: cpp.md
+5-31Lines changed: 5 additions & 31 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -342,7 +342,7 @@ This section outlines common patterns that cause unnecessary JSON copying in C++
342
342
343
343
### 1. Use References for Read-Only Operations
344
344
345
-
When declaring a `JSON::Value` as `const`, it cannot be modified, so we should always use references to avoid unnecessary copies.
345
+
When declaring a `JSON::Value` as `const`, it cannot be modified, so we should always use references to avoid unnecessary copies when iterating or passing it into a function.
346
346
347
347
#### Examples
348
348
@@ -396,33 +396,7 @@ These cases are easy to spot when declaring variables as `const` because the con
### 2. Avoid Initializer List Constructor for Large Objects
400
-
401
-
The `JSON::Value(initializer_list)` constructor always creates copies due to a limitation in C++ when using `initializer_list`, which inherently involves copying. This is not an issue specific to the `JSON::Value` implementation. For large objects (transactions, reportActions, reports, personalDetails, participants, etc.), use assignment with `move()` instead to avoid unnecessary copies.
When data is no longer needed after an operation, use `move()` to transfer ownership and avoid copies. Combine with `JSON::Value` helper functions for cleaner code.
0 commit comments