Skip to content

Commit ea94a90

Browse files
author
Jorge Aparicio
committed
unicode: unbox closures used in function arguments
1 parent 10d99a9 commit ea94a90

File tree

1 file changed

+15
-12
lines changed

1 file changed

+15
-12
lines changed

src/libunicode/normalize.rs

Lines changed: 15 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@
1111
//! Functions for computing canonical and compatible decompositions for Unicode characters.
1212
1313
use core::cmp::Ordering::{Equal, Less, Greater};
14+
use core::ops::FnMut;
1415
use core::option::Option;
1516
use core::option::Option::{Some, None};
1617
use core::slice::SliceExt;
@@ -32,14 +33,15 @@ fn bsearch_table<T>(c: char, r: &'static [(char, &'static [T])]) -> Option<&'sta
3233
}
3334

3435
/// Compute canonical Unicode decomposition for character
35-
pub fn decompose_canonical(c: char, i: |char|) { d(c, i, false); }
36+
pub fn decompose_canonical<F>(c: char, mut i: F) where F: FnMut(char) { d(c, &mut i, false); }
3637

3738
/// Compute canonical or compatible Unicode decomposition for character
38-
pub fn decompose_compatible(c: char, i: |char|) { d(c, i, true); }
39+
pub fn decompose_compatible<F>(c: char, mut i: F) where F: FnMut(char) { d(c, &mut i, true); }
3940

40-
fn d(c: char, i: |char|, k: bool) {
41+
// FIXME(#19596) This is a workaround, we should use `F` instead of `&mut F`
42+
fn d<F>(c: char, i: &mut F, k: bool) where F: FnMut(char) {
4143
// 7-bit ASCII never decomposes
42-
if c <= '\x7f' { i(c); return; }
44+
if c <= '\x7f' { (*i)(c); return; }
4345

4446
// Perform decomposition for Hangul
4547
if (c as u32) >= S_BASE && (c as u32) < (S_BASE + S_COUNT) {
@@ -51,29 +53,29 @@ fn d(c: char, i: |char|, k: bool) {
5153
match bsearch_table(c, canonical_table) {
5254
Some(canon) => {
5355
for x in canon.iter() {
54-
d(*x, |b| i(b), k);
56+
d(*x, i, k);
5557
}
5658
return;
5759
}
5860
None => ()
5961
}
6062

6163
// Bottom out if we're not doing compat.
62-
if !k { i(c); return; }
64+
if !k { (*i)(c); return; }
6365

6466
// Then check the compatibility decompositions
6567
match bsearch_table(c, compatibility_table) {
6668
Some(compat) => {
6769
for x in compat.iter() {
68-
d(*x, |b| i(b), k);
70+
d(*x, i, k);
6971
}
7072
return;
7173
}
7274
None => ()
7375
}
7476

7577
// Finally bottom out.
76-
i(c);
78+
(*i)(c);
7779
}
7880

7981
pub fn compose(a: char, b: char) -> Option<char> {
@@ -108,23 +110,24 @@ const T_COUNT: u32 = 28;
108110
const N_COUNT: u32 = (V_COUNT * T_COUNT);
109111
const S_COUNT: u32 = (L_COUNT * N_COUNT);
110112

113+
// FIXME(#19596) This is a workaround, we should use `F` instead of `&mut F`
111114
// Decompose a precomposed Hangul syllable
112115
#[inline(always)]
113-
fn decompose_hangul(s: char, f: |char|) {
116+
fn decompose_hangul<F>(s: char, f: &mut F) where F: FnMut(char) {
114117
use core::mem::transmute;
115118

116119
let si = s as u32 - S_BASE;
117120

118121
let li = si / N_COUNT;
119122
unsafe {
120-
f(transmute(L_BASE + li));
123+
(*f)(transmute(L_BASE + li));
121124

122125
let vi = (si % N_COUNT) / T_COUNT;
123-
f(transmute(V_BASE + vi));
126+
(*f)(transmute(V_BASE + vi));
124127

125128
let ti = si % T_COUNT;
126129
if ti > 0 {
127-
f(transmute(T_BASE + ti));
130+
(*f)(transmute(T_BASE + ti));
128131
}
129132
}
130133
}

0 commit comments

Comments
 (0)