From cb74158d5d807990e8920868f9e9283377c7ffb3 Mon Sep 17 00:00:00 2001 From: Anders Olsson Date: Wed, 25 May 2022 09:44:20 +0200 Subject: [PATCH] Added inline to most functions --- Cargo.toml | 3 +++ crates/u-norm/Cargo.toml | 1 - crates/u-norm/src/lib.rs | 4 ++++ crates/u-norm/src/main.rs | 29 ++++++++++++++++++++--------- 4 files changed, 27 insertions(+), 10 deletions(-) diff --git a/Cargo.toml b/Cargo.toml index c66a4d7..6270a22 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -1,2 +1,5 @@ [workspace] members = ["crates/*"] + +[profile.release] +debug = true diff --git a/crates/u-norm/Cargo.toml b/crates/u-norm/Cargo.toml index b0a080a..a34e5d5 100644 --- a/crates/u-norm/Cargo.toml +++ b/crates/u-norm/Cargo.toml @@ -11,7 +11,6 @@ name = "bench" harness = false [dependencies] -# fst = "0.4.7" tinyvec = { version = "1.6.0", features = ["alloc"] } u-fst = { path = "../u-fst" } diff --git a/crates/u-norm/src/lib.rs b/crates/u-norm/src/lib.rs index 088fffb..d9ea790 100644 --- a/crates/u-norm/src/lib.rs +++ b/crates/u-norm/src/lib.rs @@ -80,6 +80,7 @@ pub struct Decompositions { impl> Iterator for Decompositions { type Item = char; + #[inline(always)] fn next(&mut self) -> Option { while self.buffer.ready.end == 0 { match self.iter.next() { @@ -125,6 +126,7 @@ const T_COUNT: u32 = 28; const N_COUNT: u32 = V_COUNT * T_COUNT; const S_COUNT: u32 = L_COUNT * N_COUNT; +#[inline(always)] fn decompose(c: char, buffer: &mut Buffer) { // 7-bit ASCII never decomposes if c <= '\x7f' { @@ -155,10 +157,12 @@ fn decompose(c: char, buffer: &mut Buffer) { buffer.push_back(c); } +#[inline(always)] fn is_hangul_syllable(c: char) -> bool { (c as u32) >= S_BASE && (c as u32) < (S_BASE + S_COUNT) } +#[inline(always)] #[allow(unsafe_code)] fn decompose_hangul(s: char, buffer: &mut Buffer) { let s_index = s as u32 - S_BASE; diff --git a/crates/u-norm/src/main.rs b/crates/u-norm/src/main.rs index 9ffa21d..9603413 100644 --- a/crates/u-norm/src/main.rs +++ b/crates/u-norm/src/main.rs @@ -1,14 +1,25 @@ -use u_norm::table; +use std::fs; fn main() { - for c in '\x00'..='\x7f' { - let d = table::lookup(c); + let long = fs::read_to_string("benches/long.txt").unwrap(); - println!( - "{:?} class: {}, decomp: {:?}", - c, - d.combining_class(), - d.decomposition().map(|d| d.collect::>()) - ); + println!("{}", u_norm::nfd(&long).count()); + + /* + for ch in u_norm::nfd(&long) { + print!("{} ", u_norm::table::lookup(ch).combining_class()); } + + println!(); + */ + + /* + let mut count = 0; + + for _ in 0..5000 { + count += u_norm::nfd(&long).count(); + } + + println!("count: {}", count / 5000); + */ }