summaryrefslogtreecommitdiffstats
path: root/vendor/smol_str
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 /vendor/smol_str
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 'vendor/smol_str')
-rw-r--r--vendor/smol_str/.cargo-checksum.json2
-rw-r--r--vendor/smol_str/Cargo.toml5
-rw-r--r--vendor/smol_str/README.md6
-rw-r--r--vendor/smol_str/src/lib.rs118
-rw-r--r--vendor/smol_str/tests/test.rs12
5 files changed, 112 insertions, 31 deletions
diff --git a/vendor/smol_str/.cargo-checksum.json b/vendor/smol_str/.cargo-checksum.json
index d0213a158..690237f12 100644
--- a/vendor/smol_str/.cargo-checksum.json
+++ b/vendor/smol_str/.cargo-checksum.json
@@ -1 +1 @@
-{"files":{"Cargo.toml":"33e40e50c6c2e4855e7a321f359d06f1266d31790f58a1ae12e0e878bd868d4e","LICENSE-APACHE":"a60eea817514531668d7e00765731449fe14d059d3249e0bc93b36de45f759f2","LICENSE-MIT":"23f18e03dc49df91622fe2a76176497404e46ced8a715d9d2b67a7446571cca3","README.md":"e5639a2c2983f5d6f4fc016169384e11acdb8c7dcbde08046f420ddc347af637","bors.toml":"ebd69f714a49dceb8fd10ebadfea6e2767be4732fdef49eddf6239151b4bc78c","src/lib.rs":"bff7635d19d91a5dc76daa69210d4c7316dd781e871e3d1b23b70c8e186e14b2","tests/test.rs":"3205def7ca476610d598284f72e97b75dfb6fe0f9b2ae3df2f0aa631b17caec5","tests/tidy.rs":"15f655d7022a23cea887c6ac52727811f72c7d6a0fd54cdbb0476521ab4fea7f"},"package":"7475118a28b7e3a2e157ce0131ba8c5526ea96e90ee601d9f6bb2e286a35ab44"} \ No newline at end of file
+{"files":{"Cargo.toml":"fdf0a8fe2288b0b20cbcb757aa86feb4f947fbffe61a38d2b128a4c3633d5349","LICENSE-APACHE":"a60eea817514531668d7e00765731449fe14d059d3249e0bc93b36de45f759f2","LICENSE-MIT":"23f18e03dc49df91622fe2a76176497404e46ced8a715d9d2b67a7446571cca3","README.md":"6de20b6b4bfe2f1c09e4a5e2559d3c6b6851552867c9982a4d487bb8f1a38949","bors.toml":"ebd69f714a49dceb8fd10ebadfea6e2767be4732fdef49eddf6239151b4bc78c","src/lib.rs":"0ac53b230f6c5c341b594de5065ab7fa8d8601b2cf07f46f78dd591f917091da","tests/test.rs":"311fd054a031066323ae176614625b7985c5c68fd1f604ab49b143786e6bf915","tests/tidy.rs":"15f655d7022a23cea887c6ac52727811f72c7d6a0fd54cdbb0476521ab4fea7f"},"package":"74212e6bbe9a4352329b2f68ba3130c15a3f26fe88ff22dbdc6cdd58fa85e99c"} \ No newline at end of file
diff --git a/vendor/smol_str/Cargo.toml b/vendor/smol_str/Cargo.toml
index a74496f98..d987a1526 100644
--- a/vendor/smol_str/Cargo.toml
+++ b/vendor/smol_str/Cargo.toml
@@ -12,9 +12,10 @@
[package]
edition = "2018"
name = "smol_str"
-version = "0.1.23"
+version = "0.2.0"
authors = ["Aleksey Kladov <aleksey.kladov@gmail.com>"]
description = "small-string optimized string type with O(1) clone"
+readme = "README.md"
license = "MIT OR Apache-2.0"
repository = "https://github.com/rust-analyzer/smol_str"
@@ -39,4 +40,4 @@ version = "1.0.79"
[features]
default = ["std"]
-std = ["serde/std"]
+std = ["serde?/std"]
diff --git a/vendor/smol_str/README.md b/vendor/smol_str/README.md
index 2e61b9ee4..5e3506846 100644
--- a/vendor/smol_str/README.md
+++ b/vendor/smol_str/README.md
@@ -7,11 +7,11 @@
A `SmolStr` is a string type that has the following properties:
-* `size_of::<SmolStr>() == size_of::<String>()`
+* `size_of::<SmolStr>() == 24 (therefore == size_of::<String>() on 64 bit platforms)
* `Clone` is `O(1)`
* Strings are stack-allocated if they are:
- * Up to 22 bytes long
- * Longer than 22 bytes, but substrings of `WS` (see `src/lib.rs`). Such strings consist
+ * Up to 23 bytes long
+ * Longer than 23 bytes, but substrings of `WS` (see `src/lib.rs`). Such strings consist
solely of consecutive newlines, followed by consecutive spaces
* If a string does not satisfy the aforementioned conditions, it is heap-allocated
diff --git a/vendor/smol_str/src/lib.rs b/vendor/smol_str/src/lib.rs
index 8c92e51e1..91dc6252c 100644
--- a/vendor/smol_str/src/lib.rs
+++ b/vendor/smol_str/src/lib.rs
@@ -2,6 +2,8 @@
extern crate alloc;
use alloc::{
+ borrow::Cow,
+ boxed::Box,
string::{String, ToString},
sync::Arc,
};
@@ -10,17 +12,18 @@ use core::{
cmp::{self, Ordering},
convert::Infallible,
fmt, hash, iter,
+ mem::transmute,
ops::Deref,
str::FromStr,
};
/// A `SmolStr` is a string type that has the following properties:
///
-/// * `size_of::<SmolStr>() == size_of::<String>()`
+/// * `size_of::<SmolStr>() == 24 (therefor == size_of::<String>() on 64 bit platforms)
/// * `Clone` is `O(1)`
/// * Strings are stack-allocated if they are:
-/// * Up to 22 bytes long
-/// * Longer than 22 bytes, but substrings of `WS` (see below). Such strings consist
+/// * Up to 23 bytes long
+/// * Longer than 23 bytes, but substrings of `WS` (see below). Such strings consist
/// solely of consecutive newlines, followed by consecutive spaces
/// * If a string does not satisfy the aforementioned conditions, it is heap-allocated
///
@@ -51,16 +54,16 @@ impl SmolStr {
buf[$idx] = byte
});
}
- s!(0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20, 21);
+ s!(0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20, 21, 22);
SmolStr(Repr::Inline {
- len: len as u8,
+ len: unsafe { transmute(len as u8) },
buf,
})
}
/// Constructs inline variant of `SmolStr`.
///
- /// Panics if `text.len() > 22`.
+ /// Panics if `text.len() > 23`.
#[inline]
pub const fn new_inline(text: &str) -> SmolStr {
let mut buf = [0; INLINE_CAP];
@@ -70,7 +73,7 @@ impl SmolStr {
i += 1
}
SmolStr(Repr::Inline {
- len: text.len() as u8,
+ len: unsafe { transmute(text.len() as u8) },
buf,
})
}
@@ -132,7 +135,7 @@ impl SmolStr {
len += size;
}
SmolStr(Repr::Inline {
- len: len as u8,
+ len: unsafe { transmute(len as u8) },
buf,
})
}
@@ -266,7 +269,7 @@ where
len += size;
}
SmolStr(Repr::Inline {
- len: len as u8,
+ len: unsafe { transmute(len as u8) },
buf,
})
}
@@ -289,22 +292,64 @@ impl<'a> iter::FromIterator<&'a str> for SmolStr {
}
}
-impl<T> From<T> for SmolStr
-where
- T: AsRef<str>,
-{
- fn from(text: T) -> Self {
+impl AsRef<str> for SmolStr {
+ #[inline(always)]
+ fn as_ref(&self) -> &str {
+ self.as_str()
+ }
+}
+
+impl From<&str> for SmolStr {
+ #[inline]
+ fn from(s: &str) -> SmolStr {
+ SmolStr::new(s)
+ }
+}
+
+impl From<&mut str> for SmolStr {
+ #[inline]
+ fn from(s: &mut str) -> SmolStr {
+ SmolStr::new(s)
+ }
+}
+
+impl From<&String> for SmolStr {
+ #[inline]
+ fn from(s: &String) -> SmolStr {
+ SmolStr::new(s)
+ }
+}
+
+impl From<String> for SmolStr {
+ #[inline(always)]
+ fn from(text: String) -> Self {
Self::new(text)
}
}
+impl From<Box<str>> for SmolStr {
+ #[inline]
+ fn from(s: Box<str>) -> SmolStr {
+ SmolStr::new(s)
+ }
+}
+
+impl<'a> From<Cow<'a, str>> for SmolStr {
+ #[inline]
+ fn from(s: Cow<'a, str>) -> SmolStr {
+ SmolStr::new(s)
+ }
+}
+
impl From<SmolStr> for String {
+ #[inline(always)]
fn from(text: SmolStr) -> Self {
text.as_str().into()
}
}
impl Borrow<str> for SmolStr {
+ #[inline(always)]
fn borrow(&self) -> &str {
self.as_str()
}
@@ -327,17 +372,52 @@ impl<'a> arbitrary::Arbitrary<'a> for SmolStr {
}
}
-const INLINE_CAP: usize = 22;
+const INLINE_CAP: usize = 23;
const N_NEWLINES: usize = 32;
const N_SPACES: usize = 128;
const WS: &str =
"\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n ";
+#[derive(Clone, Copy, Debug)]
+#[repr(u8)]
+enum InlineSize {
+ _V0 = 0,
+ _V1,
+ _V2,
+ _V3,
+ _V4,
+ _V5,
+ _V6,
+ _V7,
+ _V8,
+ _V9,
+ _V10,
+ _V11,
+ _V12,
+ _V13,
+ _V14,
+ _V15,
+ _V16,
+ _V17,
+ _V18,
+ _V19,
+ _V20,
+ _V21,
+ _V22,
+ _V23,
+}
+
#[derive(Clone, Debug)]
enum Repr {
Heap(Arc<str>),
- Inline { len: u8, buf: [u8; INLINE_CAP] },
- Substring { newlines: usize, spaces: usize },
+ Inline {
+ len: InlineSize,
+ buf: [u8; INLINE_CAP],
+ },
+ Substring {
+ newlines: usize,
+ spaces: usize,
+ },
}
impl Repr {
@@ -353,7 +433,7 @@ impl Repr {
let mut buf = [0; INLINE_CAP];
buf[..len].copy_from_slice(text.as_bytes());
return Repr::Inline {
- len: len as u8,
+ len: unsafe { transmute(len as u8) },
buf,
};
}
@@ -390,7 +470,7 @@ impl Repr {
fn is_empty(&self) -> bool {
match self {
Repr::Heap(data) => data.is_empty(),
- Repr::Inline { len, .. } => *len == 0,
+ Repr::Inline { len, .. } => *len as u8 == 0,
// A substring isn't created for an empty string.
Repr::Substring { .. } => false,
}
diff --git a/vendor/smol_str/tests/test.rs b/vendor/smol_str/tests/test.rs
index 934cfa3c0..187b39f00 100644
--- a/vendor/smol_str/tests/test.rs
+++ b/vendor/smol_str/tests/test.rs
@@ -29,12 +29,12 @@ fn const_fn_ctor() {
const EMPTY: SmolStr = SmolStr::new_inline("");
const A: SmolStr = SmolStr::new_inline("A");
const HELLO: SmolStr = SmolStr::new_inline("HELLO");
- const LONG: SmolStr = SmolStr::new_inline("ABCDEFGHIZKLMNOPQRSTUV");
+ const LONG: SmolStr = SmolStr::new_inline("ABCDEFGHIZKLMNOPQRSTUVW");
assert_eq!(EMPTY, SmolStr::from(""));
assert_eq!(A, SmolStr::from("A"));
assert_eq!(HELLO, SmolStr::from("HELLO"));
- assert_eq!(LONG, SmolStr::from("ABCDEFGHIZKLMNOPQRSTUV"));
+ assert_eq!(LONG, SmolStr::from("ABCDEFGHIZKLMNOPQRSTUVW"));
}
#[allow(deprecated)]
@@ -43,19 +43,19 @@ fn old_const_fn_ctor() {
const EMPTY: SmolStr = SmolStr::new_inline_from_ascii(0, b"");
const A: SmolStr = SmolStr::new_inline_from_ascii(1, b"A");
const HELLO: SmolStr = SmolStr::new_inline_from_ascii(5, b"HELLO");
- const LONG: SmolStr = SmolStr::new_inline_from_ascii(22, b"ABCDEFGHIZKLMNOPQRSTUV");
+ const LONG: SmolStr = SmolStr::new_inline_from_ascii(23, b"ABCDEFGHIZKLMNOPQRSTUVW");
assert_eq!(EMPTY, SmolStr::from(""));
assert_eq!(A, SmolStr::from("A"));
assert_eq!(HELLO, SmolStr::from("HELLO"));
- assert_eq!(LONG, SmolStr::from("ABCDEFGHIZKLMNOPQRSTUV"));
+ assert_eq!(LONG, SmolStr::from("ABCDEFGHIZKLMNOPQRSTUVW"));
}
fn check_props(std_str: &str, smol: SmolStr) -> Result<(), proptest::test_runner::TestCaseError> {
prop_assert_eq!(smol.as_str(), std_str);
prop_assert_eq!(smol.len(), std_str.len());
prop_assert_eq!(smol.is_empty(), std_str.is_empty());
- if smol.len() <= 22 {
+ if smol.len() <= 23 {
prop_assert!(!smol.is_heap_allocated());
}
Ok(())
@@ -218,7 +218,7 @@ fn test_from_char_iterator() {
// String which has too many characters to even consider inlining: Chars::size_hint uses
// (`len` + 3) / 4. With `len` = 89, this results in 23, so `from_iter` will immediately
// heap allocate
- let raw: String = std::iter::repeat('a').take(22 * 4 + 1).collect();
+ let raw: String = std::iter::repeat('a').take(23 * 4 + 1).collect();
let s: SmolStr = raw.chars().collect();
assert_eq!(s.as_str(), raw);
assert!(s.is_heap_allocated());