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

Unified Diff: ui/base/l10n/l10n_util.cc

Issue 2009683002: Avoid a copy in the debug check in GetStringFUTF16(). (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Created 4 years, 7 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 | « no previous file | no next file » | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: ui/base/l10n/l10n_util.cc
diff --git a/ui/base/l10n/l10n_util.cc b/ui/base/l10n/l10n_util.cc
index 9dfe573dc43c8377060850ef1aff5f7bdea8359d..4d63a47967b430a20891fb345ecab4d523feccfb 100644
--- a/ui/base/l10n/l10n_util.cc
+++ b/ui/base/l10n/l10n_util.cc
@@ -699,23 +699,21 @@ base::string16 GetStringFUTF16(int message_id,
// check as the code may simply want to find the placeholders rather than
// actually replacing them.
if (!offsets) {
- std::string utf8_string = base::UTF16ToUTF8(format_string);
-
// $9 is the highest allowed placeholder.
for (size_t i = 0; i < 9; ++i) {
bool placeholder_should_exist = replacements.size() > i;
- std::string placeholder =
- base::StringPrintf("$%d", static_cast<int>(i + 1));
- size_t pos = utf8_string.find(placeholder.c_str());
+ base::string16 placeholder = base::ASCIIToUTF16("$");
+ placeholder += (L'1' + i);
Lei Zhang 2016/05/25 00:07:02 At least Linux didn't like having this as part of
jungshik at Google 2016/05/25 07:37:05 |L'1'| is wchar_t (32-bit) on Linux/Mac. Didn't yo
jungshik at Google 2016/05/25 08:26:34 oh. trybots all come back green.
+ size_t pos = format_string.find(placeholder);
if (placeholder_should_exist) {
- DCHECK_NE(std::string::npos, pos) <<
- " Didn't find a " << placeholder << " placeholder in " <<
- utf8_string;
+ DCHECK_NE(std::string::npos, pos) << " Didn't find a " << placeholder
Lei Zhang 2016/05/25 00:07:02 This is just "git cl format" lining things up.
+ << " placeholder in "
+ << format_string;
} else {
- DCHECK_EQ(std::string::npos, pos) <<
- " Unexpectedly found a " << placeholder << " placeholder in " <<
- utf8_string;
+ DCHECK_EQ(std::string::npos, pos) << " Unexpectedly found a "
+ << placeholder << " placeholder in "
+ << format_string;
}
}
}
@@ -865,10 +863,11 @@ void GetAcceptLanguagesForLocale(const std::string& display_locale,
std::vector<std::string>* locale_codes) {
for (size_t i = 0; i < arraysize(kAcceptLanguageList); ++i) {
if (!l10n_util::IsLocaleNameTranslated(kAcceptLanguageList[i],
- display_locale))
- // TODO(jungshik) : Put them at the of the list with language codes
+ display_locale)) {
+ // TODO(jungshik) : Put them at the end of the list with language codes
Lei Zhang 2016/05/25 00:07:03 I think that's what you meant to say?
// enclosed by brackets instead of skipping.
- continue;
+ continue;
+ }
locale_codes->push_back(kAcceptLanguageList[i]);
}
}
« no previous file with comments | « no previous file | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698