Skip to content

Commit 2b328ea

Browse files
committed
Address feedback from PR rust-lang#101401
1 parent 4a3e169 commit 2b328ea

File tree

3 files changed

+20
-12
lines changed

3 files changed

+20
-12
lines changed

library/core/src/unicode/unicode_data.rs

+12-8
Original file line numberDiff line numberDiff line change
@@ -18,12 +18,16 @@ const fn bitset_search<
1818
let bucket_idx = (needle / 64) as usize;
1919
let chunk_map_idx = bucket_idx / CHUNK_SIZE;
2020
let chunk_piece = bucket_idx % CHUNK_SIZE;
21+
// FIXME: const-hack: Revert to `slice::get` after `const_slice_index`
22+
// feature stabilizes.
2123
let chunk_idx = if chunk_map_idx < chunk_idx_map.len() {
2224
chunk_idx_map[chunk_map_idx]
2325
} else {
2426
return false;
2527
};
2628
let idx = bitset_chunk_idx[chunk_idx as usize][chunk_piece] as usize;
29+
// FIXME: const-hack: Revert to `slice::get` after `const_slice_index`
30+
// feature stabilizes.
2731
let word = if idx < bitset_canonical.len() {
2832
bitset_canonical[idx]
2933
} else {
@@ -319,14 +323,14 @@ pub mod grapheme_extend {
319323

320324
#[rustfmt::skip]
321325
pub mod lowercase {
322-
const BITSET_CHUNKS_MAP: [u8; 123] = [
326+
const BITSET_CHUNKS_MAP: &'static [u8; 123] = &[
323327
14, 17, 0, 0, 9, 0, 0, 12, 13, 10, 0, 16, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
324328
0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 6, 2, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
325329
0, 0, 0, 4, 1, 0, 15, 0, 8, 0, 0, 11, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
326330
0, 0, 5, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 18, 0,
327331
3, 0, 0, 7,
328332
];
329-
const BITSET_INDEX_CHUNKS: [[u8; 16]; 19] = [
333+
const BITSET_INDEX_CHUNKS: &'static [[u8; 16]; 19] = &[
330334
[0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0],
331335
[0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 59, 0, 0],
332336
[0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 16, 14, 55, 0],
@@ -347,7 +351,7 @@ pub mod lowercase {
347351
[16, 49, 2, 20, 66, 9, 57, 0, 0, 0, 0, 0, 0, 0, 0, 0],
348352
[63, 39, 54, 12, 73, 61, 18, 1, 6, 62, 71, 19, 68, 69, 3, 44],
349353
];
350-
const BITSET_CANONICAL: [u64; 55] = [
354+
const BITSET_CANONICAL: &'static [u64; 55] = &[
351355
0b0000000000000000000000000000000000000000000000000000000000000000,
352356
0b1111111111111111110000000000000000000000000011111111111111111111,
353357
0b1010101010101010101010101010101010101010101010101010100000000010,
@@ -404,7 +408,7 @@ pub mod lowercase {
404408
0b1110011111111111111111111111111111111111111111110000000000000000,
405409
0b1110101111000000000000000000000000001111111111111111111111111100,
406410
];
407-
const BITSET_MAPPING: [(u8, u8); 20] = [
411+
const BITSET_MAPPING: &'static [(u8, u8); 20] = &[
408412
(0, 64), (1, 188), (1, 183), (1, 176), (1, 109), (1, 124), (1, 126), (1, 66), (1, 70),
409413
(1, 77), (2, 146), (2, 144), (2, 83), (3, 12), (3, 6), (4, 156), (4, 78), (5, 187),
410414
(6, 132), (7, 93),
@@ -456,14 +460,14 @@ pub mod n {
456460

457461
#[rustfmt::skip]
458462
pub mod uppercase {
459-
const BITSET_CHUNKS_MAP: [u8; 125] = [
463+
const BITSET_CHUNKS_MAP: &'static [u8; 125] = &[
460464
12, 15, 6, 6, 0, 6, 6, 2, 4, 11, 6, 16, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6,
461465
6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 8, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6,
462466
6, 6, 6, 5, 6, 14, 6, 10, 6, 6, 1, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6,
463467
6, 7, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 13, 6, 6,
464468
6, 6, 9, 6, 3,
465469
];
466-
const BITSET_INDEX_CHUNKS: [[u8; 16]; 17] = [
470+
const BITSET_INDEX_CHUNKS: &'static [[u8; 16]; 17] = &[
467471
[43, 43, 5, 34, 43, 43, 43, 43, 43, 43, 43, 43, 43, 43, 5, 1],
468472
[43, 43, 5, 43, 43, 43, 43, 43, 43, 43, 43, 43, 43, 43, 43, 43],
469473
[43, 43, 39, 43, 43, 43, 43, 43, 17, 17, 62, 17, 42, 29, 24, 23],
@@ -482,7 +486,7 @@ pub mod uppercase {
482486
[57, 19, 2, 18, 10, 47, 43, 43, 43, 43, 43, 43, 43, 43, 43, 43],
483487
[57, 37, 17, 27, 43, 43, 43, 43, 43, 43, 43, 43, 43, 43, 43, 43],
484488
];
485-
const BITSET_CANONICAL: [u64; 43] = [
489+
const BITSET_CANONICAL: &'static [u64; 43] = &[
486490
0b0000011111111111111111111111111000000000000000000000000000000000,
487491
0b0000000000111111111111111111111111111111111111111111111111111111,
488492
0b0101010101010101010101010101010101010101010101010101010000000001,
@@ -527,7 +531,7 @@ pub mod uppercase {
527531
0b1111011111111111000000000000000000000000000000000000000000000000,
528532
0b1111111100000000111111110000000000111111000000001111111100000000,
529533
];
530-
const BITSET_MAPPING: [(u8, u8); 25] = [
534+
const BITSET_MAPPING: &'static [(u8, u8); 25] = &[
531535
(0, 187), (0, 177), (0, 171), (0, 167), (0, 164), (0, 32), (0, 47), (0, 51), (0, 121),
532536
(0, 117), (0, 109), (1, 150), (1, 148), (1, 142), (1, 134), (1, 131), (1, 64), (2, 164),
533537
(2, 146), (2, 20), (3, 146), (3, 140), (3, 134), (4, 178), (4, 171),

src/tools/unicode-table-generator/src/range_search.rs

+4
Original file line numberDiff line numberDiff line change
@@ -16,12 +16,16 @@ const fn bitset_search<
1616
let bucket_idx = (needle / 64) as usize;
1717
let chunk_map_idx = bucket_idx / CHUNK_SIZE;
1818
let chunk_piece = bucket_idx % CHUNK_SIZE;
19+
// FIXME: const-hack: Revert to `slice::get` after `const_slice_index`
20+
// feature stabilizes.
1921
let chunk_idx = if chunk_map_idx < chunk_idx_map.len() {
2022
chunk_idx_map[chunk_map_idx]
2123
} else {
2224
return false;
2325
};
2426
let idx = bitset_chunk_idx[chunk_idx as usize][chunk_piece] as usize;
27+
// FIXME: const-hack: Revert to `slice::get` after `const_slice_index`
28+
// feature stabilizes.
2529
let word = if idx < bitset_canonical.len() {
2630
bitset_canonical[idx]
2731
} else {

src/tools/unicode-table-generator/src/raw_emitter.rs

+4-4
Original file line numberDiff line numberDiff line change
@@ -76,15 +76,15 @@ impl RawEmitter {
7676

7777
writeln!(
7878
&mut self.file,
79-
"const BITSET_CANONICAL: [u64; {}] = [{}];",
79+
"const BITSET_CANONICAL: &'static [u64; {}] = &[{}];",
8080
canonicalized.canonical_words.len(),
8181
fmt_list(canonicalized.canonical_words.iter().map(|v| Bits(*v))),
8282
)
8383
.unwrap();
8484
self.bytes_used += 8 * canonicalized.canonical_words.len();
8585
writeln!(
8686
&mut self.file,
87-
"const BITSET_MAPPING: [(u8, u8); {}] = [{}];",
87+
"const BITSET_MAPPING: &'static [(u8, u8); {}] = &[{}];",
8888
canonicalized.canonicalized_words.len(),
8989
fmt_list(&canonicalized.canonicalized_words),
9090
)
@@ -135,15 +135,15 @@ impl RawEmitter {
135135

136136
writeln!(
137137
&mut self.file,
138-
"const BITSET_CHUNKS_MAP: [u8; {}] = [{}];",
138+
"const BITSET_CHUNKS_MAP: &'static [u8; {}] = &[{}];",
139139
chunk_indices.len(),
140140
fmt_list(&chunk_indices),
141141
)
142142
.unwrap();
143143
self.bytes_used += chunk_indices.len();
144144
writeln!(
145145
&mut self.file,
146-
"const BITSET_INDEX_CHUNKS: [[u8; {}]; {}] = [{}];",
146+
"const BITSET_INDEX_CHUNKS: &'static [[u8; {}]; {}] = &[{}];",
147147
chunk_length,
148148
chunks.len(),
149149
fmt_list(chunks.iter()),

0 commit comments

Comments
 (0)