From d6abe8e5148c2c513cb65f487a037c7600de2498 Mon Sep 17 00:00:00 2001 From: "Sergey \"Shnatsel\" Davidoff" Date: Mon, 13 Jan 2020 19:56:13 +0100 Subject: [PATCH 1/3] Switch from SmallVec to 100% safe TinyVec --- Cargo.toml | 2 +- src/decompose.rs | 8 ++++---- src/lib.rs | 2 +- src/recompose.rs | 8 ++++---- 4 files changed, 10 insertions(+), 10 deletions(-) diff --git a/Cargo.toml b/Cargo.toml index eec56f1..56cbf03 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -21,4 +21,4 @@ Unicode Standard Annex #15. exclude = [ "target/*", "Cargo.lock", "scripts/tmp", "*.txt", "tests/*" ] [dependencies] -smallvec = "1.0" +tinyvec = "0.1.2" diff --git a/src/decompose.rs b/src/decompose.rs index b4ef386..57682ca 100644 --- a/src/decompose.rs +++ b/src/decompose.rs @@ -7,7 +7,7 @@ // , at your // option. This file may not be copied, modified, or distributed // except according to those terms. -use smallvec::SmallVec; +use tinyvec::TinyVec; use std::fmt::{self, Write}; use std::iter::Fuse; use std::ops::Range; @@ -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: SmallVec<[(u8, char); 4]>, + buffer: TinyVec<[(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: SmallVec::new(), + buffer: TinyVec::new(), ready: 0..0, } } @@ -51,7 +51,7 @@ pub fn new_compatible>(iter: I) -> Decompositions { Decompositions { kind: self::DecompositionType::Compatible, iter: iter.fuse(), - buffer: SmallVec::new(), + buffer: TinyVec::new(), ready: 0..0, } } diff --git a/src/lib.rs b/src/lib.rs index a86ade1..56142a2 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -41,7 +41,7 @@ #![doc(html_logo_url = "https://unicode-rs.github.io/unicode-rs_sm.png", html_favicon_url = "https://unicode-rs.github.io/unicode-rs_sm.png")] -extern crate smallvec; +extern crate tinyvec; pub use tables::UNICODE_VERSION; pub use decompose::Decompositions; diff --git a/src/recompose.rs b/src/recompose.rs index 4c2bf97..40b20dc 100644 --- a/src/recompose.rs +++ b/src/recompose.rs @@ -9,7 +9,7 @@ // except according to those terms. use decompose::Decompositions; -use smallvec::SmallVec; +use tinyvec::TinyVec; use std::fmt::{self, Write}; #[derive(Clone)] @@ -24,7 +24,7 @@ enum RecompositionState { pub struct Recompositions { iter: Decompositions, state: RecompositionState, - buffer: SmallVec<[char; 4]>, + buffer: TinyVec<[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: SmallVec::new(), + buffer: TinyVec::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: SmallVec::new(), + buffer: TinyVec::new(), composee: None, last_ccc: None, } From a3fcd13a4e38aaf4020be7af2d10468c72dbc0e1 Mon Sep 17 00:00:00 2001 From: "Sergey \"Shnatsel\" Davidoff" Date: Mon, 16 Mar 2020 00:22:48 +0100 Subject: [PATCH 2/3] Update to newer TinyVec --- Cargo.toml | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/Cargo.toml b/Cargo.toml index 56cbf03..b4ee027 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -20,5 +20,6 @@ Unicode Standard Annex #15. exclude = [ "target/*", "Cargo.lock", "scripts/tmp", "*.txt", "tests/*" ] -[dependencies] -tinyvec = "0.1.2" +[dependencies.tinyvec] +version = "0.3.2" +features = ["alloc"] From da9402370399631d1132408a2f57f7e8ee9ad47f Mon Sep 17 00:00:00 2001 From: "Sergey \"Shnatsel\" Davidoff" Date: Mon, 16 Mar 2020 00:37:04 +0100 Subject: [PATCH 3/3] Improve comment --- src/decompose.rs | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/decompose.rs b/src/decompose.rs index 57682ca..6533c0c 100644 --- a/src/decompose.rs +++ b/src/decompose.rs @@ -78,8 +78,8 @@ impl Decompositions { #[inline] fn reset_buffer(&mut self) { - // Equivalent to `self.buffer.drain(0..self.ready.end)` (if SmallVec - // supported this API) + // Equivalent to `self.buffer.drain(0..self.ready.end)` + // but faster than drain() if the buffer is a SmallVec or TinyVec let pending = self.buffer.len() - self.ready.end; for i in 0..pending { self.buffer[i] = self.buffer[i + self.ready.end];