grpc 1.31.0.pre1 → 1.31.0.pre2
Sign up to get free protection for your applications and to get access to all the features.
Potentially problematic release.
This version of grpc might be problematic. Click here for more details.
- checksums.yaml +4 -4
- data/Makefile +2 -2
- data/src/core/ext/filters/client_channel/lb_policy/weighted_target/weighted_target.cc +3 -4
- data/src/core/ext/filters/client_channel/lb_policy/xds/xds_routing.cc +5 -4
- data/src/ruby/lib/grpc/version.rb +1 -1
- data/third_party/re2/re2/bitmap256.h +117 -0
- data/third_party/re2/re2/bitstate.cc +385 -0
- data/third_party/re2/re2/compile.cc +1279 -0
- data/third_party/re2/re2/dfa.cc +2130 -0
- data/third_party/re2/re2/filtered_re2.cc +121 -0
- data/third_party/re2/re2/filtered_re2.h +109 -0
- data/third_party/re2/re2/mimics_pcre.cc +197 -0
- data/third_party/re2/re2/nfa.cc +713 -0
- data/third_party/re2/re2/onepass.cc +623 -0
- data/third_party/re2/re2/parse.cc +2464 -0
- data/third_party/re2/re2/perl_groups.cc +119 -0
- data/third_party/re2/re2/pod_array.h +55 -0
- data/third_party/re2/re2/prefilter.cc +710 -0
- data/third_party/re2/re2/prefilter.h +108 -0
- data/third_party/re2/re2/prefilter_tree.cc +407 -0
- data/third_party/re2/re2/prefilter_tree.h +139 -0
- data/third_party/re2/re2/prog.cc +988 -0
- data/third_party/re2/re2/prog.h +436 -0
- data/third_party/re2/re2/re2.cc +1362 -0
- data/third_party/re2/re2/re2.h +1002 -0
- data/third_party/re2/re2/regexp.cc +980 -0
- data/third_party/re2/re2/regexp.h +659 -0
- data/third_party/re2/re2/set.cc +154 -0
- data/third_party/re2/re2/set.h +80 -0
- data/third_party/re2/re2/simplify.cc +657 -0
- data/third_party/re2/re2/sparse_array.h +392 -0
- data/third_party/re2/re2/sparse_set.h +264 -0
- data/third_party/re2/re2/stringpiece.cc +65 -0
- data/third_party/re2/re2/stringpiece.h +210 -0
- data/third_party/re2/re2/tostring.cc +351 -0
- data/third_party/re2/re2/unicode_casefold.cc +582 -0
- data/third_party/re2/re2/unicode_casefold.h +78 -0
- data/third_party/re2/re2/unicode_groups.cc +6269 -0
- data/third_party/re2/re2/unicode_groups.h +67 -0
- data/third_party/re2/re2/walker-inl.h +246 -0
- data/third_party/re2/util/benchmark.h +156 -0
- data/third_party/re2/util/flags.h +26 -0
- data/third_party/re2/util/logging.h +109 -0
- data/third_party/re2/util/malloc_counter.h +19 -0
- data/third_party/re2/util/mix.h +41 -0
- data/third_party/re2/util/mutex.h +148 -0
- data/third_party/re2/util/pcre.cc +1025 -0
- data/third_party/re2/util/pcre.h +681 -0
- data/third_party/re2/util/rune.cc +260 -0
- data/third_party/re2/util/strutil.cc +149 -0
- data/third_party/re2/util/strutil.h +21 -0
- data/third_party/re2/util/test.h +50 -0
- data/third_party/re2/util/utf.h +44 -0
- data/third_party/re2/util/util.h +42 -0
- metadata +78 -29
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: a1f9a28ba86dad0d526e6f12ea9981f6fdcd73b0b7f146273b7172d0e305201a
|
4
|
+
data.tar.gz: aae22a55fe36be7e24e963676e4d91f2dc9c8b2e173792bd71655aa85df0ba17
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 8b5fb607278a07602fadcce34362fb28510893a542da51b42caa5eac4325c5f083a25944b4b683a799fe88b6869f34464ff8fb62d66a0b0059a2d641be896a21
|
7
|
+
data.tar.gz: 1e19353f704d3851283562d811fd95a10f28271c4839963fe1deb3e86545b88a485cd634c0cd4029d62475dce97ae93b8c487ed6388c98bb9769e00335edcc9f
|
data/Makefile
CHANGED
@@ -450,8 +450,8 @@ Q = @
|
|
450
450
|
endif
|
451
451
|
|
452
452
|
CORE_VERSION = 11.0.0
|
453
|
-
CPP_VERSION = 1.31.0-
|
454
|
-
CSHARP_VERSION = 2.31.0-
|
453
|
+
CPP_VERSION = 1.31.0-pre2
|
454
|
+
CSHARP_VERSION = 2.31.0-pre2
|
455
455
|
|
456
456
|
CPPFLAGS_NO_ARCH += $(addprefix -I, $(INCLUDES)) $(addprefix -D, $(DEFINES))
|
457
457
|
CPPFLAGS += $(CPPFLAGS_NO_ARCH) $(ARCH_FLAGS)
|
@@ -169,7 +169,7 @@ class WeightedTargetLb : public LoadBalancingPolicy {
|
|
169
169
|
// The owning LB policy.
|
170
170
|
RefCountedPtr<WeightedTargetLb> weighted_target_policy_;
|
171
171
|
|
172
|
-
const std::string
|
172
|
+
const std::string name_;
|
173
173
|
|
174
174
|
uint32_t weight_;
|
175
175
|
|
@@ -288,9 +288,8 @@ void WeightedTargetLb::UpdateLocked(UpdateArgs args) {
|
|
288
288
|
const std::string& name = p.first;
|
289
289
|
auto it = targets_.find(name);
|
290
290
|
if (it == targets_.end()) {
|
291
|
-
|
292
|
-
|
293
|
-
Ref(DEBUG_LOCATION, "WeightedChild"), it->first);
|
291
|
+
targets_.emplace(name, MakeOrphanable<WeightedChild>(
|
292
|
+
Ref(DEBUG_LOCATION, "WeightedChild"), name));
|
294
293
|
}
|
295
294
|
}
|
296
295
|
// Update all children.
|
@@ -185,7 +185,7 @@ class XdsRoutingLb : public LoadBalancingPolicy {
|
|
185
185
|
RefCountedPtr<XdsRoutingLb> xds_routing_policy_;
|
186
186
|
|
187
187
|
// Points to the corresponding key in XdsRoutingLb::actions_.
|
188
|
-
const std::string
|
188
|
+
const std::string name_;
|
189
189
|
|
190
190
|
OrphanablePtr<LoadBalancingPolicy> child_policy_;
|
191
191
|
|
@@ -405,9 +405,10 @@ void XdsRoutingLb::UpdateLocked(UpdateArgs args) {
|
|
405
405
|
const RefCountedPtr<LoadBalancingPolicy::Config>& config = p.second;
|
406
406
|
auto it = actions_.find(name);
|
407
407
|
if (it == actions_.end()) {
|
408
|
-
it = actions_
|
409
|
-
|
410
|
-
|
408
|
+
it = actions_
|
409
|
+
.emplace(name, MakeOrphanable<XdsRoutingChild>(
|
410
|
+
Ref(DEBUG_LOCATION, "XdsRoutingChild"), name))
|
411
|
+
.first;
|
411
412
|
}
|
412
413
|
it->second->UpdateLocked(config, args.addresses, args.args);
|
413
414
|
}
|
@@ -0,0 +1,117 @@
|
|
1
|
+
// Copyright 2016 The RE2 Authors. All Rights Reserved.
|
2
|
+
// Use of this source code is governed by a BSD-style
|
3
|
+
// license that can be found in the LICENSE file.
|
4
|
+
|
5
|
+
#ifndef RE2_BITMAP256_H_
|
6
|
+
#define RE2_BITMAP256_H_
|
7
|
+
|
8
|
+
#ifdef _MSC_VER
|
9
|
+
#include <intrin.h>
|
10
|
+
#endif
|
11
|
+
#include <stdint.h>
|
12
|
+
#include <string.h>
|
13
|
+
|
14
|
+
#include "util/util.h"
|
15
|
+
#include "util/logging.h"
|
16
|
+
|
17
|
+
namespace re2 {
|
18
|
+
|
19
|
+
class Bitmap256 {
|
20
|
+
public:
|
21
|
+
Bitmap256() {
|
22
|
+
Clear();
|
23
|
+
}
|
24
|
+
|
25
|
+
// Clears all of the bits.
|
26
|
+
void Clear() {
|
27
|
+
memset(words_, 0, sizeof words_);
|
28
|
+
}
|
29
|
+
|
30
|
+
// Tests the bit with index c.
|
31
|
+
bool Test(int c) const {
|
32
|
+
DCHECK_GE(c, 0);
|
33
|
+
DCHECK_LE(c, 255);
|
34
|
+
|
35
|
+
return (words_[c / 64] & (uint64_t{1} << (c % 64))) != 0;
|
36
|
+
}
|
37
|
+
|
38
|
+
// Sets the bit with index c.
|
39
|
+
void Set(int c) {
|
40
|
+
DCHECK_GE(c, 0);
|
41
|
+
DCHECK_LE(c, 255);
|
42
|
+
|
43
|
+
words_[c / 64] |= (uint64_t{1} << (c % 64));
|
44
|
+
}
|
45
|
+
|
46
|
+
// Finds the next non-zero bit with index >= c.
|
47
|
+
// Returns -1 if no such bit exists.
|
48
|
+
int FindNextSetBit(int c) const;
|
49
|
+
|
50
|
+
private:
|
51
|
+
// Finds the least significant non-zero bit in n.
|
52
|
+
static int FindLSBSet(uint64_t n) {
|
53
|
+
DCHECK_NE(n, 0);
|
54
|
+
#if defined(__GNUC__)
|
55
|
+
return __builtin_ctzll(n);
|
56
|
+
#elif defined(_MSC_VER) && defined(_M_X64)
|
57
|
+
unsigned long c;
|
58
|
+
_BitScanForward64(&c, n);
|
59
|
+
return static_cast<int>(c);
|
60
|
+
#elif defined(_MSC_VER) && defined(_M_IX86)
|
61
|
+
unsigned long c;
|
62
|
+
if (static_cast<uint32_t>(n) != 0) {
|
63
|
+
_BitScanForward(&c, static_cast<uint32_t>(n));
|
64
|
+
return static_cast<int>(c);
|
65
|
+
} else {
|
66
|
+
_BitScanForward(&c, static_cast<uint32_t>(n >> 32));
|
67
|
+
return static_cast<int>(c) + 32;
|
68
|
+
}
|
69
|
+
#else
|
70
|
+
int c = 63;
|
71
|
+
for (int shift = 1 << 5; shift != 0; shift >>= 1) {
|
72
|
+
uint64_t word = n << shift;
|
73
|
+
if (word != 0) {
|
74
|
+
n = word;
|
75
|
+
c -= shift;
|
76
|
+
}
|
77
|
+
}
|
78
|
+
return c;
|
79
|
+
#endif
|
80
|
+
}
|
81
|
+
|
82
|
+
uint64_t words_[4];
|
83
|
+
};
|
84
|
+
|
85
|
+
int Bitmap256::FindNextSetBit(int c) const {
|
86
|
+
DCHECK_GE(c, 0);
|
87
|
+
DCHECK_LE(c, 255);
|
88
|
+
|
89
|
+
// Check the word that contains the bit. Mask out any lower bits.
|
90
|
+
int i = c / 64;
|
91
|
+
uint64_t word = words_[i] & (~uint64_t{0} << (c % 64));
|
92
|
+
if (word != 0)
|
93
|
+
return (i * 64) + FindLSBSet(word);
|
94
|
+
|
95
|
+
// Check any following words.
|
96
|
+
i++;
|
97
|
+
switch (i) {
|
98
|
+
case 1:
|
99
|
+
if (words_[1] != 0)
|
100
|
+
return (1 * 64) + FindLSBSet(words_[1]);
|
101
|
+
FALLTHROUGH_INTENDED;
|
102
|
+
case 2:
|
103
|
+
if (words_[2] != 0)
|
104
|
+
return (2 * 64) + FindLSBSet(words_[2]);
|
105
|
+
FALLTHROUGH_INTENDED;
|
106
|
+
case 3:
|
107
|
+
if (words_[3] != 0)
|
108
|
+
return (3 * 64) + FindLSBSet(words_[3]);
|
109
|
+
FALLTHROUGH_INTENDED;
|
110
|
+
default:
|
111
|
+
return -1;
|
112
|
+
}
|
113
|
+
}
|
114
|
+
|
115
|
+
} // namespace re2
|
116
|
+
|
117
|
+
#endif // RE2_BITMAP256_H_
|
@@ -0,0 +1,385 @@
|
|
1
|
+
// Copyright 2008 The RE2 Authors. All Rights Reserved.
|
2
|
+
// Use of this source code is governed by a BSD-style
|
3
|
+
// license that can be found in the LICENSE file.
|
4
|
+
|
5
|
+
// Tested by search_test.cc, exhaustive_test.cc, tester.cc
|
6
|
+
|
7
|
+
// Prog::SearchBitState is a regular expression search with submatch
|
8
|
+
// tracking for small regular expressions and texts. Similarly to
|
9
|
+
// testing/backtrack.cc, it allocates a bitmap with (count of
|
10
|
+
// lists) * (length of text) bits to make sure it never explores the
|
11
|
+
// same (instruction list, character position) multiple times. This
|
12
|
+
// limits the search to run in time linear in the length of the text.
|
13
|
+
//
|
14
|
+
// Unlike testing/backtrack.cc, SearchBitState is not recursive
|
15
|
+
// on the text.
|
16
|
+
//
|
17
|
+
// SearchBitState is a fast replacement for the NFA code on small
|
18
|
+
// regexps and texts when SearchOnePass cannot be used.
|
19
|
+
|
20
|
+
#include <stddef.h>
|
21
|
+
#include <stdint.h>
|
22
|
+
#include <string.h>
|
23
|
+
#include <limits>
|
24
|
+
#include <utility>
|
25
|
+
|
26
|
+
#include "util/logging.h"
|
27
|
+
#include "re2/pod_array.h"
|
28
|
+
#include "re2/prog.h"
|
29
|
+
#include "re2/regexp.h"
|
30
|
+
|
31
|
+
namespace re2 {
|
32
|
+
|
33
|
+
struct Job {
|
34
|
+
int id;
|
35
|
+
int rle; // run length encoding
|
36
|
+
const char* p;
|
37
|
+
};
|
38
|
+
|
39
|
+
class BitState {
|
40
|
+
public:
|
41
|
+
explicit BitState(Prog* prog);
|
42
|
+
|
43
|
+
// The usual Search prototype.
|
44
|
+
// Can only call Search once per BitState.
|
45
|
+
bool Search(const StringPiece& text, const StringPiece& context,
|
46
|
+
bool anchored, bool longest,
|
47
|
+
StringPiece* submatch, int nsubmatch);
|
48
|
+
|
49
|
+
private:
|
50
|
+
inline bool ShouldVisit(int id, const char* p);
|
51
|
+
void Push(int id, const char* p);
|
52
|
+
void GrowStack();
|
53
|
+
bool TrySearch(int id, const char* p);
|
54
|
+
|
55
|
+
// Search parameters
|
56
|
+
Prog* prog_; // program being run
|
57
|
+
StringPiece text_; // text being searched
|
58
|
+
StringPiece context_; // greater context of text being searched
|
59
|
+
bool anchored_; // whether search is anchored at text.begin()
|
60
|
+
bool longest_; // whether search wants leftmost-longest match
|
61
|
+
bool endmatch_; // whether match must end at text.end()
|
62
|
+
StringPiece* submatch_; // submatches to fill in
|
63
|
+
int nsubmatch_; // # of submatches to fill in
|
64
|
+
|
65
|
+
// Search state
|
66
|
+
static constexpr int kVisitedBits = 64;
|
67
|
+
PODArray<uint64_t> visited_; // bitmap: (list ID, char*) pairs visited
|
68
|
+
PODArray<const char*> cap_; // capture registers
|
69
|
+
PODArray<Job> job_; // stack of text positions to explore
|
70
|
+
int njob_; // stack size
|
71
|
+
|
72
|
+
BitState(const BitState&) = delete;
|
73
|
+
BitState& operator=(const BitState&) = delete;
|
74
|
+
};
|
75
|
+
|
76
|
+
BitState::BitState(Prog* prog)
|
77
|
+
: prog_(prog),
|
78
|
+
anchored_(false),
|
79
|
+
longest_(false),
|
80
|
+
endmatch_(false),
|
81
|
+
submatch_(NULL),
|
82
|
+
nsubmatch_(0),
|
83
|
+
njob_(0) {
|
84
|
+
}
|
85
|
+
|
86
|
+
// Given id, which *must* be a list head, we can look up its list ID.
|
87
|
+
// Then the question is: Should the search visit the (list ID, p) pair?
|
88
|
+
// If so, remember that it was visited so that the next time,
|
89
|
+
// we don't repeat the visit.
|
90
|
+
bool BitState::ShouldVisit(int id, const char* p) {
|
91
|
+
int n = prog_->list_heads()[id] * static_cast<int>(text_.size()+1) +
|
92
|
+
static_cast<int>(p-text_.data());
|
93
|
+
if (visited_[n/kVisitedBits] & (uint64_t{1} << (n & (kVisitedBits-1))))
|
94
|
+
return false;
|
95
|
+
visited_[n/kVisitedBits] |= uint64_t{1} << (n & (kVisitedBits-1));
|
96
|
+
return true;
|
97
|
+
}
|
98
|
+
|
99
|
+
// Grow the stack.
|
100
|
+
void BitState::GrowStack() {
|
101
|
+
PODArray<Job> tmp(2*job_.size());
|
102
|
+
memmove(tmp.data(), job_.data(), njob_*sizeof job_[0]);
|
103
|
+
job_ = std::move(tmp);
|
104
|
+
}
|
105
|
+
|
106
|
+
// Push (id, p) onto the stack, growing it if necessary.
|
107
|
+
void BitState::Push(int id, const char* p) {
|
108
|
+
if (njob_ >= job_.size()) {
|
109
|
+
GrowStack();
|
110
|
+
if (njob_ >= job_.size()) {
|
111
|
+
LOG(DFATAL) << "GrowStack() failed: "
|
112
|
+
<< "njob_ = " << njob_ << ", "
|
113
|
+
<< "job_.size() = " << job_.size();
|
114
|
+
return;
|
115
|
+
}
|
116
|
+
}
|
117
|
+
|
118
|
+
// If id < 0, it's undoing a Capture,
|
119
|
+
// so we mustn't interfere with that.
|
120
|
+
if (id >= 0 && njob_ > 0) {
|
121
|
+
Job* top = &job_[njob_-1];
|
122
|
+
if (id == top->id &&
|
123
|
+
p == top->p + top->rle + 1 &&
|
124
|
+
top->rle < std::numeric_limits<int>::max()) {
|
125
|
+
++top->rle;
|
126
|
+
return;
|
127
|
+
}
|
128
|
+
}
|
129
|
+
|
130
|
+
Job* top = &job_[njob_++];
|
131
|
+
top->id = id;
|
132
|
+
top->rle = 0;
|
133
|
+
top->p = p;
|
134
|
+
}
|
135
|
+
|
136
|
+
// Try a search from instruction id0 in state p0.
|
137
|
+
// Return whether it succeeded.
|
138
|
+
bool BitState::TrySearch(int id0, const char* p0) {
|
139
|
+
bool matched = false;
|
140
|
+
const char* end = text_.data() + text_.size();
|
141
|
+
njob_ = 0;
|
142
|
+
// Push() no longer checks ShouldVisit(),
|
143
|
+
// so we must perform the check ourselves.
|
144
|
+
if (ShouldVisit(id0, p0))
|
145
|
+
Push(id0, p0);
|
146
|
+
while (njob_ > 0) {
|
147
|
+
// Pop job off stack.
|
148
|
+
--njob_;
|
149
|
+
int id = job_[njob_].id;
|
150
|
+
int& rle = job_[njob_].rle;
|
151
|
+
const char* p = job_[njob_].p;
|
152
|
+
|
153
|
+
if (id < 0) {
|
154
|
+
// Undo the Capture.
|
155
|
+
cap_[prog_->inst(-id)->cap()] = p;
|
156
|
+
continue;
|
157
|
+
}
|
158
|
+
|
159
|
+
if (rle > 0) {
|
160
|
+
p += rle;
|
161
|
+
// Revivify job on stack.
|
162
|
+
--rle;
|
163
|
+
++njob_;
|
164
|
+
}
|
165
|
+
|
166
|
+
Loop:
|
167
|
+
// Visit id, p.
|
168
|
+
Prog::Inst* ip = prog_->inst(id);
|
169
|
+
switch (ip->opcode()) {
|
170
|
+
default:
|
171
|
+
LOG(DFATAL) << "Unexpected opcode: " << ip->opcode();
|
172
|
+
return false;
|
173
|
+
|
174
|
+
case kInstFail:
|
175
|
+
break;
|
176
|
+
|
177
|
+
case kInstAltMatch:
|
178
|
+
if (ip->greedy(prog_)) {
|
179
|
+
// out1 is the Match instruction.
|
180
|
+
id = ip->out1();
|
181
|
+
p = end;
|
182
|
+
goto Loop;
|
183
|
+
}
|
184
|
+
if (longest_) {
|
185
|
+
// ip must be non-greedy...
|
186
|
+
// out is the Match instruction.
|
187
|
+
id = ip->out();
|
188
|
+
p = end;
|
189
|
+
goto Loop;
|
190
|
+
}
|
191
|
+
goto Next;
|
192
|
+
|
193
|
+
case kInstByteRange: {
|
194
|
+
int c = -1;
|
195
|
+
if (p < end)
|
196
|
+
c = *p & 0xFF;
|
197
|
+
if (!ip->Matches(c))
|
198
|
+
goto Next;
|
199
|
+
|
200
|
+
if (ip->hint() != 0)
|
201
|
+
Push(id+ip->hint(), p); // try the next when we're done
|
202
|
+
id = ip->out();
|
203
|
+
p++;
|
204
|
+
goto CheckAndLoop;
|
205
|
+
}
|
206
|
+
|
207
|
+
case kInstCapture:
|
208
|
+
if (!ip->last())
|
209
|
+
Push(id+1, p); // try the next when we're done
|
210
|
+
|
211
|
+
if (0 <= ip->cap() && ip->cap() < cap_.size()) {
|
212
|
+
// Capture p to register, but save old value first.
|
213
|
+
Push(-id, cap_[ip->cap()]); // undo when we're done
|
214
|
+
cap_[ip->cap()] = p;
|
215
|
+
}
|
216
|
+
|
217
|
+
id = ip->out();
|
218
|
+
goto CheckAndLoop;
|
219
|
+
|
220
|
+
case kInstEmptyWidth:
|
221
|
+
if (ip->empty() & ~Prog::EmptyFlags(context_, p))
|
222
|
+
goto Next;
|
223
|
+
|
224
|
+
if (!ip->last())
|
225
|
+
Push(id+1, p); // try the next when we're done
|
226
|
+
id = ip->out();
|
227
|
+
goto CheckAndLoop;
|
228
|
+
|
229
|
+
case kInstNop:
|
230
|
+
if (!ip->last())
|
231
|
+
Push(id+1, p); // try the next when we're done
|
232
|
+
id = ip->out();
|
233
|
+
|
234
|
+
CheckAndLoop:
|
235
|
+
// Sanity check: id is the head of its list, which must
|
236
|
+
// be the case if id-1 is the last of *its* list. :)
|
237
|
+
DCHECK(id == 0 || prog_->inst(id-1)->last());
|
238
|
+
if (ShouldVisit(id, p))
|
239
|
+
goto Loop;
|
240
|
+
break;
|
241
|
+
|
242
|
+
case kInstMatch: {
|
243
|
+
if (endmatch_ && p != end)
|
244
|
+
goto Next;
|
245
|
+
|
246
|
+
// We found a match. If the caller doesn't care
|
247
|
+
// where the match is, no point going further.
|
248
|
+
if (nsubmatch_ == 0)
|
249
|
+
return true;
|
250
|
+
|
251
|
+
// Record best match so far.
|
252
|
+
// Only need to check end point, because this entire
|
253
|
+
// call is only considering one start position.
|
254
|
+
matched = true;
|
255
|
+
cap_[1] = p;
|
256
|
+
if (submatch_[0].data() == NULL ||
|
257
|
+
(longest_ && p > submatch_[0].data() + submatch_[0].size())) {
|
258
|
+
for (int i = 0; i < nsubmatch_; i++)
|
259
|
+
submatch_[i] =
|
260
|
+
StringPiece(cap_[2 * i],
|
261
|
+
static_cast<size_t>(cap_[2 * i + 1] - cap_[2 * i]));
|
262
|
+
}
|
263
|
+
|
264
|
+
// If going for first match, we're done.
|
265
|
+
if (!longest_)
|
266
|
+
return true;
|
267
|
+
|
268
|
+
// If we used the entire text, no longer match is possible.
|
269
|
+
if (p == end)
|
270
|
+
return true;
|
271
|
+
|
272
|
+
// Otherwise, continue on in hope of a longer match.
|
273
|
+
// Note the absence of the ShouldVisit() check here
|
274
|
+
// due to execution remaining in the same list.
|
275
|
+
Next:
|
276
|
+
if (!ip->last()) {
|
277
|
+
id++;
|
278
|
+
goto Loop;
|
279
|
+
}
|
280
|
+
break;
|
281
|
+
}
|
282
|
+
}
|
283
|
+
}
|
284
|
+
return matched;
|
285
|
+
}
|
286
|
+
|
287
|
+
// Search text (within context) for prog_.
|
288
|
+
bool BitState::Search(const StringPiece& text, const StringPiece& context,
|
289
|
+
bool anchored, bool longest,
|
290
|
+
StringPiece* submatch, int nsubmatch) {
|
291
|
+
// Search parameters.
|
292
|
+
text_ = text;
|
293
|
+
context_ = context;
|
294
|
+
if (context_.data() == NULL)
|
295
|
+
context_ = text;
|
296
|
+
if (prog_->anchor_start() && context_.begin() != text.begin())
|
297
|
+
return false;
|
298
|
+
if (prog_->anchor_end() && context_.end() != text.end())
|
299
|
+
return false;
|
300
|
+
anchored_ = anchored || prog_->anchor_start();
|
301
|
+
longest_ = longest || prog_->anchor_end();
|
302
|
+
endmatch_ = prog_->anchor_end();
|
303
|
+
submatch_ = submatch;
|
304
|
+
nsubmatch_ = nsubmatch;
|
305
|
+
for (int i = 0; i < nsubmatch_; i++)
|
306
|
+
submatch_[i] = StringPiece();
|
307
|
+
|
308
|
+
// Allocate scratch space.
|
309
|
+
int nvisited = prog_->list_count() * static_cast<int>(text.size()+1);
|
310
|
+
nvisited = (nvisited + kVisitedBits-1) / kVisitedBits;
|
311
|
+
visited_ = PODArray<uint64_t>(nvisited);
|
312
|
+
memset(visited_.data(), 0, nvisited*sizeof visited_[0]);
|
313
|
+
|
314
|
+
int ncap = 2*nsubmatch;
|
315
|
+
if (ncap < 2)
|
316
|
+
ncap = 2;
|
317
|
+
cap_ = PODArray<const char*>(ncap);
|
318
|
+
memset(cap_.data(), 0, ncap*sizeof cap_[0]);
|
319
|
+
|
320
|
+
// When sizeof(Job) == 16, we start with a nice round 1KiB. :)
|
321
|
+
job_ = PODArray<Job>(64);
|
322
|
+
|
323
|
+
// Anchored search must start at text.begin().
|
324
|
+
if (anchored_) {
|
325
|
+
cap_[0] = text.data();
|
326
|
+
return TrySearch(prog_->start(), text.data());
|
327
|
+
}
|
328
|
+
|
329
|
+
// Unanchored search, starting from each possible text position.
|
330
|
+
// Notice that we have to try the empty string at the end of
|
331
|
+
// the text, so the loop condition is p <= text.end(), not p < text.end().
|
332
|
+
// This looks like it's quadratic in the size of the text,
|
333
|
+
// but we are not clearing visited_ between calls to TrySearch,
|
334
|
+
// so no work is duplicated and it ends up still being linear.
|
335
|
+
const char* etext = text.data() + text.size();
|
336
|
+
for (const char* p = text.data(); p <= etext; p++) {
|
337
|
+
// Try to use prefix accel (e.g. memchr) to skip ahead.
|
338
|
+
if (p < etext && prog_->can_prefix_accel()) {
|
339
|
+
p = reinterpret_cast<const char*>(prog_->PrefixAccel(p, etext - p));
|
340
|
+
if (p == NULL)
|
341
|
+
p = etext;
|
342
|
+
}
|
343
|
+
|
344
|
+
cap_[0] = p;
|
345
|
+
if (TrySearch(prog_->start(), p)) // Match must be leftmost; done.
|
346
|
+
return true;
|
347
|
+
// Avoid invoking undefined behavior (arithmetic on a null pointer)
|
348
|
+
// by simply not continuing the loop.
|
349
|
+
if (p == NULL)
|
350
|
+
break;
|
351
|
+
}
|
352
|
+
return false;
|
353
|
+
}
|
354
|
+
|
355
|
+
// Bit-state search.
|
356
|
+
bool Prog::SearchBitState(const StringPiece& text,
|
357
|
+
const StringPiece& context,
|
358
|
+
Anchor anchor,
|
359
|
+
MatchKind kind,
|
360
|
+
StringPiece* match,
|
361
|
+
int nmatch) {
|
362
|
+
// If full match, we ask for an anchored longest match
|
363
|
+
// and then check that match[0] == text.
|
364
|
+
// So make sure match[0] exists.
|
365
|
+
StringPiece sp0;
|
366
|
+
if (kind == kFullMatch) {
|
367
|
+
anchor = kAnchored;
|
368
|
+
if (nmatch < 1) {
|
369
|
+
match = &sp0;
|
370
|
+
nmatch = 1;
|
371
|
+
}
|
372
|
+
}
|
373
|
+
|
374
|
+
// Run the search.
|
375
|
+
BitState b(this);
|
376
|
+
bool anchored = anchor == kAnchored;
|
377
|
+
bool longest = kind != kFirstMatch;
|
378
|
+
if (!b.Search(text, context, anchored, longest, match, nmatch))
|
379
|
+
return false;
|
380
|
+
if (kind == kFullMatch && match[0].end() != text.end())
|
381
|
+
return false;
|
382
|
+
return true;
|
383
|
+
}
|
384
|
+
|
385
|
+
} // namespace re2
|