Skip to content

Switch from SmallVec to 100% safe TinyVec #54

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 4 commits into from
Mar 16, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 3 additions & 2 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -20,5 +20,6 @@ Unicode Standard Annex #15.

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

[dependencies]
smallvec = "1.1"
[dependencies.tinyvec]
version = "0.3.2"
features = ["alloc"]
12 changes: 6 additions & 6 deletions src/decompose.rs
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
// <LICENSE-MIT or http://opensource.org/licenses/MIT>, 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;
Expand All @@ -32,7 +32,7 @@ pub struct Decompositions<I> {
// 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<usize>,
}

Expand All @@ -41,7 +41,7 @@ pub fn new_canonical<I: Iterator<Item=char>>(iter: I) -> Decompositions<I> {
Decompositions {
kind: self::DecompositionType::Canonical,
iter: iter.fuse(),
buffer: SmallVec::new(),
buffer: TinyVec::new(),
ready: 0..0,
}
}
Expand All @@ -51,7 +51,7 @@ pub fn new_compatible<I: Iterator<Item=char>>(iter: I) -> Decompositions<I> {
Decompositions {
kind: self::DecompositionType::Compatible,
iter: iter.fuse(),
buffer: SmallVec::new(),
buffer: TinyVec::new(),
ready: 0..0,
}
}
Expand All @@ -78,8 +78,8 @@ impl<I> Decompositions<I> {

#[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];
Expand Down
2 changes: 1 addition & 1 deletion src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
8 changes: 4 additions & 4 deletions src/recompose.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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)]
Expand All @@ -24,7 +24,7 @@ enum RecompositionState {
pub struct Recompositions<I> {
iter: Decompositions<I>,
state: RecompositionState,
buffer: SmallVec<[char; 4]>,
buffer: TinyVec<[char; 4]>,
composee: Option<char>,
last_ccc: Option<u8>,
}
Expand All @@ -34,7 +34,7 @@ pub fn new_canonical<I: Iterator<Item=char>>(iter: I) -> Recompositions<I> {
Recompositions {
iter: super::decompose::new_canonical(iter),
state: self::RecompositionState::Composing,
buffer: SmallVec::new(),
buffer: TinyVec::new(),
composee: None,
last_ccc: None,
}
Expand All @@ -45,7 +45,7 @@ pub fn new_compatible<I: Iterator<Item=char>>(iter: I) -> Recompositions<I> {
Recompositions {
iter: super::decompose::new_compatible(iter),
state: self::RecompositionState::Composing,
buffer: SmallVec::new(),
buffer: TinyVec::new(),
composee: None,
last_ccc: None,
}
Expand Down