mirror of
https://github.com/serde-rs/json.git
synced 2025-10-01 15:02:37 +00:00
Optimize Unicode decoding by 1%
This commit is contained in:
parent
6130f9b358
commit
9ffb43a1e4
18
src/read.rs
18
src/read.rs
@ -1055,15 +1055,17 @@ static HEX0: [i16; 256] = build_hex_table(0);
|
||||
static HEX1: [i16; 256] = build_hex_table(4);
|
||||
|
||||
fn decode_four_hex_digits(a: u8, b: u8, c: u8, d: u8) -> Option<u16> {
|
||||
let a = HEX1[a as usize];
|
||||
let b = HEX0[b as usize];
|
||||
let c = HEX1[c as usize];
|
||||
let d = HEX0[d as usize];
|
||||
let a = HEX1[a as usize] as i32;
|
||||
let b = HEX0[b as usize] as i32;
|
||||
let c = HEX1[c as usize] as i32;
|
||||
let d = HEX0[d as usize] as i32;
|
||||
|
||||
let codepoint = ((a | b) << 8) | c | d;
|
||||
|
||||
// A single sign bit check.
|
||||
if (a | b | c | d) < 0 {
|
||||
return None;
|
||||
if codepoint >= 0 {
|
||||
Some(codepoint as u16)
|
||||
} else {
|
||||
None
|
||||
}
|
||||
|
||||
Some((((a | b) << 8) | c | d) as u16)
|
||||
}
|
||||
|
Loading…
x
Reference in New Issue
Block a user