diff options
| author | Ryan Liptak <squeek502@hotmail.com> | 2024-07-12 00:38:10 -0700 |
|---|---|---|
| committer | Andrew Kelley <andrew@ziglang.org> | 2024-07-13 14:48:17 -0700 |
| commit | 959d227d1370c9cf9198ed111e3a8bca15a7e47b (patch) | |
| tree | 4141025bd114fa54fedf1e76adf19202561bc018 /lib/std/Thread | |
| parent | 11534aa34d6e9c66081eb2918bfaacbb21db0e56 (diff) | |
| download | zig-959d227d1370c9cf9198ed111e3a8bca15a7e47b.tar.gz zig-959d227d1370c9cf9198ed111e3a8bca15a7e47b.zip | |
ArgIteratorWindows: Reduce allocated memory by parsing the WTF-16 string directly
Before this commit, the WTF-16 command line string would be converted to WTF-8 in `init`, and then a second buffer of the WTF-8 size + 1 would be allocated to store the parsed arguments. The converted WTF-8 command line would then be parsed and the relevant bytes would be copied into the argument buffer before being returned.
After this commit, only the WTF-8 size of the WTF-16 string is calculated (without conversion) which is then used to allocate the buffer for the parsed arguments. Parsing is then done on the WTF-16 slice directly, with the arguments being converted to WTF-8 on-the-fly.
This has a few (minor) benefits:
- Cuts the amount of memory allocated by ArgIteratorWindows in half (or better)
- Makes the total amount of memory allocated by ArgIteratorWindows predictable, since, before, the upfront `wtf16LeToWtf8Alloc` call could end up allocating more-memory-than-necessary temporarily due to its internal use of an ArrayList. Now, the amount of memory allocated is always exactly `calcWtf8Len(cmd_line) + 1`.
Diffstat (limited to 'lib/std/Thread')
0 files changed, 0 insertions, 0 deletions
