8000 Switch to smallvec. · emilio/unicode-normalization@647ea28 · GitHub
[go: up one dir, main page]

Skip to content

Commit 647ea28

Browse files
committed
Switch to smallvec.
1 parent 68f2f55 commit 647ea28

File tree

5 files changed

+21
-24
lines changed

5 files changed

+21
-24
lines changed

Cargo.toml

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -22,10 +22,8 @@ edition = "2018"
2222

2323
exclude = [ "target/*", "Cargo.lock", "scripts/tmp", "*.txt", "tests/*" ]
2424

25-
[dependencies.tinyvec]
26-
version = "1"
27-
features = ["alloc"]
28-
25+
[dependencies]
26+
smallvec = "1"
2927

3028
[features]
3129
default = ["std"]

src/decompose.rs

Lines changed: 12 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@
1010
use core::fmt::{self, Write};
1111
use core::iter::Fuse;
1212
use core::ops::Range;
13-
use tinyvec::TinyVec;
13+
use smallvec::SmallVec;
1414

1515
#[derive(Clone)]
1616
enum DecompositionType {
@@ -32,7 +32,7 @@ pub struct Decompositions<I> {
3232
// 2) "Ready" characters which are sorted and ready to emit on demand;
3333
// 3) A "pending" block which stills needs more characters for us to be able
3434
// to sort in canonical order and is not safe to emit.
35-
buffer: TinyVec<[(u8, char); 4]>,
35+
buffer: SmallVec<[(u8, char); 4]>,
3636
ready: Range<usize>,
3737
}
3838

@@ -41,7 +41,7 @@ pub fn new_canonical<I: Iterator<Item = char>>(iter: I) -> Decompositions<I> {
4141
Decompositions {
4242
kind: self::DecompositionType::Canonical,
4343
iter: iter.fuse(),
44-
buffer: TinyVec::new(),
44+
buffer: Default::default(),
4545
ready: 0..0,
4646
}
4747
}
@@ -51,7 +51,7 @@ pub fn new_compatible<I: Iterator<Item = char>>(iter: I) -> Decompositions<I> {
5151
Decompositions {
5252
kind: self::DecompositionType::Compatible,
5353
iter: iter.fuse(),
54-
buffer: TinyVec::new(),
54+
buffer: Default::default(),
5555
ready: 0..0,
5656
}
5757
}
@@ -116,16 +116,15 @@ impl<I: Iterator<Item = char>> Iterator for Decompositions<I> {
116116
(None, _) => {
117117
if self.buffer.is_empty() {
118118
return None;
119-
} else {
120-
self.sort_pending();
121-
self.ready.end = self.buffer.len();
122-
123-
// This implementation means that we can call `next`
124-
// on an exhausted iterator; the last outer `next` call
125-
// will result in an inner `next` call. To make this
126-
// safe, we use `fuse`.
127-
break;
128119
}
120+
self.sort_pending();
121+
self.ready.end = self.buffer.len();
122+
123+
// This implementation means that we can call `next`
124+
// on an exhausted iterator; the last outer `next` call
125+
// will result in an inner `next` call. To make this
126+
// safe, we use `fuse`.
127+
break;
129128
}
130129
}
131130
}

src/lib.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -50,7 +50,7 @@ extern crate alloc;
5050
#[cfg(feature = "std")]
5151
extern crate core;
5252

53-
extern crate tinyvec;
53+
extern crate smallvec;
5454

5555
pub use crate::decompose::Decompositions;
5656
pub use crate::quick_check::{

src/recompose.rs

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@
1010

1111
use crate::decompose::Decompositions;
1212
use core::fmt::{self, Write};
13-
use tinyvec::TinyVec;
13+
use smallvec::SmallVec;
1414

1515
#[derive(Clone)]
1616
enum RecompositionState {
@@ -24,7 +24,7 @@ enum RecompositionState {
2424
pub struct Recompositions<I> {
2525
iter: Decompositions<I>,
2626
state: RecompositionState,
27-
buffer: TinyVec<[char; 4]>,
27+
buffer: SmallVec<[char; 4]>,
2828
composee: Option<char>,
2929
last_ccc: Option<u8>,
3030
}
@@ -34,7 +34,7 @@ pub fn new_canonical<I: Iterator<Item = char>>(iter: I) -> Recompositions<I> {
3434
Recompositions {
3535
iter: super::decompose::new_canonical(iter),
3636
state: self::RecompositionState::Composing,
37-
buffer: TinyVec::new(),
37+
buffer: SmallVec::new(),
3838
composee: None,
3939
last_ccc: None,
4040
}
@@ -45,7 +45,7 @@ pub fn new_compatible<I: Iterator<Item = char>>(iter: I) -> Recompositions<I> {
4545
Recompositions {
4646
iter: super::decompose::new_compatible(iter),
4747
state: self::RecompositionState::Composing,
48-
buffer: TinyVec::new(),
48+
buffer: SmallVec::new(),
4949
composee: None,
5050
last_ccc: None,
5151
}

src/replace.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@
88
// option. This file may not be copied, modified, or distributed
99
// except according to those terms.
1010
use core::fmt::{self, Write};
11-
use tinyvec::ArrayVec;
11+
use smallvec::SmallVec;
1212

1313
/// External iterator for replacements for a string's characters.
1414
#[derive(Clone)]
@@ -36,7 +36,7 @@ impl<I: Iterator<Item = char>> Iterator for Replacements<I> {
3636
match self.iter.next() {
3737
Some(ch) => {
3838
// At this time, the longest replacement sequence has length 2.
39-
let mut buffer = ArrayVec::<[char; 2]>::new();
39+
let mut buffer = SmallVec::<[char; 2]>::new();
4040
super::char::decompose_cjk_compat_variants(ch, |d| buffer.push(d));
4141
self.buffer = buffer.get(1).copied();
4242
Some(buffer[0])

0 commit comments

Comments
 (0)
0