Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(204)

Unified Diff: base/i18n/rtl.cc

Issue 1281343003: Optimize RTL check in ICU to avoid mmap access. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: compile fixes Created 5 years, 4 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
« no previous file with comments | « base/i18n/rtl.h ('k') | base/i18n/rtl_unittest.cc » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: base/i18n/rtl.cc
diff --git a/base/i18n/rtl.cc b/base/i18n/rtl.cc
index 93f91c26a24e4690ee68a4973fea31c0fa5b16ee..ac9589cb32531f551271c5817f9578daa801d250 100644
--- a/base/i18n/rtl.cc
+++ b/base/i18n/rtl.cc
@@ -4,9 +4,11 @@
#include "base/i18n/rtl.h"
+#include <algorithm>
+
#include "base/files/file_path.h"
#include "base/logging.h"
-#include "base/metrics/field_trial.h"
+#include "base/strings/string_split.h"
#include "base/strings/string_util.h"
#include "base/strings/sys_string_conversions.h"
#include "base/strings/utf_string_conversions.h"
@@ -127,22 +129,32 @@ bool IsRTL() {
bool ICUIsRTL() {
if (g_icu_text_direction == UNKNOWN_DIRECTION) {
const icu::Locale& locale = icu::Locale::getDefault();
- g_icu_text_direction = GetTextDirectionForLocale(locale.getName());
+ g_icu_text_direction = GetTextDirectionForLocaleInStartUp(locale.getName());
}
return g_icu_text_direction == RIGHT_TO_LEFT;
}
-TextDirection GetTextDirectionForLocale(const char* locale_name) {
- const std::string group_name =
- FieldTrialList::FindFullName("LightSpeed");
- // StartsWith allows flexibility for this experiment to apply to multiple
- // group names. To start, this will apply to AvoidMMapOnStartup.
- if (StartsWith(group_name, "AvoidMMap", CompareCase::SENSITIVE)) {
- static const char kEnglishLocale[] = "en_";
- if (StartsWith(locale_name, kEnglishLocale, CompareCase::SENSITIVE))
- return LEFT_TO_RIGHT;
- }
+TextDirection GetTextDirectionForLocaleInStartUp(const char* locale_name) {
+// On iOS, check for RTL forcing.
+#if defined(OS_IOS)
+ if (ios::IsInForcedRTL())
+ return RIGHT_TO_LEFT;
+#endif
+
+ // This list needs to be updated in alphabetical order if we add more RTL
+ // locales.
+ static const char* kRTLLanguageCodes[] = {"ar", "fa", "he", "iw", "ur"};
+ std::vector<StringPiece> locale_split =
+ SplitStringPiece(locale_name, "-_", KEEP_WHITESPACE, SPLIT_WANT_ALL);
+ const StringPiece& language_code = locale_split[0];
+ if (std::binary_search(kRTLLanguageCodes,
+ kRTLLanguageCodes + arraysize(kRTLLanguageCodes),
+ language_code))
+ return RIGHT_TO_LEFT;
+ return LEFT_TO_RIGHT;
+}
+TextDirection GetTextDirectionForLocale(const char* locale_name) {
Alexei Svitkine (slow) 2015/08/12 15:40:02 Seems like the only place where GetTextDirectionFo
danduong 2015/08/12 17:22:42 That's a good question. jshin@ I know your origina
// On iOS, check for RTL forcing.
#if defined(OS_IOS)
if (ios::IsInForcedRTL())
« no previous file with comments | « base/i18n/rtl.h ('k') | base/i18n/rtl_unittest.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698