Index: base/i18n/number_formatting.cc |
diff --git a/base/i18n/number_formatting.cc b/base/i18n/number_formatting.cc |
index 7a69294a76fc547b8f7ef0b7b93e1234fc27a589..df6af1462c2aeb09bf9f92ca7bd0ed0a95b76681 100644 |
--- a/base/i18n/number_formatting.cc |
+++ b/base/i18n/number_formatting.cc |
@@ -6,7 +6,8 @@ |
#include "base/format_macros.h" |
#include "base/logging.h" |
-#include "base/singleton.h" |
+#include "base/lazy_instance.h" |
+#include "base/scoped_ptr.h" |
#include "base/string_util.h" |
#include "base/utf_string_conversions.h" |
#include "unicode/numfmt.h" |
@@ -16,25 +17,26 @@ namespace base { |
namespace { |
-struct NumberFormatSingletonTraits |
- : public DefaultSingletonTraits<icu::NumberFormat> { |
- static icu::NumberFormat* New() { |
+struct NumberFormatWrapper { |
+ NumberFormatWrapper() { |
+ // There's no ICU call to destroy a NumberFormat object other than |
+ // operator delete, so use the default Delete, which calls operator delete. |
+ // This can cause problems if a different allocator is used by this file |
+ // than by ICU. |
UErrorCode status = U_ZERO_ERROR; |
- icu::NumberFormat* formatter = icu::NumberFormat::createInstance(status); |
+ number_format.reset(icu::NumberFormat::createInstance(status)); |
DCHECK(U_SUCCESS(status)); |
- return formatter; |
} |
- // There's no ICU call to destroy a NumberFormat object other than |
- // operator delete, so use the default Delete, which calls operator delete. |
- // This can cause problems if a different allocator is used by this file than |
- // by ICU. |
+ |
+ scoped_ptr<icu::NumberFormat> number_format; |
}; |
} // namespace |
+static LazyInstance<NumberFormatWrapper> g_number_format(LINKER_INITIALIZED); |
Evan Martin
2010/12/13 17:38:30
*
|
+ |
string16 FormatNumber(int64 number) { |
- icu::NumberFormat* number_format = |
- Singleton<icu::NumberFormat, NumberFormatSingletonTraits>::get(); |
+ icu::NumberFormat* number_format = g_number_format.Get().number_format.get(); |
if (!number_format) { |
// As a fallback, just return the raw number in a string. |