diff options
| author | bors <bors@rust-lang.org> | 2023-06-30 00:35:19 +0000 |
|---|---|---|
| committer | bors <bors@rust-lang.org> | 2023-06-30 00:35:19 +0000 |
| commit | 8aed93d912ec23819c08e9a89ca1fb461b3cd2e6 (patch) | |
| tree | cf08613768e315951133c7494e2487cebd22c598 /compiler/rustc_data_structures/src | |
| parent | 330727467b8fdf2c43b95095a0efae7012c4f83b (diff) | |
| parent | 7e786e81b00cf48a664084d30d4f82f408825397 (diff) | |
| download | rust-8aed93d912ec23819c08e9a89ca1fb461b3cd2e6.tar.gz rust-8aed93d912ec23819c08e9a89ca1fb461b3cd2e6.zip | |
Auto merge of #113116 - nnethercote:codegen-opts, r=oli-obk
A mish-mash of micro-optimizations These were aimed at speeding up LLVM codegen, but ended up affecting other places as well. r? `@bjorn3`
Diffstat (limited to 'compiler/rustc_data_structures/src')
| -rw-r--r-- | compiler/rustc_data_structures/src/lib.rs | 1 | ||||
| -rw-r--r-- | compiler/rustc_data_structures/src/small_str.rs | 68 | ||||
| -rw-r--r-- | compiler/rustc_data_structures/src/small_str/tests.rs | 20 |
3 files changed, 0 insertions, 89 deletions
diff --git a/compiler/rustc_data_structures/src/lib.rs b/compiler/rustc_data_structures/src/lib.rs index 859e384d8b5..3deb9c5c2f5 100644 --- a/compiler/rustc_data_structures/src/lib.rs +++ b/compiler/rustc_data_structures/src/lib.rs @@ -68,7 +68,6 @@ pub mod macros; pub mod obligation_forest; pub mod sip128; pub mod small_c_str; -pub mod small_str; pub mod snapshot_map; pub mod svh; pub use ena::snapshot_vec; diff --git a/compiler/rustc_data_structures/src/small_str.rs b/compiler/rustc_data_structures/src/small_str.rs deleted file mode 100644 index 800acb1b03e..00000000000 --- a/compiler/rustc_data_structures/src/small_str.rs +++ /dev/null @@ -1,68 +0,0 @@ -use smallvec::SmallVec; - -#[cfg(test)] -mod tests; - -/// Like SmallVec but for strings. -#[derive(Default)] -pub struct SmallStr<const N: usize>(SmallVec<[u8; N]>); - -impl<const N: usize> SmallStr<N> { - #[inline] - pub fn new() -> Self { - SmallStr(SmallVec::default()) - } - - #[inline] - pub fn push_str(&mut self, s: &str) { - self.0.extend_from_slice(s.as_bytes()); - } - - #[inline] - pub fn empty(&self) -> bool { - self.0.is_empty() - } - - #[inline] - pub fn spilled(&self) -> bool { - self.0.spilled() - } - - #[inline] - pub fn as_str(&self) -> &str { - unsafe { std::str::from_utf8_unchecked(self.0.as_slice()) } - } -} - -impl<const N: usize> std::ops::Deref for SmallStr<N> { - type Target = str; - - #[inline] - fn deref(&self) -> &str { - self.as_str() - } -} - -impl<const N: usize, A: AsRef<str>> FromIterator<A> for SmallStr<N> { - #[inline] - fn from_iter<T>(iter: T) -> Self - where - T: IntoIterator<Item = A>, - { - let mut s = SmallStr::default(); - s.extend(iter); - s - } -} - -impl<const N: usize, A: AsRef<str>> Extend<A> for SmallStr<N> { - #[inline] - fn extend<T>(&mut self, iter: T) - where - T: IntoIterator<Item = A>, - { - for a in iter.into_iter() { - self.push_str(a.as_ref()); - } - } -} diff --git a/compiler/rustc_data_structures/src/small_str/tests.rs b/compiler/rustc_data_structures/src/small_str/tests.rs deleted file mode 100644 index 7635a9b7204..00000000000 --- a/compiler/rustc_data_structures/src/small_str/tests.rs +++ /dev/null @@ -1,20 +0,0 @@ -use super::*; - -#[test] -fn empty() { - let s = SmallStr::<1>::new(); - assert!(s.empty()); - assert_eq!("", s.as_str()); - assert!(!s.spilled()); -} - -#[test] -fn from_iter() { - let s = ["aa", "bb", "cc"].iter().collect::<SmallStr<6>>(); - assert_eq!("aabbcc", s.as_str()); - assert!(!s.spilled()); - - let s = ["aa", "bb", "cc", "dd"].iter().collect::<SmallStr<6>>(); - assert_eq!("aabbccdd", s.as_str()); - assert!(s.spilled()); -} |
