diff options
| author | Mark Rousskov <mark.simulacrum@gmail.com> | 2020-03-21 15:22:41 -0400 |
|---|---|---|
| committer | Mark Rousskov <mark.simulacrum@gmail.com> | 2020-03-21 17:51:40 -0400 |
| commit | 233ab2f168d29d5e77abc1bc6c3923edf3575e08 (patch) | |
| tree | 162bcc2deba61e31b7157116b06f381f2048d45f /src/tools/unicode-table-generator | |
| parent | 5f71d98f90354f9ee67c2b77c8607fbc9169d63e (diff) | |
| download | rust-233ab2f168d29d5e77abc1bc6c3923edf3575e08.tar.gz rust-233ab2f168d29d5e77abc1bc6c3923edf3575e08.zip | |
Push the byte of LAST_CHUNK_MAP into the array
This optimizes slightly better. Alphabetic : 2536 bytes Case_Ignorable : 1771 bytes Cased : 788 bytes Cc : 24 bytes Grapheme_Extend: 1488 bytes Lowercase : 863 bytes N : 1038 bytes Uppercase : 776 bytes White_Space : 83 bytes Total table sizes: 9367 bytes (-18 bytes; 2 bytes per set)
Diffstat (limited to 'src/tools/unicode-table-generator')
| -rw-r--r-- | src/tools/unicode-table-generator/src/range_search.rs | 16 | ||||
| -rw-r--r-- | src/tools/unicode-table-generator/src/raw_emitter.rs | 9 |
2 files changed, 14 insertions, 11 deletions
diff --git a/src/tools/unicode-table-generator/src/range_search.rs b/src/tools/unicode-table-generator/src/range_search.rs index a0bc1e6aec5..12efa5a9f83 100644 --- a/src/tools/unicode-table-generator/src/range_search.rs +++ b/src/tools/unicode-table-generator/src/range_search.rs @@ -8,7 +8,7 @@ fn range_search< >( needle: u32, chunk_idx_map: &[u8; N], - (last_chunk_idx, last_chunk_mapping): (u16, u8), + last_chunk_idx: u16, bitset_chunk_idx: &[[u8; CHUNK_SIZE]; N1], bitset_canonical: &[u64; CANONICAL], bitset_canonicalized: &[(u8, u8); CANONICALIZED], @@ -16,14 +16,14 @@ fn range_search< let bucket_idx = (needle / 64) as usize; let chunk_map_idx = bucket_idx / CHUNK_SIZE; let chunk_piece = bucket_idx % CHUNK_SIZE; - let chunk_idx = if chunk_map_idx >= N { - if chunk_map_idx == last_chunk_idx as usize { - last_chunk_mapping - } else { - return false; - } - } else { + // The last entry of `chunk_idx_map` actually should be at `last_chunk_idx`, + // so we need to remap it + let chunk_idx = if chunk_map_idx < (chunk_idx_map.len() - 1) { chunk_idx_map[chunk_map_idx] + } else if chunk_map_idx == last_chunk_idx as usize { + chunk_idx_map[chunk_idx_map.len() - 1] + } else { + return false; }; let idx = bitset_chunk_idx[(chunk_idx as usize)][chunk_piece] as usize; let word = if idx < CANONICAL { diff --git a/src/tools/unicode-table-generator/src/raw_emitter.rs b/src/tools/unicode-table-generator/src/raw_emitter.rs index a0814fd0d36..4898df3c800 100644 --- a/src/tools/unicode-table-generator/src/raw_emitter.rs +++ b/src/tools/unicode-table-generator/src/raw_emitter.rs @@ -150,19 +150,22 @@ impl RawEmitter { while zero_chunk_idx.is_some() && chunk_indices.last().cloned() == zero_chunk_idx { chunk_indices.pop(); } + // We do not count the LAST_CHUNK_MAP as adding bytes because it's a + // small constant whose values are inlined directly into the instruction + // stream. writeln!( &mut self.file, - "static BITSET_LAST_CHUNK_MAP: (u16, u8) = ({}, {});", + "const BITSET_LAST_CHUNK_MAP: u16 = {};", chunk_indices.len() - 1, - chunk_indices.pop().unwrap(), ) .unwrap(); - self.bytes_used += 3; + let nonzero = chunk_indices.pop().unwrap(); // Try to pop again, now that we've recorded a non-zero pointing index // into the LAST_CHUNK_MAP. while zero_chunk_idx.is_some() && chunk_indices.last().cloned() == zero_chunk_idx { chunk_indices.pop(); } + chunk_indices.push(nonzero); writeln!( &mut self.file, "static BITSET_CHUNKS_MAP: [u8; {}] = [{}];", |
