Skip to content

Commit 939b145

Browse files
committed
faster
1 parent 103ae30 commit 939b145

File tree

2 files changed

+15
-14
lines changed

2 files changed

+15
-14
lines changed

build/ucd_generator/generators.rs

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -34,17 +34,17 @@ pub fn generate_enum_table(code_dir : &std::path::Path, name : &str, enum_values
3434
write!(fd, "const {}_COLUMN_BITS : usize = {};\n", upper_name, column_bits)?;
3535
write!(fd, "const {}_INDEX_LEN : usize = {};\n", upper_name, index.len())?;
3636
write!(fd, "const {}_INDEX_BITS : usize = {};\n\n", upper_name, index_bits)?;
37+
write!(fd, "const {}_INDEX_BYTE_OFFSET : usize = {};\n\n", upper_name, column_bytes.len())?;
3738

38-
write!(fd, "const {}_COLUMN: [u8; {}] = [", upper_name, column_bytes.len())?;
39+
write!(fd, "const {}_DATA: [u8; {}] = [\n", upper_name, column_bytes.len() + index_bytes.len())?;
40+
write!(fd, " // Column table")?;
3941
for (i, v) in column_bytes.iter().enumerate() {
4042
if i % 32 == 0 {
4143
write!(fd, "\n ")?;
4244
}
4345
write!(fd, "{:3},", v)?;
4446
}
45-
write!(fd, "\n];\n\n")?;
46-
47-
write!(fd, "const {}_INDEX: [u8; {}] = [", upper_name, index_bytes.len())?;
47+
write!(fd, "\n // Index table")?;
4848
for (i, v) in index_bytes.iter().enumerate() {
4949
if i % 32 == 0 {
5050
write!(fd, "\n ")?;
@@ -86,7 +86,7 @@ pub fn generate_enum_table(code_dir : &std::path::Path, name : &str, enum_values
8686
write!(fd, " let mut index: usize = 0;\n")?;
8787
let index_bytes_to_read = (index_bits + 7) / 8 + 1;
8888
for i in (0..index_bytes_to_read).rev() {
89-
write!(fd, " index |= ({}_INDEX[index_byte_offset + {}] as usize) << {};\n", upper_name, i, i * 8)?;
89+
write!(fd, " index |= ({}_DATA[{}_INDEX_BYTE_OFFSET + index_byte_offset + {}] as usize) << {};\n", upper_name, upper_name, i, i * 8)?;
9090
}
9191
write!(fd, " index >>= index_bit_offset;\n")?;
9292
write!(fd, " index &= INDEX_MASK;\n\n")?;
@@ -98,7 +98,7 @@ pub fn generate_enum_table(code_dir : &std::path::Path, name : &str, enum_values
9898
write!(fd, " let mut value: usize = 0;\n")?;
9999
let column_bytes_to_read = (column_bits + 7) / 8 + 1;
100100
for i in (0..column_bytes_to_read).rev() {
101-
write!(fd, " value |= ({}_COLUMN[column_byte_offset + {}] as usize) << {};\n", upper_name, i, i * 8)?;
101+
write!(fd, " value |= ({}_DATA[column_byte_offset + {}] as usize) << {};\n", upper_name, i, i * 8)?;
102102
}
103103
write!(fd, " value >>= column_bit_offset;\n")?;
104104
write!(fd, " value &= COLUMN_MASK;\n\n")?;

src/east_asian_width.rs

Lines changed: 9 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,10 @@ const EAST_ASIAN_WIDTH_COLUMN_BITS : usize = 3;
55
const EAST_ASIAN_WIDTH_INDEX_LEN : usize = 4352;
66
const EAST_ASIAN_WIDTH_INDEX_BITS : usize = 6;
77

8-
const EAST_ASIAN_WIDTH_COLUMN: [u8; 4807] = [
8+
const EAST_ASIAN_WIDTH_INDEX_BYTE_OFFSET : usize = 4807;
9+
10+
const EAST_ASIAN_WIDTH_DATA: [u8; 8078] = [
11+
// Column table
912
0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 73,146, 36, 73,146, 36, 73,146, 36, 73,146, 36, 73,146, 36, 73,146, 36, 73,146,
1013
36, 73,146, 36, 73,146, 36, 73,146, 36, 73,146, 36, 73,146, 4, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 80,162, 68,130,
1114
16, 41,146, 36, 72,146, 32, 73, 0, 0, 8, 0, 0, 0, 2, 0, 64, 2, 0, 72, 18, 0, 8,146, 32, 1,130, 4, 64,146, 32, 8,
@@ -157,9 +160,7 @@ const EAST_ASIAN_WIDTH_COLUMN: [u8; 4807] = [
157160
73,146, 36, 73,146, 36, 73,146, 36, 73,146, 36, 73,146, 36, 73,146, 36, 73,146, 36, 73,146, 36, 73,146, 36, 73,146, 36, 73,146,
158161
36, 73,146, 36, 73,146, 36, 73,146, 36, 73,146, 36, 73,146, 36, 73,146, 36, 73,146, 36, 73,146, 36, 73,146, 36, 73,146, 36, 1,
159162
0, 0, 0, 0, 0, 0, 0,
160-
];
161-
162-
const EAST_ASIAN_WIDTH_INDEX: [u8; 3271] = [
163+
// Index table
163164
64, 32, 12, 68, 81, 20, 69, 81, 20, 69, 81, 20,133, 81, 20, 69, 81, 20, 69, 81, 20, 69, 81, 20, 7,146, 40, 11,211, 56,197, 83,
164165
64, 69, 17, 73, 19, 85, 89,150,101, 89,150,101, 89,150,101, 89,150,101, 89,150,101, 89,150,101, 89,150,101, 89,150,101, 89,150,
165166
101, 89,150,101, 89,150,101, 89,150,101, 89,150,101, 89,150,101, 89,150,101, 89,150,101, 89,150,101, 89,150,101, 89,150,101, 89,
@@ -299,8 +300,8 @@ pub enum EastAsianWidth {
299300
let index_byte_offset = index_offset / 8;
300301
let index_bit_offset = index_offset % 8;
301302
let mut index: usize = 0;
302-
index |= (EAST_ASIAN_WIDTH_INDEX[index_byte_offset + 1] as usize) << 8;
303-
index |= (EAST_ASIAN_WIDTH_INDEX[index_byte_offset + 0] as usize) << 0;
303+
index |= (EAST_ASIAN_WIDTH_DATA[EAST_ASIAN_WIDTH_INDEX_BYTE_OFFSET + index_byte_offset + 1] as usize) << 8;
304+
index |= (EAST_ASIAN_WIDTH_DATA[EAST_ASIAN_WIDTH_INDEX_BYTE_OFFSET + index_byte_offset + 0] as usize) << 0;
304305
index >>= index_bit_offset;
305306
index &= INDEX_MASK;
306307

@@ -309,8 +310,8 @@ pub enum EastAsianWidth {
309310
let column_bit_offset = column_offset % 8;
310311

311312
let mut value: usize = 0;
312-
value |= (EAST_ASIAN_WIDTH_COLUMN[column_byte_offset + 1] as usize) << 8;
313-
value |= (EAST_ASIAN_WIDTH_COLUMN[column_byte_offset + 0] as usize) << 0;
313+
value |= (EAST_ASIAN_WIDTH_DATA[column_byte_offset + 1] as usize) << 8;
314+
value |= (EAST_ASIAN_WIDTH_DATA[column_byte_offset + 0] as usize) << 0;
314315
value >>= column_bit_offset;
315316
value &= COLUMN_MASK;
316317

0 commit comments

Comments
 (0)