Skip to content

Commit

Permalink
Baked data for icu_datetime (#3591)
Browse files Browse the repository at this point in the history
  • Loading branch information
robertbastian authored Jun 28, 2023
1 parent 0d4ddf8 commit 7e2733d
Show file tree
Hide file tree
Showing 24 changed files with 1,166 additions and 790 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.

5 changes: 5 additions & 0 deletions components/datetime/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ categories = ["internationalization"]
# Keep this in sync with other crates unless there are exceptions
include = [
"src/**/*",
"data/*",
"examples/**/*",
"benches/**/*",
"tests/**/*",
Expand Down Expand Up @@ -46,6 +47,9 @@ zerovec = { version = "0.9.4", path = "../../utils/zerovec", features = ["yoke"]
serde = { version = "1.0", default-features = false, features = ["derive", "alloc"], optional = true }
databake = { version = "0.1.3", path = "../../utils/databake", features = ["derive"], optional = true}

icu_datetime_data = { path = "data", optional = true }
icu_locid_transform = { path = "../../components/locid_transform", features = ["data"], optional = true }

# Experimental
litemap = { version = "0.7.0", path = "../../utils/litemap", optional = true }

Expand Down Expand Up @@ -94,6 +98,7 @@ datagen = [
]
experimental = ["dep:litemap"]
bench = ["serde"]
data = ["dep:icu_datetime_data", "dep:icu_locid_transform", "icu_calendar/data", "icu_decimal/data", "icu_plurals/data", "icu_timezone/data"]

[lib]
path = "src/lib.rs"
Expand Down
9 changes: 3 additions & 6 deletions components/datetime/README.md

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

72 changes: 23 additions & 49 deletions components/datetime/benches/datetime.rs
Original file line number Diff line number Diff line change
Expand Up @@ -13,9 +13,6 @@ use icu_datetime::{time_zone::TimeZoneFormatterOptions, TypedZonedDateTimeFormat
use icu_locid::Locale;
use icu_timezone::CustomTimeZone;

#[cfg(feature = "experimental")]
use icu_provider::AsDeserializingBufferProvider;

#[path = "../tests/mock.rs"]
mod mock;

Expand All @@ -39,17 +36,15 @@ fn datetime_benches(c: &mut Criterion) {
let options = fixtures::get_options(&setup.options).unwrap();
#[cfg(feature = "experimental")]
let dtf = {
TypedDateTimeFormatter::<Gregorian>::try_new_experimental_unstable(
&icu_testdata::buffer().as_deserializing(),
TypedDateTimeFormatter::<Gregorian>::try_new_experimental(
&locale.into(),
options.clone(),
)
.expect("Failed to create TypedDateTimeFormatter.")
};
#[cfg(not(feature = "experimental"))]
let dtf = {
TypedDateTimeFormatter::<Gregorian>::try_new_unstable(
&icu_testdata::unstable(),
TypedDateTimeFormatter::<Gregorian>::try_new(
&locale.into(),
options.clone(),
)
Expand Down Expand Up @@ -86,8 +81,7 @@ fn datetime_benches(c: &mut Criterion) {
for setup in &fx.setups {
let locale: Locale = setup.locale.parse().unwrap();
let options = fixtures::get_options(&setup.options).unwrap();
let dtf = TypedZonedDateTimeFormatter::<Gregorian>::try_new_unstable(
&icu_testdata::unstable(),
let dtf = TypedZonedDateTimeFormatter::<Gregorian>::try_new(
&locale.into(),
options,
TimeZoneFormatterOptions::default(),
Expand Down Expand Up @@ -127,12 +121,9 @@ fn datetime_benches(c: &mut Criterion) {
for setup in &fx.setups {
let locale: Locale = setup.locale.parse().unwrap();
let options = fixtures::get_options(&setup.options).unwrap();
let dtf = TypedDateTimeFormatter::<Gregorian>::try_new_unstable(
&icu_testdata::unstable(),
&locale.into(),
options,
)
.unwrap();
let dtf =
TypedDateTimeFormatter::<Gregorian>::try_new(&locale.into(), options)
.unwrap();

let mut scratch = String::new();

Expand All @@ -157,12 +148,9 @@ fn datetime_benches(c: &mut Criterion) {
for setup in &fx.setups {
let locale: Locale = setup.locale.parse().unwrap();
let options = fixtures::get_options(&setup.options).unwrap();
let dtf = TypedDateTimeFormatter::<Gregorian>::try_new_unstable(
&icu_testdata::unstable(),
&locale.into(),
options,
)
.unwrap();
let dtf =
TypedDateTimeFormatter::<Gregorian>::try_new(&locale.into(), options)
.unwrap();

for dt in &datetimes {
let _ = dtf.format_to_string(dt);
Expand All @@ -184,12 +172,9 @@ fn datetime_benches(c: &mut Criterion) {
for setup in &fx.setups {
let locale: Locale = setup.locale.parse().unwrap();
let options = fixtures::get_options(&setup.options).unwrap();
let dtf = TypedDateTimeFormatter::<Gregorian>::try_new_unstable(
&icu_testdata::unstable(),
&locale.into(),
options,
)
.unwrap();
let dtf =
TypedDateTimeFormatter::<Gregorian>::try_new(&locale.into(), options)
.unwrap();

let mut result = String::new();

Expand All @@ -215,12 +200,9 @@ fn datetime_benches(c: &mut Criterion) {
for setup in &fx.setups {
let locale: Locale = setup.locale.parse().unwrap();
let options = fixtures::get_options(&setup.options).unwrap();
let dtf = TypedDateTimeFormatter::<Gregorian>::try_new_unstable(
&icu_testdata::unstable(),
&locale.into(),
options,
)
.unwrap();
let dtf =
TypedDateTimeFormatter::<Gregorian>::try_new(&locale.into(), options)
.unwrap();

for dt in &datetimes {
let fdt = dtf.format(dt);
Expand All @@ -243,12 +225,9 @@ fn datetime_benches(c: &mut Criterion) {
for setup in &fx.setups {
let locale: Locale = setup.locale.parse().unwrap();
let options = fixtures::get_options(&setup.options).unwrap();
let dtf = TypedDateTimeFormatter::<Gregorian>::try_new_unstable(
&icu_testdata::unstable(),
&locale.into(),
options,
)
.unwrap();
let dtf =
TypedDateTimeFormatter::<Gregorian>::try_new(&locale.into(), options)
.unwrap();

for dt in &datetimes {
let fdt = dtf.format(dt);
Expand All @@ -272,8 +251,7 @@ fn datetime_benches(c: &mut Criterion) {
for setup in &fx.setups {
let locale: Locale = setup.locale.parse().unwrap();
let options = fixtures::get_options(&setup.options).unwrap();
let dtf = TypedZonedDateTimeFormatter::<Gregorian>::try_new_unstable(
&icu_testdata::unstable(),
let dtf = TypedZonedDateTimeFormatter::<Gregorian>::try_new(
&locale.into(),
options,
TimeZoneFormatterOptions::default(),
Expand Down Expand Up @@ -303,8 +281,7 @@ fn datetime_benches(c: &mut Criterion) {
for setup in &fx.setups {
let locale: Locale = setup.locale.parse().unwrap();
let options = fixtures::get_options(&setup.options).unwrap();
let dtf = TypedZonedDateTimeFormatter::<Gregorian>::try_new_unstable(
&icu_testdata::unstable(),
let dtf = TypedZonedDateTimeFormatter::<Gregorian>::try_new(
&locale.into(),
options,
TimeZoneFormatterOptions::default(),
Expand All @@ -331,8 +308,7 @@ fn datetime_benches(c: &mut Criterion) {
for setup in &fx.setups {
let locale: Locale = setup.locale.parse().unwrap();
let options = fixtures::get_options(&setup.options).unwrap();
let dtf = TypedZonedDateTimeFormatter::<Gregorian>::try_new_unstable(
&icu_testdata::unstable(),
let dtf = TypedZonedDateTimeFormatter::<Gregorian>::try_new(
&locale.into(),
options,
TimeZoneFormatterOptions::default(),
Expand Down Expand Up @@ -363,8 +339,7 @@ fn datetime_benches(c: &mut Criterion) {
for setup in &fx.setups {
let locale: Locale = setup.locale.parse().unwrap();
let options = fixtures::get_options(&setup.options).unwrap();
let dtf = TypedZonedDateTimeFormatter::<Gregorian>::try_new_unstable(
&icu_testdata::unstable(),
let dtf = TypedZonedDateTimeFormatter::<Gregorian>::try_new(
&locale.into(),
options,
TimeZoneFormatterOptions::default(),
Expand Down Expand Up @@ -392,8 +367,7 @@ fn datetime_benches(c: &mut Criterion) {
for setup in &fx.setups {
let locale: Locale = setup.locale.parse().unwrap();
let options = fixtures::get_options(&setup.options).unwrap();
let dtf = TypedZonedDateTimeFormatter::<Gregorian>::try_new_unstable(
&icu_testdata::unstable(),
let dtf = TypedZonedDateTimeFormatter::<Gregorian>::try_new(
&locale.into(),
options,
TimeZoneFormatterOptions::default(),
Expand Down
8 changes: 2 additions & 6 deletions components/datetime/examples/work_log.rs
Original file line number Diff line number Diff line change
Expand Up @@ -51,12 +51,8 @@ fn main(_argc: isize, _argv: *const *const u8) -> isize {
options.date = Some(length::Date::Medium);
options.time = Some(length::Time::Short);

let dtf = TypedDateTimeFormatter::<Gregorian>::try_new_unstable(
&icu_testdata::unstable(),
&locale!("en").into(),
options.into(),
)
.expect("Failed to create TypedDateTimeFormatter instance.");
let dtf = TypedDateTimeFormatter::<Gregorian>::try_new(&locale!("en").into(), options.into())
.expect("Failed to create TypedDateTimeFormatter instance.");
{
print("\n====== Work Log (en) example ============", None);

Expand Down
Loading

0 comments on commit 7e2733d

Please sign in to comment.