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: chrome/browser/autofill/phone_number_i18n.h

Issue 7044102: Another performance improvement for phone library - at least +25% to previous cl (982ms for 100 i... (Closed) Base URL: svn://chrome-svn/chrome/trunk/src/
Patch Set: '' Created 9 years, 6 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 | 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 #ifndef CHROME_BROWSER_AUTOFILL_PHONE_NUMBER_I18N_H_ 5 #ifndef CHROME_BROWSER_AUTOFILL_PHONE_NUMBER_I18N_H_
6 #define CHROME_BROWSER_AUTOFILL_PHONE_NUMBER_I18N_H_ 6 #define CHROME_BROWSER_AUTOFILL_PHONE_NUMBER_I18N_H_
7 #pragma once 7 #pragma once
8 8
9 #include <string> 9 #include <string>
10 #include <vector> 10 #include <vector>
11 11
12 #include "base/compiler_specific.h" 12 #include "base/compiler_specific.h"
13 #include "base/memory/scoped_ptr.h"
13 #include "base/string16.h" 14 #include "base/string16.h"
14 15
16 namespace i18n {
17 namespace phonenumbers {
18 class PhoneNumber;
19 }
20 }
21
15 // Utilities to process, normalize and compare international phone numbers. 22 // Utilities to process, normalize and compare international phone numbers.
16
17 namespace autofill_i18n { 23 namespace autofill_i18n {
18 24
19 // Most of the following functions require |locale| to operate. The |locale| is 25 // Most of the following functions require |locale| to operate. The |locale| is
20 // a ISO 3166 standard code ("US" for USA, "CZ" for Czech Republic, etc.). 26 // a ISO 3166 standard code ("US" for USA, "CZ" for Czech Republic, etc.).
21 27
22 // Normalizes phone number, by changing digits in the extended fonts 28 // Normalizes phone number, by changing digits in the extended fonts
23 // (such as \xFF1x) into '0'-'9'. Also strips out non-digit characters. 29 // (such as \xFF1x) into '0'-'9'. Also strips out non-digit characters.
24 string16 NormalizePhoneNumber(const string16& value, 30 string16 NormalizePhoneNumber(const string16& value,
25 const std::string& locale); 31 const std::string& locale);
26 32
(...skipping 54 matching lines...) Expand 10 before | Expand all | Expand 10 after
81 87
82 // Compares two phones, normalizing them before comparision. 88 // Compares two phones, normalizing them before comparision.
83 PhoneMatch ComparePhones(const string16& phone1, 89 PhoneMatch ComparePhones(const string16& phone1,
84 const string16& phone2, 90 const string16& phone2,
85 const std::string& locale); 91 const std::string& locale);
86 92
87 bool PhoneNumbersMatch(const string16& number_a, 93 bool PhoneNumbersMatch(const string16& number_a,
88 const string16& number_b, 94 const string16& number_b,
89 const std::string& country_code); 95 const std::string& country_code);
90 96
97 // The cached phone number, does parsing only once, improves performance.
98 class PhoneObject {
99 public:
100 PhoneObject(const string16& number, const std::string& locale);
101 PhoneObject(const PhoneObject&);
102 PhoneObject();
103 ~PhoneObject();
104
105 string16 GetCountryCode() const;
106 string16 GetCityCode() const;
107 string16 GetNumber() const;
108 std::string GetLocale() const { return locale_; }
109
110 string16 GetWholeNumber() const;
111
112 PhoneMatch ComparePhones(const string16& phone) const;
113 PhoneMatch ComparePhones(const PhoneObject& phone) const;
114
115 PhoneObject& operator=(const PhoneObject& other);
116
117 bool ValidNumber() const { return i18n_number_ != NULL; }
118
119 private:
120 string16 city_code_;
121 string16 country_code_;
122 string16 number_;
123 mutable string16 whole_number_; // Set on first request.
124 std::string locale_;
125 scoped_ptr<i18n::phonenumbers::PhoneNumber> i18n_number_;
126 };
127
91 } // namespace autofill_i18n 128 } // namespace autofill_i18n
92 129
93 #endif // CHROME_BROWSER_AUTOFILL_PHONE_NUMBER_I18N_H_ 130 #endif // CHROME_BROWSER_AUTOFILL_PHONE_NUMBER_I18N_H_
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698