diff options
| author | Josh Stone <jistone@redhat.com> | 2019-02-13 13:46:45 -0800 |
|---|---|---|
| committer | Josh Stone <jistone@redhat.com> | 2019-02-13 13:46:45 -0800 |
| commit | 70c5af85e09be583128df5eda6b4de25a23387c1 (patch) | |
| tree | d8bc8228e9f2fdf3b90f18d071bf99ab888065e3 /src/libstd/sys | |
| parent | e54494727855cd14229f5d456591ed2a2f027c46 (diff) | |
| download | rust-70c5af85e09be583128df5eda6b4de25a23387c1.tar.gz rust-70c5af85e09be583128df5eda6b4de25a23387c1.zip | |
Avoid allocation in std::sys::unix::weak
If we add a terminating NUL to the name in the `weak!` macro, then `fetch()` can use `CStr::from_bytes_with_nul()` instead of `CString`.
Diffstat (limited to 'src/libstd/sys')
| -rw-r--r-- | src/libstd/sys/unix/weak.rs | 6 |
1 files changed, 3 insertions, 3 deletions
diff --git a/src/libstd/sys/unix/weak.rs b/src/libstd/sys/unix/weak.rs index d0242ca7422..9b80ad8d9b2 100644 --- a/src/libstd/sys/unix/weak.rs +++ b/src/libstd/sys/unix/weak.rs @@ -18,7 +18,7 @@ use libc; -use ffi::CString; +use ffi::CStr; use marker; use mem; use sync::atomic::{AtomicUsize, Ordering}; @@ -26,7 +26,7 @@ use sync::atomic::{AtomicUsize, Ordering}; macro_rules! weak { (fn $name:ident($($t:ty),*) -> $ret:ty) => ( static $name: ::sys::weak::Weak<unsafe extern fn($($t),*) -> $ret> = - ::sys::weak::Weak::new(stringify!($name)); + ::sys::weak::Weak::new(concat!(stringify!($name), '\0')); ) } @@ -61,7 +61,7 @@ impl<F> Weak<F> { } unsafe fn fetch(name: &str) -> usize { - let name = match CString::new(name) { + let name = match CStr::from_bytes_with_nul(name.as_bytes()) { Ok(cstr) => cstr, Err(..) => return 0, }; |
