Skip to content
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

RFC: Switch from tinyvec to smallvec #85

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
Open
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
8 changes: 3 additions & 5 deletions Cargo.toml
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
[package]

name = "unicode-normalization"
version = "0.1.19"
version = "0.1.20"
authors = ["kwantam <kwantam@gmail.com>", "Manish Goregaokar <manishsmail@gmail.com>"]

homepage = "https://github.com/unicode-rs/unicode-normalization"
Expand All @@ -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"]
Expand Down
25 changes: 12 additions & 13 deletions src/decompose.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
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: TinyVec<[(u8, char); 4]>,
buffer: SmallVec<[(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: TinyVec::new(),
buffer: Default::default(),
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: TinyVec::new(),
buffer: Default::default(),
ready: 0..0,
}
}
Expand Down Expand Up @@ -116,16 +116,15 @@ impl<I: Iterator<Item = char>> Iterator for Decompositions<I> {
(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;
}
}
}
Expand Down
2 changes: 1 addition & 1 deletion src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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::{
Expand Down
8 changes: 4 additions & 4 deletions src/recompose.rs
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@

use crate::decompose::Decompositions;
use core::fmt::{self, Write};
use tinyvec::TinyVec;
use smallvec::SmallVec;

#[derive(Clone)]
enum RecompositionState {
Expand All @@ -24,7 +24,7 @@ enum RecompositionState {
pub struct Recompositions<I> {
iter: Decompositions<I>,
state: RecompositionState,
buffer: TinyVec<[char; 4]>,
buffer: SmallVec<[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: TinyVec::new(),
buffer: SmallVec::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: TinyVec::new(),
buffer: SmallVec::new(),
composee: None,
last_ccc: None,
}
Expand Down
4 changes: 2 additions & 2 deletions src/replace.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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)]
Expand Down Expand Up @@ -36,7 +36,7 @@ impl<I: Iterator<Item = char>> Iterator for Replacements<I> {
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])
Expand Down