Skip to content

Commit 63fa8da

Browse files
Remove -x- encoding for marker attributes (#5038)
#3632 * baked: use `(&str, &str)` if needed, otherwise `&str` as before * blob: use U+001E ("record separator") as the separator * fs: use additional directory level
1 parent 3f5464f commit 63fa8da

File tree

8,521 files changed

+28822
-28809
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

8,521 files changed

+28822
-28809
lines changed

components/experimental/tests/transliterate/data/baked/macros/transliterator_rules_v1.rs.data

Lines changed: 19 additions & 19 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.
-4 Bytes
Binary file not shown.

provider/baked/src/binary_search.rs

Lines changed: 36 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -16,30 +16,47 @@ pub fn bake(
1616
) -> TokenStream {
1717
let mut data = data
1818
.into_iter()
19-
.map(|((l, a), i)| {
20-
(
21-
DataRequest {
22-
locale: &l,
23-
marker_attributes: &a,
24-
..Default::default()
25-
}
26-
.legacy_encode(),
27-
quote!(#i),
28-
)
29-
})
19+
.map(|((l, a), i)| ((a.to_string(), l.to_string()), quote!(#i)))
3020
.collect::<Vec<_>>();
3121

3222
data.sort_by(|(a, _), (b, _)| a.cmp(b));
3323

3424
let n = data.len();
35-
let data = data.iter().map(|(r, i)| quote!((#r, &#i)));
36-
37-
quote! {
38-
static DATA: [(&str, & #struct_type); #n] = [#(#data,)*];
39-
fn lookup(req: icu_provider::DataRequest) -> Option<&'static #struct_type> {
40-
DATA.binary_search_by(|(k, _)| req.legacy_cmp(k.as_bytes()).reverse())
41-
.map(|i| (*unsafe { DATA.get_unchecked(i) }).1)
42-
.ok()
25+
26+
if data.iter().all(|((a, _), _)| a.is_empty()) {
27+
// Only DataLocales
28+
let data = data.iter().map(|((_, l), i)| quote!((#l, &#i)));
29+
30+
quote! {
31+
static DATA: [(&str, & #struct_type); #n] = [#(#data,)*];
32+
fn lookup(req: icu_provider::DataRequest) -> Option<&'static #struct_type> {
33+
DATA.binary_search_by(|(l, _)| req.locale.strict_cmp(l.as_bytes()).reverse())
34+
.map(|i| (*unsafe { DATA.get_unchecked(i) }).1)
35+
.ok()
36+
}
37+
}
38+
} else if data.iter().all(|((_, l), _)| *l == "und") {
39+
// Only marker attributes
40+
let data = data.iter().map(|((a, _), i)| quote!((#a, &#i)));
41+
42+
quote! {
43+
static DATA: [(&str, & #struct_type); #n] = [#(#data,)*];
44+
fn lookup(req: icu_provider::DataRequest) -> Option<&'static #struct_type> {
45+
DATA.binary_search_by(|(a, _)| a.cmp(&&**req.marker_attributes))
46+
.map(|i| (*unsafe { DATA.get_unchecked(i) }).1)
47+
.ok()
48+
}
49+
}
50+
} else {
51+
let data = data.iter().map(|((a, l), i)| quote!(((#a, #l), &#i)));
52+
53+
quote! {
54+
static DATA: [((&str, &str), & #struct_type); #n] = [#(#data,)*];
55+
fn lookup(req: icu_provider::DataRequest) -> Option<&'static #struct_type> {
56+
DATA.binary_search_by(|((a, l), _)| a.cmp(&&**req.marker_attributes).then_with(|| req.locale.strict_cmp(l.as_bytes()).reverse()))
57+
.map(|i| (*unsafe { DATA.get_unchecked(i) }).1)
58+
.ok()
59+
}
4360
}
4461
}
4562
}

provider/baked/src/export.rs

Lines changed: 40 additions & 31 deletions
Original file line numberDiff line numberDiff line change
@@ -495,21 +495,16 @@ impl DataExporter for BakedExporter {
495495
let mut idents = reqs
496496
.iter()
497497
.map(|(locale, marker_attributes)| {
498-
DataRequest {
499-
locale,
500-
marker_attributes,
501-
..Default::default()
502-
}
503-
.legacy_encode()
504-
.chars()
505-
.map(|ch| {
506-
if ch == '-' {
507-
'_'
508-
} else {
509-
ch.to_ascii_uppercase()
510-
}
511-
})
512-
.collect::<String>()
498+
format!("_{}_{}", marker_attributes as &str, locale)
499+
.chars()
500+
.map(|ch| {
501+
if ch == '-' {
502+
'_'
503+
} else {
504+
ch.to_ascii_uppercase()
505+
}
506+
})
507+
.collect::<String>()
513508
})
514509
.collect::<Vec<_>>();
515510
idents.sort();
@@ -573,27 +568,41 @@ impl DataExporter for BakedExporter {
573568
}
574569
};
575570

576-
let mut legacy_encoded = deduplicated_values
571+
let reqs = deduplicated_values
577572
.values()
578573
.flat_map(|s| {
579574
s.iter().map(|(locale, marker_attributes)| {
580-
DataRequest {
581-
locale,
582-
marker_attributes,
583-
..Default::default()
584-
}
585-
.legacy_encode()
575+
(marker_attributes.to_string(), locale.to_string())
586576
})
587577
})
588-
.collect::<Vec<_>>();
589-
legacy_encoded.sort();
590-
591-
let iterable_body = quote!(Ok(
592-
[#(#legacy_encoded),*]
593-
.into_iter()
594-
.filter_map(icu_provider::DataRequest::legacy_decode)
595-
.collect()
596-
));
578+
.collect::<BTreeSet<_>>();
579+
let locales = reqs.iter().map(|(_, l)| l);
580+
let attrs = reqs.iter().map(|(a, _)| a);
581+
582+
let iterable_body = if attrs.clone().all(|a| a.is_empty()) {
583+
// Only DataLocales
584+
quote!(Ok(
585+
[#(icu_provider::_internal::locale_core::locale!(#locales)),*]
586+
.into_iter()
587+
.map(|l| (l.into(), Default::default()))
588+
.collect()
589+
))
590+
} else if locales.clone().all(|l| l == "und") {
591+
// Only attributes
592+
quote!(Ok(
593+
[#(#attrs),*]
594+
.into_iter()
595+
.map(|a| (Default::default(), a.parse().unwrap()))
596+
.collect()
597+
))
598+
} else {
599+
quote!(Ok(
600+
[#((#attrs, icu_provider::_internal::locale_core::locale!(#locales))),*]
601+
.into_iter()
602+
.map(|(a, l)| (l.into(), a.parse().unwrap()))
603+
.collect()
604+
))
605+
};
597606

598607
(load_body, iterable_body)
599608
};

0 commit comments

Comments
 (0)