Skip to content

Commit

Permalink
Merge branch 'main' into normalizerdata
Browse files Browse the repository at this point in the history
  • Loading branch information
hsivonen authored Nov 14, 2024
2 parents 852834c + ef5fda1 commit 29435a2
Show file tree
Hide file tree
Showing 61 changed files with 765 additions and 754 deletions.
2 changes: 2 additions & 0 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion components/datetime/src/external_loaders.rs
Original file line number Diff line number Diff line change
Expand Up @@ -113,7 +113,7 @@ pub(crate) struct ExternalLoaderUnstable<'a, P: ?Sized>(pub &'a P);

impl<P> FixedDecimalFormatterLoader for ExternalLoaderUnstable<'_, P>
where
P: ?Sized + DataProvider<icu_decimal::provider::DecimalSymbolsV1Marker>,
P: ?Sized + DataProvider<icu_decimal::provider::DecimalSymbolsV2Marker>,
{
#[inline]
fn load(
Expand Down
10 changes: 5 additions & 5 deletions components/datetime/src/format/neo.rs
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ use icu_calendar::types::FormattingEra;
use icu_calendar::types::MonthCode;
use icu_decimal::options::FixedDecimalFormatterOptions;
use icu_decimal::options::GroupingStrategy;
use icu_decimal::provider::DecimalSymbolsV1Marker;
use icu_decimal::provider::DecimalSymbolsV2Marker;
use icu_decimal::FixedDecimalFormatter;
use icu_provider::marker::NeverMarker;
use icu_provider::prelude::*;
Expand Down Expand Up @@ -262,7 +262,7 @@ where
size_test!(
TypedDateTimeNames<icu_calendar::Gregorian, DateTimeMarker>,
typed_date_time_names_size,
456
336
);

/// A low-level type that formats datetime patterns with localized names.
Expand Down Expand Up @@ -625,7 +625,7 @@ impl<C: CldrCalendar, R: DateTimeNamesMarker> TypedDateTimeNames<C, R> {
#[doc = icu_provider::gen_any_buffer_unstable_docs!(UNSTABLE, Self::try_new)]
pub fn try_new_unstable<P>(provider: &P, locale: &DataLocale) -> Result<Self, DataError>
where
P: DataProvider<DecimalSymbolsV1Marker> + ?Sized,
P: DataProvider<DecimalSymbolsV2Marker> + ?Sized,
{
let mut names = Self {
locale: locale.clone(),
Expand Down Expand Up @@ -1418,7 +1418,7 @@ impl<C: CldrCalendar, R: DateTimeNamesMarker> TypedDateTimeNames<C, R> {
#[inline]
pub fn load_fixed_decimal_formatter<P>(&mut self, provider: &P) -> Result<&mut Self, DataError>
where
P: DataProvider<DecimalSymbolsV1Marker> + ?Sized,
P: DataProvider<DecimalSymbolsV2Marker> + ?Sized,
{
self.inner
.load_fixed_decimal_formatter(&ExternalLoaderUnstable(provider), &self.locale)?;
Expand Down Expand Up @@ -1497,7 +1497,7 @@ impl<C: CldrCalendar, R: DateTimeNamesMarker> TypedDateTimeNames<C, R> {
+ DataProvider<tz::MzSpecificLongV1Marker>
+ DataProvider<tz::MzSpecificShortV1Marker>
+ DataProvider<tz::MzPeriodV1Marker>
+ DataProvider<DecimalSymbolsV1Marker>
+ DataProvider<DecimalSymbolsV2Marker>
+ ?Sized,
{
let locale = &self.locale;
Expand Down
4 changes: 2 additions & 2 deletions components/datetime/src/neo.rs
Original file line number Diff line number Diff line change
Expand Up @@ -132,7 +132,7 @@ macro_rules! gen_any_buffer_constructors_with_external_loader {
// }
// }

size_test!(FixedCalendarDateTimeFormatter<icu_calendar::Gregorian, crate::fieldset::YMD>, typed_neo_year_month_day_formatter_size, 456);
size_test!(FixedCalendarDateTimeFormatter<icu_calendar::Gregorian, crate::fieldset::YMD>, typed_neo_year_month_day_formatter_size, 336);

/// [`FixedCalendarDateTimeFormatter`] is a formatter capable of formatting dates and/or times from
/// a calendar selected at compile time.
Expand Down Expand Up @@ -352,7 +352,7 @@ where
size_test!(
DateTimeFormatter<crate::fieldset::YMD>,
neo_year_month_day_formatter_size,
512
392
);

/// [`DateTimeFormatter`] is a formatter capable of formatting dates and/or times from
Expand Down
10 changes: 5 additions & 5 deletions components/datetime/src/scaffold/fieldset_traits.rs
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ use icu_calendar::{
},
Date, Iso, Time,
};
use icu_decimal::provider::DecimalSymbolsV1Marker;
use icu_decimal::provider::DecimalSymbolsV2Marker;
use icu_provider::{marker::NeverMarker, prelude::*};
use icu_timezone::scaffold::IntoOption;
use icu_timezone::{TimeZoneBcp47Id, UtcOffset, ZoneVariant};
Expand Down Expand Up @@ -368,10 +368,10 @@ where

/// Trait to consolidate data provider markers external to this crate
/// for datetime formatting with a fixed calendar.
pub trait AllFixedCalendarExternalDataMarkers: DataProvider<DecimalSymbolsV1Marker> {}
pub trait AllFixedCalendarExternalDataMarkers: DataProvider<DecimalSymbolsV2Marker> {}

impl<T> AllFixedCalendarExternalDataMarkers for T where
T: ?Sized + DataProvider<DecimalSymbolsV1Marker>
T: ?Sized + DataProvider<DecimalSymbolsV2Marker>
{
}

Expand All @@ -384,7 +384,7 @@ pub trait AllAnyCalendarExternalDataMarkers:
+ DataProvider<IslamicUmmAlQuraCacheV1Marker>
+ DataProvider<JapaneseErasV1Marker>
+ DataProvider<JapaneseExtendedErasV1Marker>
+ DataProvider<DecimalSymbolsV1Marker>
+ DataProvider<DecimalSymbolsV2Marker>
{
}

Expand All @@ -396,7 +396,7 @@ impl<T> AllAnyCalendarExternalDataMarkers for T where
+ DataProvider<IslamicUmmAlQuraCacheV1Marker>
+ DataProvider<JapaneseErasV1Marker>
+ DataProvider<JapaneseExtendedErasV1Marker>
+ DataProvider<DecimalSymbolsV1Marker>
+ DataProvider<DecimalSymbolsV2Marker>
{
}

Expand Down
2 changes: 1 addition & 1 deletion components/datetime/tests/data/gen.sh
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ GregorianDateLengthsV1Marker \
GregorianDateSymbolsV1Marker \
TimeLengthsV1Marker \
TimeSymbolsV1Marker \
DecimalSymbolsV1Marker \
DecimalSymbolsV2Marker \
TimeZoneFormatsV1Marker \
MetazoneSpecificNamesShortV1Marker \
--locales en \
Expand Down
6 changes: 3 additions & 3 deletions components/decimal/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ displaydoc = { workspace = true }
fixed_decimal = { workspace = true }
icu_provider = { workspace = true, features = ["macros"] }
writeable = { workspace = true }

zerovec = { workspace = true }
databake = { workspace = true, features = ["derive"], optional = true}
serde = { workspace = true, features = ["derive", "alloc"], optional = true }

Expand All @@ -46,8 +46,8 @@ criterion = { workspace = true }
[features]
default = ["compiled_data"]
std = ["fixed_decimal/std", "icu_locale_core/std", "icu_provider/std"]
serde = ["dep:serde", "icu_provider/serde"]
datagen = ["serde", "dep:databake"]
serde = ["dep:serde", "icu_provider/serde", "zerovec/serde"]
datagen = ["serde", "dep:databake", "zerovec/databake"]
bench = ["serde"]
compiled_data = ["dep:icu_decimal_data"]

Expand Down
13 changes: 11 additions & 2 deletions components/decimal/benches/fixed_decimal_format.rs
Original file line number Diff line number Diff line change
Expand Up @@ -9,8 +9,10 @@ use rand_pcg::Lcg64Xsh32;
use criterion::{black_box, criterion_group, criterion_main, Criterion};

use fixed_decimal::FixedDecimal;
use icu_decimal::provider::DecimalSymbolsV1Marker;
use icu_decimal::provider::{Baked, DecimalSymbolsV2Marker};
use icu_decimal::FixedDecimalFormatter;
use icu_locale_core::locale;
use icu_provider::prelude::*;
use icu_provider_adapters::fixed::FixedProvider;

fn triangular_nums(range: f64) -> Vec<isize> {
Expand All @@ -26,7 +28,14 @@ fn triangular_nums(range: f64) -> Vec<isize> {

fn overview_bench(c: &mut Criterion) {
let nums = triangular_nums(1e9);
let provider = FixedProvider::<DecimalSymbolsV1Marker>::new_default();
let data = Baked
.load(DataRequest {
id: DataIdentifierBorrowed::for_locale(&locale!("en-US").into()),
..Default::default()
})
.unwrap()
.payload;
let provider = FixedProvider::<DecimalSymbolsV2Marker>::from_payload(data);
c.bench_function("icu_decimal/overview", |b| {
b.iter(|| {
// This benchmark demonstrates the performance of the format function on 1000 numbers
Expand Down
17 changes: 9 additions & 8 deletions components/decimal/src/format.rs
Original file line number Diff line number Diff line change
Expand Up @@ -17,15 +17,16 @@ use writeable::Writeable;
pub struct FormattedFixedDecimal<'l> {
pub(crate) value: &'l FixedDecimal,
pub(crate) options: &'l FixedDecimalFormatterOptions,
pub(crate) symbols: &'l DecimalSymbolsV1<'l>,
pub(crate) symbols: &'l DecimalSymbolsV2<'l>,
}

impl FormattedFixedDecimal<'_> {
fn get_affixes(&self) -> Option<&AffixesV1> {
/// Returns the affixes needed for the current sign, as (prefix, suffix)
fn get_affixes(&self) -> Option<(&str, &str)> {
match self.value.sign() {
Sign::None => None,
Sign::Negative => Some(&self.symbols.minus_sign_affixes),
Sign::Positive => Some(&self.symbols.plus_sign_affixes),
Sign::Negative => Some(self.symbols.minus_sign_affixes()),
Sign::Positive => Some(self.symbols.plus_sign_affixes()),
}
}
}
Expand All @@ -37,13 +38,13 @@ impl Writeable for FormattedFixedDecimal<'_> {
{
let affixes = self.get_affixes();
if let Some(affixes) = affixes {
sink.write_str(&affixes.prefix)?;
sink.write_str(affixes.0)?;
}
let range = self.value.magnitude_range();
let upper_magnitude = *range.end();
for m in range.rev() {
if m == -1 {
sink.write_str(&self.symbols.decimal_separator)?;
sink.write_str(self.symbols.decimal_separator())?;
}
#[allow(clippy::indexing_slicing)] // digit_at in 0..=9
sink.write_char(self.symbols.digits[self.value.digit_at(m) as usize])?;
Expand All @@ -53,11 +54,11 @@ impl Writeable for FormattedFixedDecimal<'_> {
self.options.grouping_strategy,
&self.symbols.grouping_sizes,
) {
sink.write_str(&self.symbols.grouping_separator)?;
sink.write_str(self.symbols.grouping_separator())?;
}
}
if let Some(affixes) = affixes {
sink.write_str(&affixes.suffix)?;
sink.write_str(affixes.1)?;
}
Ok(())
}
Expand Down
6 changes: 3 additions & 3 deletions components/decimal/src/grouper.rs
Original file line number Diff line number Diff line change
Expand Up @@ -154,10 +154,10 @@ fn test_grouper() {
for cas in &cases {
for i in 0..4 {
let dec = FixedDecimal::from(1).multiplied_pow10((i as i16) + 3);
let provider = FixedProvider::<DecimalSymbolsV1Marker>::from_owned(
crate::provider::DecimalSymbolsV1 {
let provider = FixedProvider::<DecimalSymbolsV2Marker>::from_owned(
crate::provider::DecimalSymbolsV2 {
grouping_sizes: cas.sizes,
..Default::default()
..DecimalSymbolsV2::new_en_for_testing()
},
);
let options = options::FixedDecimalFormatterOptions {
Expand Down
6 changes: 3 additions & 3 deletions components/decimal/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -104,7 +104,7 @@ use icu_provider::prelude::*;
use size_test_macro::size_test;
use writeable::Writeable;

size_test!(FixedDecimalFormatter, fixed_decimal_formatter_size, 208);
size_test!(FixedDecimalFormatter, fixed_decimal_formatter_size, 88);

/// A formatter for [`FixedDecimal`], rendering decimal digits in an i18n-friendly way.
///
Expand All @@ -122,7 +122,7 @@ size_test!(FixedDecimalFormatter, fixed_decimal_formatter_size, 208);
#[derive(Debug)]
pub struct FixedDecimalFormatter {
options: options::FixedDecimalFormatterOptions,
symbols: DataPayload<provider::DecimalSymbolsV1Marker>,
symbols: DataPayload<provider::DecimalSymbolsV2Marker>,
}

impl AsRef<FixedDecimalFormatter> for FixedDecimalFormatter {
Expand All @@ -138,7 +138,7 @@ impl FixedDecimalFormatter {
);

#[doc = icu_provider::gen_any_buffer_unstable_docs!(UNSTABLE, Self::try_new)]
pub fn try_new_unstable<D: DataProvider<provider::DecimalSymbolsV1Marker> + ?Sized>(
pub fn try_new_unstable<D: DataProvider<provider::DecimalSymbolsV2Marker> + ?Sized>(
provider: &D,
locale: &DataLocale,
options: options::FixedDecimalFormatterOptions,
Expand Down
Loading

0 comments on commit 29435a2

Please sign in to comment.