rust/library/std/src/sys_common
bors 1b225414f3 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.
2022-10-09 15:07:10 +00:00
..
condvar make Condvar, Mutex, RwLock const constructors work with unsupported impl 2022-06-27 12:37:06 +02:00
memchr Move std::memchr to sys_common 2021-05-14 03:54:46 +02:00
net Use implicit capture syntax in format_args 2022-03-10 10:23:40 -05:00
once std: use futex in Once 2022-10-07 12:12:36 +02:00
remutex std: make ReentrantMutex movable and const; simplify Stdout initialization 2022-09-03 14:05:28 +02:00
thread_local_key avoid some int2ptr casts in thread_local_key tests 2022-08-11 09:39:25 -04:00
thread_parker std: use futex-based locks and thread parker on Hermit 2022-09-09 11:56:50 +02:00
wtf8 Remove is_known_utf8 checks from more tests where it's no longer set. 2022-06-23 13:10:47 -07:00
backtrace.rs Use implicit capture syntax in format_args 2022-03-10 10:23:40 -05:00
condvar.rs make Condvar, Mutex, RwLock const constructors work with unsupported impl 2022-06-27 12:37:06 +02:00
fs.rs Hide Repr details from io::Error, and rework io::Error::new_const. 2022-02-04 18:47:29 -08:00
io.rs Avoid double panics when using TempDir in tests 2022-01-25 10:36:10 +00:00
lazy_box.rs Leak pthreax_mutex_t when it's dropped while locked. 2022-06-16 12:09:12 +02:00
memchr.rs Move std::memchr to sys_common 2021-05-14 03:54:46 +02:00
mod.rs std: use futex in Once 2022-10-07 12:12:36 +02:00
mutex.rs make Condvar, Mutex, RwLock const constructors work with unsupported impl 2022-06-27 12:37:06 +02:00
net.rs Reduce CString allocations in std as much as possible 2022-10-03 11:13:17 -07:00
process.rs Remove CommandEnv::apply 2021-12-29 10:07:44 +01:00
remutex.rs std: make ReentrantMutex movable and const; simplify Stdout initialization 2022-09-03 14:05:28 +02:00
rwlock.rs Auto merge of #98457 - japaric:gh98378, r=m-ou-se 2022-09-25 04:12:30 +00:00
tests.rs std: move "mod tests/benches" to separate files 2020-08-31 02:56:59 +00:00
thread.rs Relax memory ordering used in min_stack 2022-05-01 15:55:54 -07:00
thread_info.rs Merge two THREAD_INFO.with and following RefCell borrow 2021-09-16 15:24:53 +02:00
thread_local_dtor.rs Remove "sys isn't exported yet" phrase 2022-05-30 12:07:43 +02:00
thread_local_key.rs update and extend some comments, and cfg-out some unused code 2022-08-22 09:14:33 -04:00
wtf8.rs Auto merge of #96869 - sunfishcode:main, r=joshtriplett 2022-08-24 01:17:52 +00:00