diff options
| author | The 8472 <git@infinite-source.de> | 2023-08-29 02:01:24 +0200 |
|---|---|---|
| committer | The 8472 <git@infinite-source.de> | 2023-11-27 22:06:35 +0100 |
| commit | 40cf1f9257628d40e38a4eca9e1b8ea03a3abcd1 (patch) | |
| tree | 46dbd71f9ce402e14ef7c7ffcb6236dc7cbc0564 /library/alloc/tests | |
| parent | 3f55e8665c548d5c2ed33c9823880a8dbdf8a78f (diff) | |
optimize str::iter::Chars::advance_by
this avoids part of the char decoding work by not looking at utf8 continuation bytes
Diffstat (limited to 'library/alloc/tests')
| -rw-r--r-- | library/alloc/tests/str.rs | 11 |
1 files changed, 11 insertions, 0 deletions
diff --git a/library/alloc/tests/str.rs b/library/alloc/tests/str.rs index cb59a9d4ab2..df8a260624a 100644 --- a/library/alloc/tests/str.rs +++ b/library/alloc/tests/str.rs @@ -1171,6 +1171,17 @@ fn test_iterator() { } #[test] +fn test_iterator_advance() { + let s = "「赤錆」と呼ばれる鉄錆は、水の存在下での鉄の自然酸化によって生じる、オキシ水酸化鉄(III) 等の(含水)酸化物粒子の疎な凝集膜であるとみなせる。"; + let chars: Vec<char> = s.chars().collect(); + let mut it = s.chars(); + it.advance_by(1).unwrap(); + assert_eq!(it.next(), Some(chars[1])); + it.advance_by(33).unwrap(); + assert_eq!(it.next(), Some(chars[35])); +} + +#[test] fn test_rev_iterator() { let s = "ศไทย中华Việt Nam"; let v = ['m', 'a', 'N', ' ', 't', 'ệ', 'i', 'V', '华', '中', 'ย', 'ท', 'ไ', 'ศ']; |
