From 647ea28def72eb53f7a389c24f72459772966569 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Emilio=20Cobos=20=C3=81lvarez?= Date: Thu, 9 Jun 2022 14:10:10 +0200 Subject: [PATCH 1/2] Switch to smallvec. --- Cargo.toml | 6 ++---- src/decompose.rs | 25 ++++++++++++------------- src/lib.rs | 2 +- src/recompose.rs | 8 ++++---- src/replace.rs | 4 ++-- 5 files changed, 21 insertions(+), 24 deletions(-) diff --git a/Cargo.toml b/Cargo.toml index 51d9444..464cc99 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -22,10 +22,8 @@ edition = "2018" exclude = [ "target/*", "Cargo.lock", "scripts/tmp", "*.txt", "tests/*" ] -[dependencies.tinyvec] -version = "1" -features = ["alloc"] - +[dependencies] +smallvec = "1" [features] default = ["std"] diff --git a/src/decompose.rs b/src/decompose.rs index 23cdb1a..02e4c41 100644 --- a/src/decompose.rs +++ b/src/decompose.rs @@ -10,7 +10,7 @@ use core::fmt::{self, Write}; use core::iter::Fuse; use core::ops::Range; -use tinyvec::TinyVec; +use smallvec::SmallVec; #[derive(Clone)] enum DecompositionType { @@ -32,7 +32,7 @@ pub struct Decompositions { // 2) "Ready" characters which are sorted and ready to emit on demand; // 3) A "pending" block which stills needs more characters for us to be able // to sort in canonical order and is not safe to emit. - buffer: TinyVec<[(u8, char); 4]>, + buffer: SmallVec<[(u8, char); 4]>, ready: Range, } @@ -41,7 +41,7 @@ pub fn new_canonical>(iter: I) -> Decompositions { Decompositions { kind: self::DecompositionType::Canonical, iter: iter.fuse(), - buffer: TinyVec::new(), + buffer: Default::default(), ready: 0..0, } } @@ -51,7 +51,7 @@ pub fn new_compatible>(iter: I) -> Decompositions { Decompositions { kind: self::DecompositionType::Compatible, iter: iter.fuse(), - buffer: TinyVec::new(), + buffer: Default::default(), ready: 0..0, } } @@ -116,16 +116,15 @@ impl> Iterator for Decompositions { (None, _) => { if self.buffer.is_empty() { return None; - } else { - self.sort_pending(); - self.ready.end = self.buffer.len(); - - // This implementation means that we can call `next` - // on an exhausted iterator; the last outer `next` call - // will result in an inner `next` call. To make this - // safe, we use `fuse`. - break; } + self.sort_pending(); + self.ready.end = self.buffer.len(); + + // This implementation means that we can call `next` + // on an exhausted iterator; the last outer `next` call + // will result in an inner `next` call. To make this + // safe, we use `fuse`. + break; } } } diff --git a/src/lib.rs b/src/lib.rs index 062dc85..7ec1513 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -50,7 +50,7 @@ extern crate alloc; #[cfg(feature = "std")] extern crate core; -extern crate tinyvec; +extern crate smallvec; pub use crate::decompose::Decompositions; pub use crate::quick_check::{ diff --git a/src/recompose.rs b/src/recompose.rs index 2a1960a..63c7a26 100644 --- a/src/recompose.rs +++ b/src/recompose.rs @@ -10,7 +10,7 @@ use crate::decompose::Decompositions; use core::fmt::{self, Write}; -use tinyvec::TinyVec; +use smallvec::SmallVec; #[derive(Clone)] enum RecompositionState { @@ -24,7 +24,7 @@ enum RecompositionState { pub struct Recompositions { iter: Decompositions, state: RecompositionState, - buffer: TinyVec<[char; 4]>, + buffer: SmallVec<[char; 4]>, composee: Option, last_ccc: Option, } @@ -34,7 +34,7 @@ pub fn new_canonical>(iter: I) -> Recompositions { Recompositions { iter: super::decompose::new_canonical(iter), state: self::RecompositionState::Composing, - buffer: TinyVec::new(), + buffer: SmallVec::new(), composee: None, last_ccc: None, } @@ -45,7 +45,7 @@ pub fn new_compatible>(iter: I) -> Recompositions { Recompositions { iter: super::decompose::new_compatible(iter), state: self::RecompositionState::Composing, - buffer: TinyVec::new(), + buffer: SmallVec::new(), composee: None, last_ccc: None, } diff --git a/src/replace.rs b/src/replace.rs index 8d8cb42..7fdff3f 100644 --- a/src/replace.rs +++ b/src/replace.rs @@ -8,7 +8,7 @@ // option. This file may not be copied, modified, or distributed // except according to those terms. use core::fmt::{self, Write}; -use tinyvec::ArrayVec; +use smallvec::SmallVec; /// External iterator for replacements for a string's characters. #[derive(Clone)] @@ -36,7 +36,7 @@ impl> Iterator for Replacements { match self.iter.next() { Some(ch) => { // At this time, the longest replacement sequence has length 2. - let mut buffer = ArrayVec::<[char; 2]>::new(); + let mut buffer = SmallVec::<[char; 2]>::new(); super::char::decompose_cjk_compat_variants(ch, |d| buffer.push(d)); self.buffer = buffer.get(1).copied(); Some(buffer[0]) From 911c140897a6c4b265f3adda9c91b8fb51f2d2e7 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Emilio=20Cobos=20=C3=81lvarez?= Date: Thu, 9 Jun 2022 14:11:17 +0200 Subject: [PATCH 2/2] Bump version. --- Cargo.toml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Cargo.toml b/Cargo.toml index 464cc99..a90a0b4 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -1,7 +1,7 @@ [package] name = "unicode-normalization" -version = "0.1.19" +version = "0.1.20" authors = ["kwantam ", "Manish Goregaokar "] homepage = "https://github.com/unicode-rs/unicode-normalization"