Increments reference count, returns object as convenience.
| 88 | |
| 89 | // Increments reference count, returns object as convenience. |
| 90 | Regexp* Regexp::Incref() { |
| 91 | if (ref_ >= kMaxRef-1) { |
| 92 | static std::once_flag ref_once; |
| 93 | std::call_once(ref_once, []() { |
| 94 | ref_mutex = new Mutex; |
| 95 | ref_map = new std::map<Regexp*, int>; |
| 96 | }); |
| 97 | |
| 98 | // Store ref count in overflow map. |
| 99 | MutexLock l(ref_mutex); |
| 100 | if (ref_ == kMaxRef) { |
| 101 | // already overflowed |
| 102 | (*ref_map)[this]++; |
| 103 | } else { |
| 104 | // overflowing now |
| 105 | (*ref_map)[this] = kMaxRef; |
| 106 | ref_ = kMaxRef; |
| 107 | } |
| 108 | return this; |
| 109 | } |
| 110 | |
| 111 | ref_++; |
| 112 | return this; |
| 113 | } |
| 114 | |
| 115 | // Decrements reference count and deletes this object if count reaches 0. |
| 116 | void Regexp::Decref() { |
no test coverage detected