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

Side by Side Diff: third_party/libphonenumber/cpp/src/regexp_cache.cc

Issue 8736001: Pull the phone library directly. Delete old version. (Closed) Base URL: svn://chrome-svn/chrome/trunk/src/
Patch Set: '' Created 9 years 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
(Empty)
1 // Copyright (C) 2011 Google Inc.
2 //
3 // Licensed under the Apache License, Version 2.0 (the "License");
4 // you may not use this file except in compliance with the License.
5 // You may obtain a copy of the License at
6 //
7 // http://www.apache.org/licenses/LICENSE-2.0
8 //
9 // Unless required by applicable law or agreed to in writing, software
10 // distributed under the License is distributed on an "AS IS" BASIS,
11 // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12 // See the License for the specific language governing permissions and
13 // limitations under the License.
14
15 // Author: Fredrik Roubert
16
17 #include "regexp_cache.h"
18
19 #include <cstddef>
20 #include <string>
21 #include <utility>
22
23 #include "base/logging.h"
24 #include "base/synchronization/lock.h"
25 #include "regexp_adapter.h"
26
27 using std::string;
28
29 namespace i18n {
30 namespace phonenumbers {
31
32 using base::AutoLock;
33
34 RegExpCache::RegExpCache(size_t min_items)
35 #ifdef USE_TR1_UNORDERED_MAP
36 : cache_impl_(new CacheImpl(min_items)) {}
37 #else // USE_TR1_UNORDERED_MAP
38 : cache_impl_(new CacheImpl()) {}
39 #endif // USE_TR1_UNORDERED_MAP
40
41 RegExpCache::~RegExpCache() {
42 AutoLock l(lock_);
43 for (CacheImpl::const_iterator
44 it = cache_impl_->begin(); it != cache_impl_->end(); ++it) {
45 delete it->second;
46 }
47 }
48
49 const RegExp& RegExpCache::GetRegExp(const string& pattern) {
50 AutoLock l(lock_);
51 CacheImpl::const_iterator it = cache_impl_->find(pattern);
52 if (it != cache_impl_->end()) return *it->second;
53
54 const RegExp* regexp = RegExp::Create(pattern);
55 cache_impl_->insert(make_pair(pattern, regexp));
56 return *regexp;
57 }
58
59 } // namespace phonenumbers
60 } // namespace i18n
OLDNEW
« no previous file with comments | « third_party/libphonenumber/cpp/src/regexp_cache.h ('k') | third_party/libphonenumber/cpp/src/regexp_cache_test.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698