From 415989a5f44631cd3d4ead37b1ae91303cc47c83 Mon Sep 17 00:00:00 2001 From: "Shane F. Carr" Date: Sat, 6 Jan 2024 00:59:13 -0600 Subject: [PATCH] Add size tests for main datetime types (#4513) --- components/datetime/src/any/date.rs | 10 +++++ components/datetime/src/any/datetime.rs | 10 +++++ components/datetime/src/any/zoned_datetime.rs | 10 +++++ components/datetime/src/datetime.rs | 28 +++++++++++++ components/datetime/src/format/neo.rs | 11 +++++ components/datetime/src/helpers.rs | 2 + components/datetime/src/neo.rs | 41 +++++++++++++++++++ components/datetime/src/neo_pattern.rs | 5 +++ 8 files changed, 117 insertions(+) diff --git a/components/datetime/src/any/date.rs b/components/datetime/src/any/date.rs index 4aab37e52c5..a7f1838261e 100644 --- a/components/datetime/src/any/date.rs +++ b/components/datetime/src/any/date.rs @@ -2,6 +2,7 @@ // called LICENSE at the top level of the ICU4X source tree // (online at: https://github.com/unicode-org/icu4x/blob/main/LICENSE ). +use crate::helpers::size_test; use crate::provider::calendar::*; use crate::{calendar, options::length, raw}; use crate::{input::DateInput, DateTimeError, FormattedDateTime}; @@ -18,6 +19,13 @@ use icu_provider::prelude::*; use icu_provider::DataLocale; use writeable::Writeable; +size_test!( + DateFormatter, + date_formatter_size, + pinned = 4600, + nightly = 4456 +); + /// [`DateFormatter`] is a formatter capable of formatting /// dates from any calendar, selected at runtime. For the difference between this and [`TypedDateFormatter`](crate::TypedDateFormatter), /// please read the [crate root docs][crate]. @@ -28,6 +36,8 @@ use writeable::Writeable; /// For that reason, one should think of the process of formatting a date in two steps - first, a computational /// heavy construction of [`DateFormatter`], and then fast formatting of [`DateTime`](icu_calendar::DateTime) data using the instance. /// +#[doc = date_formatter_size!()] +/// /// [`icu_datetime`]: crate /// /// # Examples diff --git a/components/datetime/src/any/datetime.rs b/components/datetime/src/any/datetime.rs index ff4d540bc6c..dd939e8fd93 100644 --- a/components/datetime/src/any/datetime.rs +++ b/components/datetime/src/any/datetime.rs @@ -2,6 +2,7 @@ // called LICENSE at the top level of the ICU4X source tree // (online at: https://github.com/unicode-org/icu4x/blob/main/LICENSE ). +use crate::helpers::size_test; use crate::provider::{calendar::*, date_time::PatternSelector}; use crate::{calendar, options::DateTimeFormatterOptions, raw, DateFormatter, TimeFormatter}; use crate::{input::DateTimeInput, DateTimeError, FormattedDateTime}; @@ -18,6 +19,13 @@ use icu_provider::prelude::*; use icu_provider::DataLocale; use writeable::Writeable; +size_test!( + DateTimeFormatter, + date_time_formatter_size, + pinned = 5480, + nightly = 5208 +); + /// [`DateTimeFormatter`] is a formatter capable of formatting /// date/times from any calendar, selected at runtime. For the difference between this and [`TypedDateTimeFormatter`](crate::TypedDateTimeFormatter), /// please read the [crate root docs][crate]. @@ -28,6 +36,8 @@ use writeable::Writeable; /// For that reason, one should think of the process of formatting a date in two steps - first, a computational /// heavy construction of [`DateTimeFormatter`], and then fast formatting of [`DateTime`](icu_calendar::DateTime) data using the instance. /// +#[doc = date_time_formatter_size!()] +/// /// [`icu_datetime`]: crate /// /// # Examples diff --git a/components/datetime/src/any/zoned_datetime.rs b/components/datetime/src/any/zoned_datetime.rs index 7e153c3bc6c..592824a5eb1 100644 --- a/components/datetime/src/any/zoned_datetime.rs +++ b/components/datetime/src/any/zoned_datetime.rs @@ -7,6 +7,7 @@ use alloc::string::String; use icu_provider::prelude::*; +use crate::helpers::size_test; use crate::input::{DateTimeInput, ExtractedDateTimeInput, TimeZoneInput}; use crate::provider::{self, calendar::*, date_time::PatternSelector}; use crate::time_zone::TimeZoneFormatterOptions; @@ -21,6 +22,13 @@ use icu_decimal::provider::DecimalSymbolsV1Marker; use icu_plurals::provider::OrdinalV1Marker; use writeable::Writeable; +size_test!( + ZonedDateTimeFormatter, + zoned_date_time_formatter_size, + pinned = 6520, + nightly = 6248 +); + /// [`ZonedDateTimeFormatter`] is a formatter capable of formatting /// date/times with time zones from any calendar, selected at runtime. For the difference between this and [`TypedZonedDateTimeFormatter`](crate::TypedZonedDateTimeFormatter), /// please read the [crate root docs][crate]. @@ -39,6 +47,8 @@ use writeable::Writeable; /// first, a computationally heavy construction of [`ZonedDateTimeFormatter`], and then fast formatting /// of the data using the instance. /// +#[doc = zoned_date_time_formatter_size!()] +/// /// # Examples /// /// Using a GMT time zone: diff --git a/components/datetime/src/datetime.rs b/components/datetime/src/datetime.rs index 12000f32ef9..13c719a43bc 100644 --- a/components/datetime/src/datetime.rs +++ b/components/datetime/src/datetime.rs @@ -6,6 +6,7 @@ //! Central to this is the [`TypedDateTimeFormatter`]. use crate::{ + helpers::size_test, options::{length, preferences, DateTimeFormatterOptions}, provider::calendar::{TimeLengthsV1Marker, TimeSymbolsV1Marker}, provider::date_time::PatternSelector, @@ -24,6 +25,13 @@ use crate::{ DateTimeError, FormattedDateTime, }; +size_test!( + TimeFormatter, + time_formatter_size, + pinned = 1328, + nightly = 1200 +); + /// [`TimeFormatter`] is a structure of the [`icu_datetime`] component that provides time formatting only. /// When constructed, it uses data from the [data provider], selected locale and provided preferences to /// collect all data necessary to format any time into that locale. @@ -31,6 +39,8 @@ use crate::{ /// For that reason, one should think of the process of formatting a time in two steps - first, a computational /// heavy construction of [`TimeFormatter`], and then fast formatting of [`DateTimeInput`] data using the instance. /// +#[doc = time_formatter_size!()] +/// /// [`icu_datetime`]: crate /// [`TypedDateTimeFormatter`]: crate::datetime::TimeFormatter /// @@ -178,6 +188,13 @@ impl TimeFormatter { } } +size_test!( + TypedDateFormatter, + typed_date_formatter_size, + pinned = 4544, + nightly = 4400 +); + /// [`TypedDateFormatter`] is a formatter capable of formatting /// dates from a calendar selected at compile time. For the difference between this /// and [`DateFormatter`](crate::DateFormatter), please read the [crate root docs][crate]. @@ -188,6 +205,8 @@ impl TimeFormatter { /// For that reason, one should think of the process of formatting a date in two steps - first, a computational /// heavy construction of [`TypedDateFormatter`], and then fast formatting of [`DateInput`] data using the instance. /// +#[doc = typed_date_formatter_size!()] +/// /// [`icu_datetime`]: crate /// /// # Examples @@ -390,6 +409,13 @@ impl TypedDateFormatter { } } +size_test!( + TypedDateTimeFormatter, + typed_date_time_formatter_size, + pinned = 5424, + nightly = 5152 +); + /// [`TypedDateTimeFormatter`] is a formatter capable of formatting /// date/times from a calendar selected at compile time. For the difference between this /// and [`DateTimeFormatter`](crate::DateTimeFormatter), please read the [crate root docs][crate]. @@ -400,6 +426,8 @@ impl TypedDateFormatter { /// For that reason, one should think of the process of formatting a date in two steps - first, a computational /// heavy construction of [`TypedDateTimeFormatter`], and then fast formatting of [`DateInput`] data using the instance. /// +#[doc = typed_date_time_formatter_size!()] +/// /// [`icu_datetime`]: crate /// [`TypedDateTimeFormatter`]: crate::datetime::TypedDateTimeFormatter /// diff --git a/components/datetime/src/format/neo.rs b/components/datetime/src/format/neo.rs index 6ac909a8519..0a6892db8b6 100644 --- a/components/datetime/src/format/neo.rs +++ b/components/datetime/src/format/neo.rs @@ -7,6 +7,7 @@ use crate::calendar::CldrCalendar; use crate::error::DateTimeError as Error; use crate::external_loaders::*; use crate::fields::{self, FieldLength, FieldSymbol}; +use crate::helpers::size_test; use crate::input; use crate::input::DateInput; use crate::input::DateTimeInput; @@ -115,7 +116,17 @@ impl DataProvider for PhantomProvider { } } +size_test!( + TypedDateTimeNames, + typed_date_time_names_size, + pinned = 504, + nightly = 488 +); + /// A low-level type that formats datetime patterns with localized symbols. +/// The calendar should be chosen at compile time. +/// +#[doc = typed_date_time_names_size!()] /// ///
/// 🚧 This code is experimental; it may change at any time, in breaking or non-breaking ways, diff --git a/components/datetime/src/helpers.rs b/components/datetime/src/helpers.rs index c7653e75811..da4f211dc61 100644 --- a/components/datetime/src/helpers.rs +++ b/components/datetime/src/helpers.rs @@ -83,3 +83,5 @@ macro_rules! size_test { } }; } + +pub(crate) use size_test; diff --git a/components/datetime/src/neo.rs b/components/datetime/src/neo.rs index 773345986d4..4c92566ea34 100644 --- a/components/datetime/src/neo.rs +++ b/components/datetime/src/neo.rs @@ -60,6 +60,20 @@ macro_rules! gen_any_buffer_constructors_with_external_loader { }; } +size_test!( + TypedNeoDateFormatter, + typed_neo_date_formatter_size, + pinned = 512, + nightly = 496 +); + +/// [`TypedNeoDateFormatter`] can format dates from a calendar selected at compile time. +/// +/// For the difference between this and [`DateFormatter`](crate::DateFormatter), please +/// read the [crate root docs][crate]. +/// +#[doc = typed_neo_date_formatter_size!()] +/// ///
/// 🚧 This code is experimental; it may change at any time, in breaking or non-breaking ways, /// including in SemVer minor releases. It can be enabled with the "experimental" Cargo feature @@ -231,6 +245,18 @@ impl<'a> FormattedNeoDate<'a> { } } +size_test!( + NeoTimeFormatter, + neo_time_formatter_size, + pinned = 464, + nightly = 448 +); + +/// [`NeoTimeFormatter`] can format times of day. +/// It supports both 12-hour and 24-hour formats. +/// +#[doc = neo_time_formatter_size!()] +/// ///
/// 🚧 This code is experimental; it may change at any time, in breaking or non-breaking ways, /// including in SemVer minor releases. It can be enabled with the "experimental" Cargo feature @@ -385,6 +411,21 @@ impl<'a> FormattedNeoTime<'a> { } } +size_test!( + TypedNeoDateTimeFormatter, + neo_date_time_formatter_size, + pinned = 584, + nightly = 568 +); + +/// [`TypedNeoDateTimeFormatter`] can format dates with times of day. The dates must be in +/// a calendar system determined at compile time. +/// +/// For the difference between this and [`DateTimeFormatter`](crate::DateTimeFormatter), please +/// read the [crate root docs][crate]. +/// +#[doc = neo_date_time_formatter_size!()] +/// ///
/// 🚧 This code is experimental; it may change at any time, in breaking or non-breaking ways, /// including in SemVer minor releases. It can be enabled with the "experimental" Cargo feature diff --git a/components/datetime/src/neo_pattern.rs b/components/datetime/src/neo_pattern.rs index 0af447a3fcd..f1d011c5baf 100644 --- a/components/datetime/src/neo_pattern.rs +++ b/components/datetime/src/neo_pattern.rs @@ -6,8 +6,11 @@ use core::str::FromStr; +use crate::helpers::size_test; use crate::pattern::{runtime, PatternError, PatternItem}; +size_test!(DateTimePattern, date_time_pattern_size, 32); + /// A pattern for formatting a datetime in a calendar. /// /// Most clients should use [`DateTimeFormatter`] instead of directly @@ -18,6 +21,8 @@ use crate::pattern::{runtime, PatternError, PatternItem}; /// 1. From a custom pattern string: [`DateTimePattern::try_from_pattern_str`] /// 2. From a formatted datetime: [`FormattedNeoDateTime::pattern`] /// +#[doc = date_time_pattern_size!()] +/// /// # Examples /// /// Create a pattern from a custom string and compare it to one from data: