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

Side by Side Diff: base/i18n/number_formatting.cc

Issue 8491043: Allow linker initialization of lazy instance (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: fix CrOS Created 9 years, 1 month 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 | Annotate | Revision Log
OLDNEW
1 // Copyright (c) 2011 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2011 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 "base/i18n/number_formatting.h" 5 #include "base/i18n/number_formatting.h"
6 6
7 #include "base/format_macros.h" 7 #include "base/format_macros.h"
8 #include "base/logging.h" 8 #include "base/logging.h"
9 #include "base/lazy_instance.h" 9 #include "base/lazy_instance.h"
10 #include "base/memory/scoped_ptr.h" 10 #include "base/memory/scoped_ptr.h"
(...skipping 18 matching lines...) Expand all
29 // This can cause problems if a different allocator is used by this file 29 // This can cause problems if a different allocator is used by this file
30 // than by ICU. 30 // than by ICU.
31 UErrorCode status = U_ZERO_ERROR; 31 UErrorCode status = U_ZERO_ERROR;
32 number_format.reset(icu::NumberFormat::createInstance(status)); 32 number_format.reset(icu::NumberFormat::createInstance(status));
33 DCHECK(U_SUCCESS(status)); 33 DCHECK(U_SUCCESS(status));
34 } 34 }
35 35
36 scoped_ptr<icu::NumberFormat> number_format; 36 scoped_ptr<icu::NumberFormat> number_format;
37 }; 37 };
38 38
39 LazyInstance<NumberFormatWrapper> g_number_format_int(LINKER_INITIALIZED); 39 LazyInstance<NumberFormatWrapper> g_number_format_int = LINKER_ZERO_INITIALIZED;
40 LazyInstance<NumberFormatWrapper> g_number_format_float(LINKER_INITIALIZED); 40 LazyInstance<NumberFormatWrapper> g_number_format_float =
41 LINKER_ZERO_INITIALIZED;
41 42
42 } // namespace 43 } // namespace
43 44
44 string16 FormatNumber(int64 number) { 45 string16 FormatNumber(int64 number) {
45 icu::NumberFormat* number_format = 46 icu::NumberFormat* number_format =
46 g_number_format_int.Get().number_format.get(); 47 g_number_format_int.Get().number_format.get();
47 48
48 if (!number_format) { 49 if (!number_format) {
49 // As a fallback, just return the raw number in a string. 50 // As a fallback, just return the raw number in a string.
50 return UTF8ToUTF16(StringPrintf("%" PRId64, number)); 51 return UTF8ToUTF16(StringPrintf("%" PRId64, number));
(...skipping 23 matching lines...) Expand all
74 namespace testing { 75 namespace testing {
75 76
76 void ResetFormatters() { 77 void ResetFormatters() {
77 g_number_format_int.Get().Reset(); 78 g_number_format_int.Get().Reset();
78 g_number_format_float.Get().Reset(); 79 g_number_format_float.Get().Reset();
79 } 80 }
80 81
81 } // namespace testing 82 } // namespace testing
82 83
83 } // namespace base 84 } // namespace base
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698