Commit 36bd06b
committed
gh-150875: Speed up JSON string encoding for long ASCII strings
ascii_escape_size() scans each string one character at a time to size the
escaped output, and write_escaped_ascii() writes it verbatim when nothing
needs escaping. For the one-byte representation, detect that no-escape case
eight bytes at a time and return the verbatim size directly; a length guard
keeps short strings on the original per-character loop. Strings that need
escaping and non-Latin-1 strings keep the current path.
Output is byte-identical, verified against test_json and a 199-case dumps
differential in both ensure_ascii modes. dumps of long ASCII strings runs up
to 5.3x faster; short keys, escaped strings, and non-ASCII are unaffected.1 parent 7a468a1 commit 36bd06b
2 files changed
Lines changed: 41 additions & 0 deletions
Lines changed: 4 additions & 0 deletions
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
| 1 | + | |
| 2 | + | |
| 3 | + | |
| 4 | + | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
164 | 164 | | |
165 | 165 | | |
166 | 166 | | |
| 167 | + | |
| 168 | + | |
| 169 | + | |
| 170 | + | |
| 171 | + | |
| 172 | + | |
| 173 | + | |
| 174 | + | |
| 175 | + | |
| 176 | + | |
| 177 | + | |
| 178 | + | |
| 179 | + | |
| 180 | + | |
| 181 | + | |
| 182 | + | |
| 183 | + | |
| 184 | + | |
| 185 | + | |
| 186 | + | |
| 187 | + | |
| 188 | + | |
| 189 | + | |
| 190 | + | |
| 191 | + | |
| 192 | + | |
| 193 | + | |
| 194 | + | |
| 195 | + | |
| 196 | + | |
| 197 | + | |
| 198 | + | |
| 199 | + | |
| 200 | + | |
| 201 | + | |
| 202 | + | |
| 203 | + | |
167 | 204 | | |
168 | 205 | | |
169 | 206 | | |
| |||
0 commit comments