Make char::is_lowercase and char::is_uppercase const
Implements #101400.
This commit is contained in:
@@ -1,5 +1,6 @@
|
||||
#[rustc_const_unstable(feature = "const_unicode_case_lookup", issue = "101400")]
|
||||
#[inline(always)]
|
||||
fn bitset_search<
|
||||
const fn bitset_search<
|
||||
const N: usize,
|
||||
const CHUNK_SIZE: usize,
|
||||
const N1: usize,
|
||||
@@ -15,14 +16,14 @@ fn bitset_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 let Some(&v) = chunk_idx_map.get(chunk_map_idx) {
|
||||
v
|
||||
let chunk_idx = if chunk_map_idx < chunk_idx_map.len() {
|
||||
chunk_idx_map[chunk_map_idx]
|
||||
} else {
|
||||
return false;
|
||||
};
|
||||
let idx = bitset_chunk_idx[chunk_idx as usize][chunk_piece] as usize;
|
||||
let word = if let Some(word) = bitset_canonical.get(idx) {
|
||||
*word
|
||||
let word = if idx < bitset_canonical.len() {
|
||||
bitset_canonical[idx]
|
||||
} else {
|
||||
let (real_idx, mapping) = bitset_canonicalized[idx - bitset_canonical.len()];
|
||||
let mut word = bitset_canonical[real_idx as usize];
|
||||
|
||||
@@ -76,7 +76,7 @@ impl RawEmitter {
|
||||
|
||||
writeln!(
|
||||
&mut self.file,
|
||||
"static BITSET_CANONICAL: [u64; {}] = [{}];",
|
||||
"const BITSET_CANONICAL: [u64; {}] = [{}];",
|
||||
canonicalized.canonical_words.len(),
|
||||
fmt_list(canonicalized.canonical_words.iter().map(|v| Bits(*v))),
|
||||
)
|
||||
@@ -84,7 +84,7 @@ impl RawEmitter {
|
||||
self.bytes_used += 8 * canonicalized.canonical_words.len();
|
||||
writeln!(
|
||||
&mut self.file,
|
||||
"static BITSET_MAPPING: [(u8, u8); {}] = [{}];",
|
||||
"const BITSET_MAPPING: [(u8, u8); {}] = [{}];",
|
||||
canonicalized.canonicalized_words.len(),
|
||||
fmt_list(&canonicalized.canonicalized_words),
|
||||
)
|
||||
@@ -96,7 +96,12 @@ impl RawEmitter {
|
||||
|
||||
self.blank_line();
|
||||
|
||||
writeln!(&mut self.file, "pub fn lookup(c: char) -> bool {{").unwrap();
|
||||
writeln!(
|
||||
&mut self.file,
|
||||
r#"#[rustc_const_unstable(feature = "const_unicode_case_lookup", issue = "101400")]"#
|
||||
)
|
||||
.unwrap();
|
||||
writeln!(&mut self.file, "pub const fn lookup(c: char) -> bool {{").unwrap();
|
||||
writeln!(&mut self.file, " super::bitset_search(",).unwrap();
|
||||
writeln!(&mut self.file, " c as u32,").unwrap();
|
||||
writeln!(&mut self.file, " &BITSET_CHUNKS_MAP,").unwrap();
|
||||
@@ -130,7 +135,7 @@ impl RawEmitter {
|
||||
|
||||
writeln!(
|
||||
&mut self.file,
|
||||
"static BITSET_CHUNKS_MAP: [u8; {}] = [{}];",
|
||||
"const BITSET_CHUNKS_MAP: [u8; {}] = [{}];",
|
||||
chunk_indices.len(),
|
||||
fmt_list(&chunk_indices),
|
||||
)
|
||||
@@ -138,7 +143,7 @@ impl RawEmitter {
|
||||
self.bytes_used += chunk_indices.len();
|
||||
writeln!(
|
||||
&mut self.file,
|
||||
"static BITSET_INDEX_CHUNKS: [[u8; {}]; {}] = [{}];",
|
||||
"const BITSET_INDEX_CHUNKS: [[u8; {}]; {}] = [{}];",
|
||||
chunk_length,
|
||||
chunks.len(),
|
||||
fmt_list(chunks.iter()),
|
||||
|
||||
Reference in New Issue
Block a user