Commit bc80fbc9 authored by Frank Tang's avatar Frank Tang Committed by Commit Bot

[Intl] Reduces memory by sharing code.

Bug: chromium:928098
Change-Id: I47333b06bb7cf2319eec6f6beab830ce6c6da1c5
Reviewed-on: https://chromium-review.googlesource.com/c/1461162Reviewed-by: 's avatarJakob Kummerow <jkummerow@chromium.org>
Commit-Queue: Frank Tang <ftang@chromium.org>
Cr-Commit-Position: refs/heads/master@{#59474}
parent c22bb466
......@@ -29,6 +29,7 @@
#include "unicode/brkiter.h"
#include "unicode/calendar.h"
#include "unicode/coll.h"
#include "unicode/datefmt.h"
#include "unicode/decimfmt.h"
#include "unicode/locid.h"
#include "unicode/normalizer2.h"
......@@ -1859,5 +1860,17 @@ Intl::HourCycle Intl::ToHourCycle(const std::string& hc) {
return Intl::HourCycle::kUndefined;
}
const std::set<std::string>& Intl::GetAvailableLocalesForLocale() {
static base::LazyInstance<Intl::AvailableLocales<icu::Locale>>::type
available_locales = LAZY_INSTANCE_INITIALIZER;
return available_locales.Pointer()->Get();
}
const std::set<std::string>& Intl::GetAvailableLocalesForDateFormat() {
static base::LazyInstance<Intl::AvailableLocales<icu::DateFormat>>::type
available_locales = LAZY_INSTANCE_INITIALIZER;
return available_locales.Pointer()->Get();
}
} // namespace internal
} // namespace v8
......@@ -291,6 +291,10 @@ class Intl {
static const uint8_t* ToLatin1LowerTable();
static String ConvertOneByteToLower(String src, String dst);
static const std::set<std::string>& GetAvailableLocalesForLocale();
static const std::set<std::string>& GetAvailableLocalesForDateFormat();
};
} // namespace internal
......
......@@ -1508,9 +1508,7 @@ MaybeHandle<Object> JSDateTimeFormat::FormatToParts(
}
const std::set<std::string>& JSDateTimeFormat::GetAvailableLocales() {
static base::LazyInstance<Intl::AvailableLocales<icu::DateFormat>>::type
available_locales = LAZY_INSTANCE_INITIALIZER;
return available_locales.Pointer()->Get();
return Intl::GetAvailableLocalesForDateFormat();
}
Handle<String> JSDateTimeFormat::HourCycleAsString() const {
......
......@@ -412,13 +412,10 @@ MaybeHandle<String> JSListFormat::FormatList(Isolate* isolate,
}
const std::set<std::string>& JSListFormat::GetAvailableLocales() {
// TODO(ftang): for now just use
// icu::Locale::getAvailableLocales(count) until we migrate to
// Intl::GetAvailableLocales().
// Since ListFormatter does not have a method to list all supported
// locales, use the one in icu::Locale per comments in
// ICU FR at https://unicode-org.atlassian.net/browse/ICU-20015
static base::LazyInstance<Intl::AvailableLocales<icu::Locale>>::type
available_locales = LAZY_INSTANCE_INITIALIZER;
return available_locales.Pointer()->Get();
return Intl::GetAvailableLocalesForLocale();
}
// ecma42 #sec-formatlisttoparts
......
......@@ -320,9 +320,7 @@ const std::set<std::string>& JSPluralRules::GetAvailableLocales() {
// PluralRules is missing an appropriate getAvailableLocales method,
// so we should filter from all locales, but it's not clear how; see
// https://ssl.icu-project.org/trac/ticket/12756
static base::LazyInstance<Intl::AvailableLocales<icu::Locale>>::type
available_locales = LAZY_INSTANCE_INITIALIZER;
return available_locales.Pointer()->Get();
return Intl::GetAvailableLocalesForLocale();
}
} // namespace internal
......
......@@ -18,7 +18,6 @@
#include "src/objects/intl-objects.h"
#include "src/objects/js-number-format.h"
#include "src/objects/js-relative-time-format-inl.h"
#include "unicode/datefmt.h"
#include "unicode/numfmt.h"
#include "unicode/reldatefmt.h"
......@@ -410,9 +409,9 @@ MaybeHandle<Object> JSRelativeTimeFormat::Format(
}
const std::set<std::string>& JSRelativeTimeFormat::GetAvailableLocales() {
static base::LazyInstance<Intl::AvailableLocales<icu::DateFormat>>::type
available_locales = LAZY_INSTANCE_INITIALIZER;
return available_locales.Pointer()->Get();
// Since RelativeTimeFormatter does not have a method to list all
// available locales, work around by calling the DateFormat.
return Intl::GetAvailableLocalesForDateFormat();
}
} // namespace internal
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment