summaryrefslogtreecommitdiffstats
path: root/compiler/rustc_data_structures/src/small_str.rs
diff options
context:
space:
mode:
authorDaniel Baumann <daniel.baumann@progress-linux.org>2024-05-30 03:57:31 +0000
committerDaniel Baumann <daniel.baumann@progress-linux.org>2024-05-30 03:57:31 +0000
commitdc0db358abe19481e475e10c32149b53370f1a1c (patch)
treeab8ce99c4b255ce46f99ef402c27916055b899ee /compiler/rustc_data_structures/src/small_str.rs
parentReleasing progress-linux version 1.71.1+dfsg1-2~progress7.99u1. (diff)
downloadrustc-dc0db358abe19481e475e10c32149b53370f1a1c.tar.xz
rustc-dc0db358abe19481e475e10c32149b53370f1a1c.zip
Merging upstream version 1.72.1+dfsg1.
Signed-off-by: Daniel Baumann <daniel.baumann@progress-linux.org>
Diffstat (limited to 'compiler/rustc_data_structures/src/small_str.rs')
-rw-r--r--compiler/rustc_data_structures/src/small_str.rs68
1 files changed, 0 insertions, 68 deletions
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 800acb1b0..000000000
--- 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());
- }
- }
-}