Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add data loading for chinese precomputed caches #4468

Merged
merged 20 commits into from
Dec 19, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions Cargo.lock

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

9 changes: 8 additions & 1 deletion components/calendar/benches/convert.rs
Original file line number Diff line number Diff line change
Expand Up @@ -57,10 +57,17 @@ fn convert_benches(c: &mut Criterion) {
#[cfg(feature = "bench")]
bench_calendar(
&mut group,
"calendar/chinese",
"calendar/chinese_calculating",
icu::calendar::chinese::Chinese::new_always_calculating(),
);

#[cfg(feature = "bench")]
bench_calendar(
&mut group,
"calendar/chinese_cached",
icu::calendar::chinese::Chinese::new(),
);

#[cfg(feature = "bench")]
bench_calendar(
&mut group,
Expand Down
33 changes: 31 additions & 2 deletions components/calendar/benches/date.rs
Original file line number Diff line number Diff line change
Expand Up @@ -139,7 +139,7 @@ fn date_benches(c: &mut Criterion) {
#[cfg(feature = "bench")]
bench_calendar(
&mut group,
"calendar/chinese",
"calendar/chinese_calculating",
&fxs,
icu::calendar::chinese::Chinese::new_always_calculating(),
|y, m, d| {
Expand All @@ -156,7 +156,24 @@ fn date_benches(c: &mut Criterion) {
#[cfg(feature = "bench")]
bench_calendar(
&mut group,
"calendar/dangi",
"calendar/chinese_cached",
&fxs,
icu::calendar::chinese::Chinese::new(),
|y, m, d| {
Date::try_new_chinese_date_with_calendar(
y,
m,
d,
icu::calendar::chinese::Chinese::new(),
)
.unwrap()
},
);

#[cfg(feature = "bench")]
bench_calendar(
&mut group,
"calendar/dangi_calculating",
&fxs,
icu::calendar::dangi::Dangi::new_always_calculating(),
|y, m, d| {
Expand All @@ -170,6 +187,18 @@ fn date_benches(c: &mut Criterion) {
},
);

#[cfg(feature = "bench")]
bench_calendar(
&mut group,
"calendar/dangi_cached",
&fxs,
icu::calendar::dangi::Dangi::new(),
|y, m, d| {
Date::try_new_dangi_date_with_calendar(y, m, d, icu::calendar::dangi::Dangi::new())
.unwrap()
},
);

#[cfg(feature = "bench")]
bench_calendar(
&mut group,
Expand Down
22 changes: 21 additions & 1 deletion components/calendar/benches/datetime.rs
Original file line number Diff line number Diff line change
Expand Up @@ -117,7 +117,7 @@ fn datetime_benches(c: &mut Criterion) {
#[cfg(feature = "bench")]
bench_calendar(
&mut group,
"calendar/chinese",
"calendar/chinese_calculating",
&fxs,
icu::calendar::chinese::Chinese::new_always_calculating(),
|y, m, d, h, min, s| {
Expand All @@ -134,6 +134,26 @@ fn datetime_benches(c: &mut Criterion) {
},
);

#[cfg(feature = "bench")]
bench_calendar(
&mut group,
"calendar/chinese_cached",
&fxs,
icu::calendar::chinese::Chinese::new(),
|y, m, d, h, min, s| {
DateTime::try_new_chinese_datetime_with_calendar(
y,
m,
d,
h,
min,
s,
icu::calendar::chinese::Chinese::new(),
)
.unwrap()
},
);

#[cfg(feature = "bench")]
bench_calendar(
&mut group,
Expand Down
40 changes: 26 additions & 14 deletions components/calendar/src/any_calendar.rs
Original file line number Diff line number Diff line change
Expand Up @@ -575,9 +575,9 @@ impl AnyCalendar {
pub const fn new(kind: AnyCalendarKind) -> Self {
match kind {
AnyCalendarKind::Buddhist => AnyCalendar::Buddhist(Buddhist),
AnyCalendarKind::Chinese => AnyCalendar::Chinese(Chinese),
AnyCalendarKind::Chinese => AnyCalendar::Chinese(Chinese::new()),
AnyCalendarKind::Coptic => AnyCalendar::Coptic(Coptic),
AnyCalendarKind::Dangi => AnyCalendar::Dangi(Dangi),
AnyCalendarKind::Dangi => AnyCalendar::Dangi(Dangi::new()),
AnyCalendarKind::Ethiopian => AnyCalendar::Ethiopian(Ethiopian::new_with_era_style(
EthiopianEraStyle::AmeteMihret,
)),
Expand Down Expand Up @@ -613,9 +613,13 @@ impl AnyCalendar {
{
Ok(match kind {
AnyCalendarKind::Buddhist => AnyCalendar::Buddhist(Buddhist),
AnyCalendarKind::Chinese => AnyCalendar::Chinese(Chinese),
AnyCalendarKind::Chinese => {
AnyCalendar::Chinese(Chinese::try_new_with_any_provider(provider)?)
}
AnyCalendarKind::Coptic => AnyCalendar::Coptic(Coptic),
AnyCalendarKind::Dangi => AnyCalendar::Dangi(Dangi),
AnyCalendarKind::Dangi => {
AnyCalendar::Dangi(Dangi::try_new_with_any_provider(provider)?)
}
AnyCalendarKind::Ethiopian => AnyCalendar::Ethiopian(Ethiopian::new_with_era_style(
EthiopianEraStyle::AmeteMihret,
)),
Expand Down Expand Up @@ -654,9 +658,13 @@ impl AnyCalendar {
{
Ok(match kind {
AnyCalendarKind::Buddhist => AnyCalendar::Buddhist(Buddhist),
AnyCalendarKind::Chinese => AnyCalendar::Chinese(Chinese),
AnyCalendarKind::Chinese => {
AnyCalendar::Chinese(Chinese::try_new_with_buffer_provider(provider)?)
}
AnyCalendarKind::Coptic => AnyCalendar::Coptic(Coptic),
AnyCalendarKind::Dangi => AnyCalendar::Dangi(Dangi),
AnyCalendarKind::Dangi => {
AnyCalendar::Dangi(Dangi::try_new_with_buffer_provider(provider)?)
}
AnyCalendarKind::Ethiopian => AnyCalendar::Ethiopian(Ethiopian::new_with_era_style(
EthiopianEraStyle::AmeteMihret,
)),
Expand Down Expand Up @@ -689,13 +697,15 @@ impl AnyCalendar {
where
P: DataProvider<crate::provider::JapaneseErasV1Marker>
+ DataProvider<crate::provider::JapaneseExtendedErasV1Marker>
+ DataProvider<crate::provider::ChineseCacheV1Marker>
+ DataProvider<crate::provider::DangiCacheV1Marker>
+ ?Sized,
{
Ok(match kind {
AnyCalendarKind::Buddhist => AnyCalendar::Buddhist(Buddhist),
AnyCalendarKind::Chinese => AnyCalendar::Chinese(Chinese),
AnyCalendarKind::Chinese => AnyCalendar::Chinese(Chinese::try_new_unstable(provider)?),
AnyCalendarKind::Coptic => AnyCalendar::Coptic(Coptic),
AnyCalendarKind::Dangi => AnyCalendar::Dangi(Dangi),
AnyCalendarKind::Dangi => AnyCalendar::Dangi(Dangi::try_new_unstable(provider)?),
AnyCalendarKind::Ethiopian => AnyCalendar::Ethiopian(Ethiopian::new_with_era_style(
EthiopianEraStyle::AmeteMihret,
)),
Expand Down Expand Up @@ -759,6 +769,8 @@ impl AnyCalendar {
where
P: DataProvider<crate::provider::JapaneseErasV1Marker>
+ DataProvider<crate::provider::JapaneseExtendedErasV1Marker>
+ DataProvider<crate::provider::ChineseCacheV1Marker>
+ DataProvider<crate::provider::DangiCacheV1Marker>
+ ?Sized,
{
let kind = AnyCalendarKind::from_data_locale_with_fallback(locale);
Expand Down Expand Up @@ -1026,9 +1038,9 @@ impl AnyCalendarKind {
fn debug_name(self) -> &'static str {
match self {
AnyCalendarKind::Buddhist => Buddhist.debug_name(),
AnyCalendarKind::Chinese => Chinese.debug_name(),
AnyCalendarKind::Chinese => Chinese::DEBUG_NAME,
AnyCalendarKind::Coptic => Coptic.debug_name(),
AnyCalendarKind::Dangi => Dangi.debug_name(),
AnyCalendarKind::Dangi => Dangi::DEBUG_NAME,
AnyCalendarKind::Ethiopian => Ethiopian(false).debug_name(),
AnyCalendarKind::EthiopianAmeteAlem => Ethiopian(true).debug_name(),
AnyCalendarKind::Gregorian => Gregorian.debug_name(),
Expand Down Expand Up @@ -1131,10 +1143,10 @@ impl IntoAnyCalendar for Buddhist {

impl IntoAnyCalendar for Chinese {
fn to_any(self) -> AnyCalendar {
AnyCalendar::Chinese(Chinese)
AnyCalendar::Chinese(self)
}
fn to_any_cloned(&self) -> AnyCalendar {
AnyCalendar::Chinese(Chinese)
AnyCalendar::Chinese(self.clone())
}
fn date_to_any(&self, d: &Self::DateInner) -> AnyDateInner {
AnyDateInner::Chinese(*d)
Expand All @@ -1155,10 +1167,10 @@ impl IntoAnyCalendar for Coptic {

impl IntoAnyCalendar for Dangi {
fn to_any(self) -> AnyCalendar {
AnyCalendar::Dangi(Dangi)
AnyCalendar::Dangi(self)
}
fn to_any_cloned(&self) -> AnyCalendar {
AnyCalendar::Dangi(Dangi)
AnyCalendar::Dangi(self.clone())
}
fn date_to_any(&self, d: &Self::DateInner) -> AnyDateInner {
AnyDateInner::Dangi(*d)
Expand Down
Loading