Skip to content

Commit 74dddd6

Browse files
committed
Remote unnecessary transmute (in favor of char::from_u32_unchecked)
1 parent 0e821ff commit 74dddd6

File tree

1 file changed

+6
-10
lines changed

1 file changed

+6
-10
lines changed

src/normalize.rs

Lines changed: 6 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@
99
// except according to those terms.
1010

1111
//! Functions for computing canonical and compatible decompositions for Unicode characters.
12-
12+
use std::char;
1313
use std::cmp::Ordering::{Equal, Less, Greater};
1414
use std::ops::FnMut;
1515
use tables::normalization::{canonical_table, canonical_table_STRTAB};
@@ -124,20 +124,18 @@ const S_COUNT: u32 = (L_COUNT * N_COUNT);
124124
#[allow(unsafe_code)]
125125
#[inline(always)]
126126
fn decompose_hangul<F>(s: char, f: &mut F) where F: FnMut(char) {
127-
use std::mem::transmute;
128-
129127
let si = s as u32 - S_BASE;
130128

131129
let li = si / N_COUNT;
132130
unsafe {
133-
(*f)(transmute(L_BASE + li));
131+
(*f)(char::from_u32_unchecked(L_BASE + li));
134132

135133
let vi = (si % N_COUNT) / T_COUNT;
136-
(*f)(transmute(V_BASE + vi));
134+
(*f)(char::from_u32_unchecked(V_BASE + vi));
137135

138136
let ti = si % T_COUNT;
139137
if ti > 0 {
140-
(*f)(transmute(T_BASE + ti));
138+
(*f)(char::from_u32_unchecked(T_BASE + ti));
141139
}
142140
}
143141
}
@@ -146,22 +144,20 @@ fn decompose_hangul<F>(s: char, f: &mut F) where F: FnMut(char) {
146144
#[allow(unsafe_code)]
147145
#[inline(always)]
148146
fn compose_hangul(a: char, b: char) -> Option<char> {
149-
use std::mem::transmute;
150-
151147
let l = a as u32;
152148
let v = b as u32;
153149
// Compose an LPart and a VPart
154150
if L_BASE <= l && l < (L_BASE + L_COUNT) // l should be an L choseong jamo
155151
&& V_BASE <= v && v < (V_BASE + V_COUNT) { // v should be a V jungseong jamo
156152
let r = S_BASE + (l - L_BASE) * N_COUNT + (v - V_BASE) * T_COUNT;
157-
return unsafe { Some(transmute(r)) };
153+
return unsafe { Some(char::from_u32_unchecked(r)) };
158154
}
159155
// Compose an LVPart and a TPart
160156
if S_BASE <= l && l <= (S_BASE+S_COUNT-T_COUNT) // l should be a syllable block
161157
&& T_BASE <= v && v < (T_BASE+T_COUNT) // v should be a T jongseong jamo
162158
&& (l - S_BASE) % T_COUNT == 0 { // l should be an LV syllable block (not LVT)
163159
let r = l + (v - T_BASE);
164-
return unsafe { Some(transmute(r)) };
160+
return unsafe { Some(char::from_u32_unchecked(r)) };
165161
}
166162
None
167163
}

0 commit comments

Comments
 (0)