Skip to content

Commit 11468b9

Browse files
committed
Use ASCII to get the "too big" char iterator
Additionally, make the construction of the string mechanical
1 parent 267c02f commit 11468b9

File tree

1 file changed

+7
-2
lines changed
  • src/tools/rust-analyzer/lib/smol_str/tests

1 file changed

+7
-2
lines changed

src/tools/rust-analyzer/lib/smol_str/tests/test.rs

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -209,14 +209,19 @@ fn test_from_char_iterator() {
209209
("사회과학원 어학연구소", true),
210210
// String containing diverse characters
211211
("表ポあA鷗ŒéB逍Üߪąñ丂㐀𠀀", true),
212-
// String which has too many characters to even consider inlining
213-
("☺☺☺☺☺☺☺☺☺☺☺☺☺☺☺☺☺☺☺☺☺☺☺☺☺☺☺☺☺☺☺☺", true),
214212
];
215213
for (raw, is_heap) in &examples {
216214
let s: SmolStr = raw.chars().collect();
217215
assert_eq!(s.as_str(), *raw);
218216
assert_eq!(s.is_heap_allocated(), *is_heap);
219217
}
218+
// String which has too many characters to even consider inlining: Chars::size_hint uses
219+
// (`len` + 3) / 4. With `len` = 89, this results in 23, so `from_iter` will immediately
220+
// heap allocate
221+
let raw: String = std::iter::repeat('a').take(22 * 4 + 1).collect();
222+
let s: SmolStr = raw.chars().collect();
223+
assert_eq!(s.as_str(), raw);
224+
assert!(s.is_heap_allocated());
220225
}
221226

222227
#[test]

0 commit comments

Comments
 (0)