diff options
| author | bors <bors@rust-lang.org> | 2022-10-09 15:07:10 +0000 |
|---|---|---|
| committer | bors <bors@rust-lang.org> | 2022-10-09 15:07:10 +0000 |
| commit | 1b225414f325593f974c6b41e671a0a0dc5d7d5e (patch) | |
| tree | 679e5d7d035d1f7ccc21ce222e92d4ffd47b0caf /compiler/rustc_hir_analysis/src/structured_errors.rs | |
| parent | 79a664d8b00505a76b53cfe017b9c80bcee7e080 (diff) | |
| parent | 86974b83af48ee9e196da42730ec96ad646009c4 (diff) | |
| download | rust-1b225414f325593f974c6b41e671a0a0dc5d7d5e.tar.gz rust-1b225414f325593f974c6b41e671a0a0dc5d7d5e.zip | |
Auto merge of #93668 - SUPERCILEX:path_alloc, r=joshtriplett
Reduce CString allocations in std as much as possible Currently, every operation involving paths in `fs` allocates memory to hold the path before sending it through the syscall. This PR instead uses a stack allocation (chosen size is somewhat arbitrary) when the path is short before falling back to heap allocations for long paths. Benchmarks show that the stack allocation is ~2x faster for short paths: ``` test sys::unix::fd::tests::bench_heap_path_alloc ... bench: 34 ns/iter (+/- 2) test sys::unix::fd::tests::bench_stack_path_alloc ... bench: 15 ns/iter (+/- 1) ``` For long paths, I couldn't find any measurable difference. --- I'd be surprised if I was the first to think of this, so I didn't fully flush out the PR. If this change is desirable, I'll make use of `run_with_cstr` across all platforms in every fs method (currently just unix open for testing). I also added an `impl From<FromBytesWithNulError>` which is presumably a no-no (or at least needs to be done in another PR). --- Also see https://github.com/nix-rust/nix/pull/1655 with a bunch of discussion where I'm doing something similar.
Diffstat (limited to 'compiler/rustc_hir_analysis/src/structured_errors.rs')
0 files changed, 0 insertions, 0 deletions
