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

Side by Side Diff: third_party/WebKit/Source/platform/fonts/AcceptLanguagesResolver.cpp

Issue 2213393002: Defer computing localeForHan until needed (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: fix Created 4 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 unified diff | Download patch
OLDNEW
1 // Copyright 2016 The Chromium Authors. All rights reserved. 1 // Copyright 2016 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be 2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file. 3 // found in the LICENSE file.
4 4
5 #include "platform/fonts/AcceptLanguagesResolver.h" 5 #include "platform/fonts/AcceptLanguagesResolver.h"
6 6
7 #include "platform/LayoutLocale.h" 7 #include "platform/LayoutLocale.h"
8 8
9 namespace blink { 9 namespace blink {
10 10
11 static String& current()
drott 2016/08/08 15:16:37 Could you give this a more descriptive name?
kojii 2016/08/08 15:33:54 Changed to currentAcceptLanguages().
12 {
13 DEFINE_STATIC_LOCAL(String, s_current, ());
14 return s_current;
15 }
16
11 void AcceptLanguagesResolver::acceptLanguagesChanged( 17 void AcceptLanguagesResolver::acceptLanguagesChanged(
12 const String& acceptLanguages) 18 const String& acceptLanguages)
13 { 19 {
14 LayoutLocale::setLocaleForHan( 20 if (current() == acceptLanguages)
15 localeForHanFromAcceptLanguages(acceptLanguages)); 21 return;
22
23 current() = acceptLanguages;
24 LayoutLocale::InvalidateLocaleForHan();
25 }
26
27 const LayoutLocale* AcceptLanguagesResolver::localeForHan()
28 {
29 return localeForHanFromAcceptLanguages(current());
16 } 30 }
17 31
18 const LayoutLocale* AcceptLanguagesResolver::localeForHanFromAcceptLanguages( 32 const LayoutLocale* AcceptLanguagesResolver::localeForHanFromAcceptLanguages(
19 const String& acceptLanguages) 33 const String& acceptLanguages)
20 { 34 {
21 // Use the first acceptLanguages that can disambiguate. 35 // Use the first acceptLanguages that can disambiguate.
22 Vector<String> languages; 36 Vector<String> languages;
23 acceptLanguages.split(',', languages); 37 acceptLanguages.split(',', languages);
24 for (String token : languages) { 38 for (String token : languages) {
25 token = token.stripWhiteSpace(); 39 token = token.stripWhiteSpace();
26 const LayoutLocale* locale = LayoutLocale::get(AtomicString(token)); 40 const LayoutLocale* locale = LayoutLocale::get(AtomicString(token));
27 if (locale->hasScriptForHan()) 41 if (locale->hasScriptForHan())
28 return locale; 42 return locale;
29 } 43 }
30 44
31 return nullptr; 45 return nullptr;
32 } 46 }
33 47
34 } // namespace blink 48 } // namespace blink
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698