summaryrefslogtreecommitdiffstats
path: root/third_party/libphonenumber/cpp
diff options
context:
space:
mode:
authorgeorgey@chromium.org <georgey@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2011-06-14 16:49:17 +0000
committergeorgey@chromium.org <georgey@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2011-06-14 16:49:17 +0000
commit768e7871ff550ca23ab0ff7f400bfd9edc5b57ee (patch)
tree29b81abdf2f98b7c08219c064f54d6da1dc81cea /third_party/libphonenumber/cpp
parente7427721b4014dd0fbbdfc75372b50791f9e6ad8 (diff)
downloadchromium_src-768e7871ff550ca23ab0ff7f400bfd9edc5b57ee.zip
chromium_src-768e7871ff550ca23ab0ff7f400bfd9edc5b57ee.tar.gz
chromium_src-768e7871ff550ca23ab0ff7f400bfd9edc5b57ee.tar.bz2
Improved performance on some phone-related functions by 8x (1251ms on average against 9773.4ms on average on
AutofillManagerTest.DeterminePossibleFieldTypesForUpload with 100 profiles). Real life performance improvement should be even bigger as most phones will be parsed once. TEST=The caching object is tested by multiple AutofillManager, PersonalDataManager, etc. unittests + new unit-test to test performance. BUG=85152 Review URL: http://codereview.chromium.org/7134032 git-svn-id: svn://svn.chromium.org/chrome/trunk/src@89016 0039d316-1c4b-4281-b951-d872f2087c98
Diffstat (limited to 'third_party/libphonenumber/cpp')
-rw-r--r--third_party/libphonenumber/cpp/src/phonenumberutil.cc40
-rw-r--r--third_party/libphonenumber/cpp/src/phonenumberutil.h5
2 files changed, 25 insertions, 20 deletions
diff --git a/third_party/libphonenumber/cpp/src/phonenumberutil.cc b/third_party/libphonenumber/cpp/src/phonenumberutil.cc
index b0201f2..28fbd43 100644
--- a/third_party/libphonenumber/cpp/src/phonenumberutil.cc
+++ b/third_party/libphonenumber/cpp/src/phonenumberutil.cc
@@ -1765,30 +1765,32 @@ void PhoneNumberUtil::NormalizeDigitsOnly(string* number) {
UParseError error;
icu::ErrorCode status;
- scoped_ptr<icu::Transliterator> transliterator(
- icu::Transliterator::createFromRules(
- "NormalizeDecimalDigits",
- "[[:nv=0:]-[0]-[:^nt=de:]]>0;"
- "[[:nv=1:]-[1]-[:^nt=de:]]>1;"
- "[[:nv=2:]-[2]-[:^nt=de:]]>2;"
- "[[:nv=3:]-[3]-[:^nt=de:]]>3;"
- "[[:nv=4:]-[4]-[:^nt=de:]]>4;"
- "[[:nv=5:]-[5]-[:^nt=de:]]>5;"
- "[[:nv=6:]-[6]-[:^nt=de:]]>6;"
- "[[:nv=7:]-[7]-[:^nt=de:]]>7;"
- "[[:nv=8:]-[8]-[:^nt=de:]]>8;"
- "[[:nv=9:]-[9]-[:^nt=de:]]>9;",
- UTRANS_FORWARD,
- error,
- status
- )
- );
+ if (!GetInstance()->transliterator_.get()) {
+ GetInstance()->transliterator_.reset(
+ icu::Transliterator::createFromRules(
+ "NormalizeDecimalDigits",
+ "[[:nv=0:]-[0]-[:^nt=de:]]>0;"
+ "[[:nv=1:]-[1]-[:^nt=de:]]>1;"
+ "[[:nv=2:]-[2]-[:^nt=de:]]>2;"
+ "[[:nv=3:]-[3]-[:^nt=de:]]>3;"
+ "[[:nv=4:]-[4]-[:^nt=de:]]>4;"
+ "[[:nv=5:]-[5]-[:^nt=de:]]>5;"
+ "[[:nv=6:]-[6]-[:^nt=de:]]>6;"
+ "[[:nv=7:]-[7]-[:^nt=de:]]>7;"
+ "[[:nv=8:]-[8]-[:^nt=de:]]>8;"
+ "[[:nv=9:]-[9]-[:^nt=de:]]>9;",
+ UTRANS_FORWARD,
+ error,
+ status
+ )
+ );
+ }
if (!status.isSuccess()) {
logger->Error("Error creating ICU Transliterator");
return;
}
icu::UnicodeString utf16(icu::UnicodeString::fromUTF8(number->c_str()));
- transliterator->transliterate(utf16);
+ GetInstance()->transliterator_->transliterate(utf16);
number->clear();
utf16.toUTF8String(*number);
}
diff --git a/third_party/libphonenumber/cpp/src/phonenumberutil.h b/third_party/libphonenumber/cpp/src/phonenumberutil.h
index 6a766df..43137a0 100644
--- a/third_party/libphonenumber/cpp/src/phonenumberutil.h
+++ b/third_party/libphonenumber/cpp/src/phonenumberutil.h
@@ -26,6 +26,7 @@
#include <string>
#include <utility>
#include <vector>
+#include <unicode/translit.h>
#include "base/scoped_ptr.h"
#include "base/singleton.h"
@@ -57,7 +58,7 @@ class PhoneNumberUtil {
public:
// INTERNATIONAL and NATIONAL formats are consistent with the definition
// in ITU-T Recommendation E. 123. For example, the number of the Google
- // Zürich office will be written as "+41 44 668 1800" in INTERNATIONAL
+ // Zurich office will be written as "+41 44 668 1800" in INTERNATIONAL
// format, and as "044 668 1800" in NATIONAL format. E164 format is as per
// INTERNATIONAL format but with no formatting applied e.g. +41446681800.
// RFC3966 is as per INTERNATIONAL format, but with all spaces and other
@@ -669,6 +670,8 @@ class PhoneNumberUtil {
bool check_region,
PhoneNumber* phone_number) const;
+ scoped_ptr<icu::Transliterator> transliterator_;
+
DISALLOW_COPY_AND_ASSIGN(PhoneNumberUtil);
};