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

Unified Diff: third_party/re2/re2/regexp.cc

Issue 10873029: Migrate WebRequestRedirectByRegExAction to use RE2 and roll RE2 to revision 97:401ab4168e8e (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Merged with ToT Created 8 years, 4 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 side-by-side diff with in-line comments
Download patch
« no previous file with comments | « third_party/re2/re2/regexp.h ('k') | third_party/re2/re2/testing/filtered_re2_test.cc » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: third_party/re2/re2/regexp.cc
diff --git a/third_party/re2/re2/regexp.cc b/third_party/re2/re2/regexp.cc
index 9486b3c14c6571c8333e381eb235f6765f7131d7..a74ceec8271fd8c5550b9414d33ef2d0504f3246 100644
--- a/third_party/re2/re2/regexp.cc
+++ b/third_party/re2/re2/regexp.cc
@@ -59,29 +59,39 @@ bool Regexp::QuickDestroy() {
return false;
}
-static map<Regexp*, int> ref_map;
-static Mutex ref_mutex;
+static map<Regexp*, int> *ref_map;
+GLOBAL_MUTEX(ref_mutex);
int Regexp::Ref() {
if (ref_ < kMaxRef)
return ref_;
- MutexLock l(&ref_mutex);
- return ref_map[this];
+ GLOBAL_MUTEX_LOCK(ref_mutex);
+ int r = 0;
+ if (ref_map != NULL) {
+ r = (*ref_map)[this];
+ }
+ GLOBAL_MUTEX_UNLOCK(ref_mutex);
+ return r;
}
// Increments reference count, returns object as convenience.
Regexp* Regexp::Incref() {
if (ref_ >= kMaxRef-1) {
// Store ref count in overflow map.
- MutexLock l(&ref_mutex);
- if (ref_ == kMaxRef) { // already overflowed
- ref_map[this]++;
- return this;
+ GLOBAL_MUTEX_LOCK(ref_mutex);
+ if (ref_map == NULL) {
+ ref_map = new map<Regexp*, int>;
+ }
+ if (ref_ == kMaxRef) {
+ // already overflowed
+ (*ref_map)[this]++;
+ } else {
+ // overflowing now
+ (*ref_map)[this] = kMaxRef;
+ ref_ = kMaxRef;
}
- // overflowing now
- ref_map[this] = kMaxRef;
- ref_ = kMaxRef;
+ GLOBAL_MUTEX_UNLOCK(ref_mutex);
return this;
}
@@ -93,14 +103,15 @@ Regexp* Regexp::Incref() {
void Regexp::Decref() {
if (ref_ == kMaxRef) {
// Ref count is stored in overflow map.
- MutexLock l(&ref_mutex);
- int r = ref_map[this] - 1;
+ GLOBAL_MUTEX_LOCK(ref_mutex);
+ int r = (*ref_map)[this] - 1;
if (r < kMaxRef) {
ref_ = r;
- ref_map.erase(this);
+ ref_map->erase(this);
} else {
- ref_map[this] = r;
+ (*ref_map)[this] = r;
}
+ GLOBAL_MUTEX_UNLOCK(ref_mutex);
return;
}
ref_--;
@@ -447,7 +458,7 @@ bool Regexp::Equal(Regexp* a, Regexp* b) {
}
// Keep in sync with enum RegexpStatusCode in regexp.h
-static const string kErrorStrings[] = {
+static const char *kErrorStrings[] = {
"no error",
"unexpected error",
"invalid escape sequence",
@@ -464,7 +475,7 @@ static const string kErrorStrings[] = {
"invalid named capture group",
};
-const string& RegexpStatus::CodeText(enum RegexpStatusCode code) {
+string RegexpStatus::CodeText(enum RegexpStatusCode code) {
if (code < 0 || code >= arraysize(kErrorStrings))
code = kRegexpInternalError;
return kErrorStrings[code];
« no previous file with comments | « third_party/re2/re2/regexp.h ('k') | third_party/re2/re2/testing/filtered_re2_test.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698