Commit 45fe624
authored
Avoid string allocation and improve performance of
* Avoid string allocation in WriteTo when possible.
System.Text.Json.JsonProperty.WriteTo uses get_Name, calling
JsonElement.GetPropertyName() which would allocate a string.
Use ReadOnlySpan<byte> from the underlying UTF8 json, when possible,
by adding helper methods into JsonDocument & JsonElement.
Fix #88767
* Avoid alloc in unescaping & escaping.
Current code unescapes & escapes property names and uses ToArray.
Avoid alloc by adding internal GetRaw/WriteRaw methods.
* Fix bugs on escaped property names
Original code doesn't handle GetRaw/WriteRaw on escaped
property names correctly.
* Change IndexOf to Contains if possible.
* Further avoid alloc by inlining GetUnescapedSpan
Allocations are further avoided when the property name is shorter than
JsonConstants.StackallocByteThreshold, by inlining
JsonReaderHelper.GetUnescapedSpan.
* Move writing logic to JsonElement;
Shorten names of new methods;
Add a test of writing out special names.
* Move logic into JsonDocument
* fix format
* fix format 2
* improve comment
* removed unused stub
* added assertion
* removed unnecessary testJsonProperty.WriteTo (#90074)1 parent d563d0e commit 45fe624
3 files changed
Lines changed: 25 additions & 1 deletion
File tree
- src/libraries/System.Text.Json/src/System/Text/Json/Document
Lines changed: 9 additions & 0 deletions
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
874 | 874 | | |
875 | 875 | | |
876 | 876 | | |
| 877 | + | |
| 878 | + | |
| 879 | + | |
| 880 | + | |
| 881 | + | |
| 882 | + | |
| 883 | + | |
| 884 | + | |
| 885 | + | |
877 | 886 | | |
878 | 887 | | |
879 | 888 | | |
| |||
Lines changed: 7 additions & 0 deletions
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
1316 | 1316 | | |
1317 | 1317 | | |
1318 | 1318 | | |
| 1319 | + | |
| 1320 | + | |
| 1321 | + | |
| 1322 | + | |
| 1323 | + | |
| 1324 | + | |
| 1325 | + | |
1319 | 1326 | | |
1320 | 1327 | | |
1321 | 1328 | | |
| |||
Lines changed: 9 additions & 1 deletion
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
117 | 117 | | |
118 | 118 | | |
119 | 119 | | |
120 | | - | |
| 120 | + | |
| 121 | + | |
| 122 | + | |
| 123 | + | |
| 124 | + | |
| 125 | + | |
| 126 | + | |
| 127 | + | |
| 128 | + | |
121 | 129 | | |
122 | 130 | | |
123 | 131 | | |
| |||
0 commit comments