Skip to content

Commit f2de286

Browse files
committed
HashSet
1 parent 11a1ed1 commit f2de286

File tree

1 file changed

+14
-7
lines changed

1 file changed

+14
-7
lines changed

provider/datagen/src/provider.rs

+14-7
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@ use crate::{CollationHanDatabase, CoverageLevel};
1010
use elsa::sync::FrozenMap;
1111
use icu_provider::datagen::IterableDataProvider;
1212
use icu_provider::prelude::*;
13+
use std::collections::HashSet;
1314
use std::fmt::Debug;
1415
use std::path::PathBuf;
1516
use std::sync::Arc;
@@ -80,7 +81,7 @@ impl DatagenProvider {
8081
icuexport_dictionary_fallback: None,
8182
#[cfg(feature = "legacy_api")]
8283
collations: Default::default(),
83-
supported_locales_cache_vec: Default::default(),
84+
supported_locales_cache: Default::default(),
8485
},
8586
}
8687
}
@@ -262,15 +263,20 @@ impl DatagenProvider {
262263
self.cldr()?.locales(levels)
263264
}
264265

265-
pub(crate) fn supported_locales_vec<M>(&self) -> Result<&Vec<DataLocale>, DataError>
266+
pub(crate) fn supported_locales_vec<M>(&self) -> Result<&HashSet<DataLocale>, DataError>
266267
where
267268
M: KeyedDataMarker,
268269
Self: IterableDataProviderInternal<M>,
269270
{
270271
#[allow(deprecated)] // SourceData
271272
self.source
272-
.supported_locales_cache_vec
273-
.insert_with(M::KEY, || Box::from(self.supported_locales_impl()))
273+
.supported_locales_cache
274+
.insert_with(M::KEY, || {
275+
Box::new(
276+
self.supported_locales_impl()
277+
.map(|v| v.into_iter().collect()),
278+
)
279+
})
274280
.as_ref()
275281
.map_err(|e| *e)
276282
}
@@ -322,8 +328,8 @@ pub struct SourceData {
322328
pub(crate) icuexport_dictionary_fallback: Option<Arc<SerdeCache>>,
323329
#[cfg(feature = "legacy_api")]
324330
pub(crate) collations: Vec<String>,
325-
pub(crate) supported_locales_cache_vec:
326-
Arc<FrozenMap<DataKey, Box<Result<Vec<DataLocale>, DataError>>>>,
331+
pub(crate) supported_locales_cache:
332+
Arc<FrozenMap<DataKey, Box<Result<HashSet<DataLocale>, DataError>>>>,
327333
}
328334

329335
#[cfg(feature = "legacy_api")]
@@ -513,7 +519,8 @@ where
513519
DatagenProvider: IterableDataProviderInternal<M>,
514520
{
515521
fn supported_locales(&self) -> Result<Vec<DataLocale>, DataError> {
516-
self.supported_locales_vec().cloned()
522+
self.supported_locales_vec()
523+
.map(|v| v.iter().cloned().collect())
517524
}
518525

519526
fn supports_locale(&self, locale: &DataLocale) -> Result<bool, DataError> {

0 commit comments

Comments
 (0)