Index: base/i18n/number_formatting.cc |
diff --git a/base/i18n/number_formatting.cc b/base/i18n/number_formatting.cc |
index 7a69294a76fc547b8f7ef0b7b93e1234fc27a589..d39c3227b9ed6d1a758dd609f9cbda34114b3b32 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 |
M-A Ruel
2010/12/10 14:52:18
80 cols
Satish
2010/12/10 17:13:48
Done.
|
+ // 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); |
+ |
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. |