-
Notifications
You must be signed in to change notification settings - Fork 183
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
Datagen: Cache supported_locales impls #4470
Changes from 5 commits
97628fe
2072a64
a2c51de
7be9f01
245d442
ab39def
11a1ed1
f2de286
6ccfc92
14add37
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -7,6 +7,8 @@ | |
use crate::source::*; | ||
use crate::transform::cldr::source::CldrCache; | ||
use crate::{CollationHanDatabase, CoverageLevel}; | ||
use elsa::sync::FrozenMap; | ||
use icu_provider::datagen::IterableDataProvider; | ||
use icu_provider::prelude::*; | ||
use std::fmt::Debug; | ||
use std::path::PathBuf; | ||
|
@@ -78,6 +80,7 @@ impl DatagenProvider { | |
icuexport_dictionary_fallback: None, | ||
#[cfg(feature = "legacy_api")] | ||
collations: Default::default(), | ||
supported_locales_cache_vec: Default::default(), | ||
}, | ||
} | ||
} | ||
|
@@ -306,6 +309,28 @@ pub struct SourceData { | |
pub(crate) icuexport_dictionary_fallback: Option<Arc<SerdeCache>>, | ||
#[cfg(feature = "legacy_api")] | ||
pub(crate) collations: Vec<String>, | ||
pub(crate) supported_locales_cache_vec: | ||
FrozenMapThrowawayClone<DataKey, Box<Result<Vec<DataLocale>, DataError>>>, | ||
} | ||
|
||
pub(crate) struct FrozenMapThrowawayClone<K, V>(pub(crate) FrozenMap<K, V>); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I believe There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. It does for There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Upgraded to elsa 1.10 |
||
|
||
impl<K, V> Default for FrozenMapThrowawayClone<K, V> { | ||
fn default() -> Self { | ||
Self(FrozenMap::new()) | ||
} | ||
} | ||
|
||
impl<K, V> Clone for FrozenMapThrowawayClone<K, V> { | ||
fn clone(&self) -> Self { | ||
Default::default() | ||
} | ||
} | ||
|
||
impl<K, V> Debug for FrozenMapThrowawayClone<K, V> { | ||
fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result { | ||
write!(f, "FrozenMap") | ||
} | ||
} | ||
|
||
#[cfg(feature = "legacy_api")] | ||
|
@@ -485,3 +510,34 @@ impl SourceData { | |
.locales(levels.iter().copied()) | ||
} | ||
} | ||
|
||
pub(crate) trait IterableDataProviderInternal<M: KeyedDataMarker>: DataProvider<M> { | ||
fn supported_locales_impl(&self) -> Result<Vec<DataLocale>, DataError>; | ||
} | ||
|
||
impl<M: KeyedDataMarker> IterableDataProvider<M> for DatagenProvider | ||
where | ||
DatagenProvider: IterableDataProviderInternal<M>, | ||
{ | ||
fn supported_locales(&self) -> Result<Vec<DataLocale>, DataError> { | ||
#[allow(deprecated)] // SourceData | ||
self.source | ||
.supported_locales_cache_vec | ||
.0 | ||
.insert_with(M::KEY, || Box::from(self.supported_locales_impl())) | ||
.as_ref() | ||
.cloned() | ||
.map_err(|e| *e) | ||
} | ||
|
||
fn supports_locale(&self, locale: &DataLocale) -> Result<bool, DataError> { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. |
||
#[allow(deprecated)] // SourceData | ||
self.source | ||
.supported_locales_cache_vec | ||
.0 | ||
.insert_with(M::KEY, || Box::from(self.supported_locales_impl())) | ||
.as_ref() | ||
.map_err(|e| *e) | ||
.map(|v| v.contains(locale)) | ||
} | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Use an
Arc
?There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Switched to Arc