re2 1.10.2 → 1.11.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/.prettierrc +3 -1
- package/.travis.yml +1 -1
- package/README.md +9 -8
- package/lib/addon.cc +4 -6
- package/lib/exec.cc +8 -0
- package/lib/wrapped_re2.h +1 -1
- package/package.json +5 -3
- package/re2.d.ts +5 -1
- package/tests/test_exec.js +1 -0
- package/vendor/re2/bitstate.cc +5 -1
- package/vendor/re2/compile.cc +1 -1
- package/vendor/re2/dfa.cc +8 -11
- package/vendor/re2/nfa.cc +33 -16
- package/vendor/re2/onepass.cc +4 -4
- package/vendor/re2/parse.cc +32 -32
- package/vendor/{util → re2}/pod_array.h +3 -3
- package/vendor/re2/prefilter_tree.h +1 -1
- package/vendor/re2/prog.h +3 -3
- package/vendor/re2/re2.cc +3 -3
- package/vendor/re2/set.cc +2 -2
- package/vendor/re2/simplify.cc +1 -1
- package/vendor/{util → re2}/sparse_array.h +4 -4
- package/vendor/{util → re2}/sparse_set.h +4 -4
- package/vendor/re2/testing/backtrack.cc +4 -0
- package/vendor/re2/testing/dfa_test.cc +12 -10
- package/vendor/re2/testing/dump.cc +4 -10
- package/vendor/re2/testing/exhaustive1_test.cc +2 -7
- package/vendor/re2/testing/exhaustive2_test.cc +0 -1
- package/vendor/re2/testing/exhaustive_tester.cc +11 -8
- package/vendor/re2/testing/random_test.cc +9 -7
- package/vendor/re2/testing/regexp_benchmark.cc +435 -404
- package/vendor/re2/testing/regexp_generator.cc +1 -1
- package/vendor/re2/testing/tester.cc +19 -14
- package/vendor/re2/walker-inl.h +1 -1
- package/vendor/util/benchmark.cc +83 -113
- package/vendor/util/benchmark.h +138 -25
- package/vendor/util/flags.h +8 -11
- package/vendor/util/malloc_counter.h +19 -0
- package/vendor/util/pcre.cc +7 -31
- package/vendor/util/test.cc +4 -1
- package/vendor/util/test.h +4 -12
- package/vendor/util/util.h +8 -0
|
@@ -256,7 +256,7 @@ std::vector<std::string> Explode(const StringPiece& s) {
|
|
|
256
256
|
std::vector<std::string> Split(const StringPiece& sep, const StringPiece& s) {
|
|
257
257
|
std::vector<std::string> v;
|
|
258
258
|
|
|
259
|
-
if (sep.
|
|
259
|
+
if (sep.empty())
|
|
260
260
|
return Explode(s);
|
|
261
261
|
|
|
262
262
|
const char *p = s.data();
|
|
@@ -18,14 +18,15 @@
|
|
|
18
18
|
#include "re2/re2.h"
|
|
19
19
|
#include "re2/regexp.h"
|
|
20
20
|
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
21
|
+
DEFINE_FLAG(bool, dump_prog, false, "dump regexp program");
|
|
22
|
+
DEFINE_FLAG(bool, log_okay, false, "log successful runs");
|
|
23
|
+
DEFINE_FLAG(bool, dump_rprog, false, "dump reversed regexp program");
|
|
24
24
|
|
|
25
|
-
|
|
26
|
-
|
|
25
|
+
DEFINE_FLAG(int, max_regexp_failures, 100,
|
|
26
|
+
"maximum number of regexp test failures (-1 = unlimited)");
|
|
27
27
|
|
|
28
|
-
|
|
28
|
+
DEFINE_FLAG(std::string, regexp_engines, "",
|
|
29
|
+
"pattern to select regexp engines to test");
|
|
29
30
|
|
|
30
31
|
namespace re2 {
|
|
31
32
|
|
|
@@ -62,11 +63,11 @@ static uint32_t Engines() {
|
|
|
62
63
|
if (did_parse)
|
|
63
64
|
return cached_engines;
|
|
64
65
|
|
|
65
|
-
if (FLAGS_regexp_engines.empty()) {
|
|
66
|
+
if (GetFlag(FLAGS_regexp_engines).empty()) {
|
|
66
67
|
cached_engines = ~0;
|
|
67
68
|
} else {
|
|
68
69
|
for (Engine i = static_cast<Engine>(0); i < kEngineMax; i++)
|
|
69
|
-
if (FLAGS_regexp_engines.find(EngineName(i)) != std::string::npos)
|
|
70
|
+
if (GetFlag(FLAGS_regexp_engines).find(EngineName(i)) != std::string::npos)
|
|
70
71
|
cached_engines |= 1<<i;
|
|
71
72
|
}
|
|
72
73
|
|
|
@@ -102,7 +103,8 @@ static std::string FormatCapture(const StringPiece& text,
|
|
|
102
103
|
if (s.data() == NULL)
|
|
103
104
|
return "(?,?)";
|
|
104
105
|
return StringPrintf("(%td,%td)",
|
|
105
|
-
s.begin() - text.begin(),
|
|
106
|
+
s.begin() - text.begin(),
|
|
107
|
+
s.end() - text.begin());
|
|
106
108
|
}
|
|
107
109
|
|
|
108
110
|
// Returns whether text contains non-ASCII (>= 0x80) bytes.
|
|
@@ -198,7 +200,7 @@ TestInstance::TestInstance(const StringPiece& regexp_str, Prog::MatchKind kind,
|
|
|
198
200
|
error_ = true;
|
|
199
201
|
return;
|
|
200
202
|
}
|
|
201
|
-
if (FLAGS_dump_prog) {
|
|
203
|
+
if (GetFlag(FLAGS_dump_prog)) {
|
|
202
204
|
LOG(INFO) << "Prog for "
|
|
203
205
|
<< " regexp "
|
|
204
206
|
<< CEscape(regexp_str_)
|
|
@@ -216,7 +218,7 @@ TestInstance::TestInstance(const StringPiece& regexp_str, Prog::MatchKind kind,
|
|
|
216
218
|
error_ = true;
|
|
217
219
|
return;
|
|
218
220
|
}
|
|
219
|
-
if (FLAGS_dump_rprog)
|
|
221
|
+
if (GetFlag(FLAGS_dump_rprog))
|
|
220
222
|
LOG(INFO) << rprog_->Dump();
|
|
221
223
|
}
|
|
222
224
|
|
|
@@ -528,7 +530,7 @@ bool TestInstance::RunCase(const StringPiece& text, const StringPiece& context,
|
|
|
528
530
|
Result r;
|
|
529
531
|
RunSearch(i, text, context, anchor, &r);
|
|
530
532
|
if (ResultOkay(r, correct)) {
|
|
531
|
-
if (FLAGS_log_okay)
|
|
533
|
+
if (GetFlag(FLAGS_log_okay))
|
|
532
534
|
LogMatch(r.skipped ? "Skipped: " : "Okay: ", i, text, context, anchor);
|
|
533
535
|
continue;
|
|
534
536
|
}
|
|
@@ -571,7 +573,10 @@ bool TestInstance::RunCase(const StringPiece& text, const StringPiece& context,
|
|
|
571
573
|
}
|
|
572
574
|
|
|
573
575
|
if (!all_okay) {
|
|
574
|
-
|
|
576
|
+
// This will be initialised once (after flags have been initialised)
|
|
577
|
+
// and that is desirable because we want to enforce a global limit.
|
|
578
|
+
static int max_regexp_failures = GetFlag(FLAGS_max_regexp_failures);
|
|
579
|
+
if (max_regexp_failures > 0 && --max_regexp_failures == 0)
|
|
575
580
|
LOG(QFATAL) << "Too many regexp failures.";
|
|
576
581
|
}
|
|
577
582
|
|
|
@@ -640,7 +645,7 @@ static Prog::Anchor anchors[] = {
|
|
|
640
645
|
|
|
641
646
|
bool Tester::TestInput(const StringPiece& text) {
|
|
642
647
|
bool okay = TestInputInContext(text, text);
|
|
643
|
-
if (text.
|
|
648
|
+
if (!text.empty()) {
|
|
644
649
|
StringPiece sp;
|
|
645
650
|
sp = text;
|
|
646
651
|
sp.remove_prefix(1);
|
package/vendor/re2/walker-inl.h
CHANGED
|
@@ -150,7 +150,7 @@ template<typename T> void Regexp::Walker<T>::Reset() {
|
|
|
150
150
|
if (stack_ && stack_->size() > 0) {
|
|
151
151
|
LOG(DFATAL) << "Stack not empty.";
|
|
152
152
|
while (stack_->size() > 0) {
|
|
153
|
-
delete stack_->top().child_args;
|
|
153
|
+
delete[] stack_->top().child_args;
|
|
154
154
|
stack_->pop();
|
|
155
155
|
}
|
|
156
156
|
}
|
package/vendor/util/benchmark.cc
CHANGED
|
@@ -7,155 +7,125 @@
|
|
|
7
7
|
#include <stdlib.h>
|
|
8
8
|
#include <algorithm>
|
|
9
9
|
#include <chrono>
|
|
10
|
-
#include <thread>
|
|
11
10
|
|
|
12
|
-
#include "util/util.h"
|
|
13
|
-
#include "util/flags.h"
|
|
14
11
|
#include "util/benchmark.h"
|
|
12
|
+
#include "util/flags.h"
|
|
15
13
|
#include "re2/re2.h"
|
|
16
14
|
|
|
17
|
-
DEFINE_string(test_tmpdir, "/var/tmp", "temp directory");
|
|
18
|
-
|
|
19
15
|
#ifdef _WIN32
|
|
20
16
|
#define snprintf _snprintf
|
|
21
17
|
#endif
|
|
22
18
|
|
|
23
|
-
using testing::Benchmark;
|
|
19
|
+
using ::testing::Benchmark;
|
|
24
20
|
|
|
25
21
|
static Benchmark* benchmarks[10000];
|
|
26
22
|
static int nbenchmarks;
|
|
27
23
|
|
|
28
24
|
void Benchmark::Register() {
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
if(hi < lo)
|
|
33
|
-
hi = lo;
|
|
34
|
-
nbenchmarks++;
|
|
25
|
+
lo_ = std::max(1, lo_);
|
|
26
|
+
hi_ = std::max(lo_, hi_);
|
|
27
|
+
benchmarks[nbenchmarks++] = this;
|
|
35
28
|
}
|
|
36
29
|
|
|
37
30
|
static int64_t nsec() {
|
|
38
|
-
|
|
39
|
-
|
|
31
|
+
return std::chrono::duration_cast<std::chrono::nanoseconds>(
|
|
32
|
+
std::chrono::steady_clock::now().time_since_epoch())
|
|
33
|
+
.count();
|
|
40
34
|
}
|
|
41
35
|
|
|
42
|
-
static int64_t bytes;
|
|
43
|
-
static int64_t ns;
|
|
44
36
|
static int64_t t0;
|
|
37
|
+
static int64_t ns;
|
|
38
|
+
static int64_t bytes;
|
|
45
39
|
static int64_t items;
|
|
46
40
|
|
|
47
|
-
void SetBenchmarkBytesProcessed(int64_t x) {
|
|
48
|
-
bytes = x;
|
|
49
|
-
}
|
|
50
|
-
|
|
51
|
-
void StopBenchmarkTiming() {
|
|
52
|
-
if(t0 != 0)
|
|
53
|
-
ns += nsec() - t0;
|
|
54
|
-
t0 = 0;
|
|
55
|
-
}
|
|
56
|
-
|
|
57
41
|
void StartBenchmarkTiming() {
|
|
58
|
-
|
|
59
|
-
|
|
42
|
+
if (t0 == 0) {
|
|
43
|
+
t0 = nsec();
|
|
44
|
+
}
|
|
60
45
|
}
|
|
61
46
|
|
|
62
|
-
void
|
|
63
|
-
|
|
47
|
+
void StopBenchmarkTiming() {
|
|
48
|
+
if (t0 != 0) {
|
|
49
|
+
ns += nsec() - t0;
|
|
50
|
+
t0 = 0;
|
|
51
|
+
}
|
|
64
52
|
}
|
|
65
53
|
|
|
66
|
-
void
|
|
67
|
-
// TODO(rsc): Implement.
|
|
68
|
-
}
|
|
54
|
+
void SetBenchmarkBytesProcessed(int64_t b) { bytes = b; }
|
|
69
55
|
|
|
70
|
-
|
|
71
|
-
return static_cast<int>(std::thread::hardware_concurrency());
|
|
72
|
-
}
|
|
56
|
+
void SetBenchmarkItemsProcessed(int64_t i) { items = i; }
|
|
73
57
|
|
|
74
|
-
static void
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
else if(b->fnr)
|
|
82
|
-
b->fnr(n, siz);
|
|
83
|
-
else {
|
|
84
|
-
fprintf(stderr, "%s: missing function\n", b->name);
|
|
85
|
-
abort();
|
|
86
|
-
}
|
|
87
|
-
if(t0 != 0)
|
|
88
|
-
ns += nsec() - t0;
|
|
58
|
+
static void RunFunc(Benchmark* b, int iters, int arg) {
|
|
59
|
+
t0 = nsec();
|
|
60
|
+
ns = 0;
|
|
61
|
+
bytes = 0;
|
|
62
|
+
items = 0;
|
|
63
|
+
b->func()(iters, arg);
|
|
64
|
+
StopBenchmarkTiming();
|
|
89
65
|
}
|
|
90
66
|
|
|
91
67
|
static int round(int n) {
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
return 2*base;
|
|
98
|
-
if(n < 5*base)
|
|
99
|
-
return 5*base;
|
|
100
|
-
return 10*base;
|
|
68
|
+
int base = 1;
|
|
69
|
+
while (base * 10 < n) base *= 10;
|
|
70
|
+
if (n < 2 * base) return 2 * base;
|
|
71
|
+
if (n < 5 * base) return 5 * base;
|
|
72
|
+
return 10 * base;
|
|
101
73
|
}
|
|
102
74
|
|
|
103
|
-
void RunBench(Benchmark* b, int
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
|
|
121
|
-
|
|
122
|
-
|
|
123
|
-
|
|
124
|
-
|
|
125
|
-
|
|
126
|
-
|
|
127
|
-
|
|
128
|
-
|
|
129
|
-
|
|
130
|
-
|
|
131
|
-
|
|
132
|
-
|
|
133
|
-
|
|
134
|
-
|
|
135
|
-
|
|
136
|
-
|
|
137
|
-
|
|
138
|
-
|
|
139
|
-
|
|
140
|
-
fflush(stdout);
|
|
75
|
+
static void RunBench(Benchmark* b, int arg) {
|
|
76
|
+
int iters, last;
|
|
77
|
+
|
|
78
|
+
// Run once just in case it's expensive.
|
|
79
|
+
iters = 1;
|
|
80
|
+
RunFunc(b, iters, arg);
|
|
81
|
+
while (ns < (int)1e9 && iters < (int)1e9) {
|
|
82
|
+
last = iters;
|
|
83
|
+
if (ns / iters == 0) {
|
|
84
|
+
iters = (int)1e9;
|
|
85
|
+
} else {
|
|
86
|
+
iters = (int)1e9 / static_cast<int>(ns / iters);
|
|
87
|
+
}
|
|
88
|
+
iters = std::max(last + 1, std::min(iters + iters / 2, 100 * last));
|
|
89
|
+
iters = round(iters);
|
|
90
|
+
RunFunc(b, iters, arg);
|
|
91
|
+
}
|
|
92
|
+
|
|
93
|
+
char mb[100];
|
|
94
|
+
char suf[100];
|
|
95
|
+
mb[0] = '\0';
|
|
96
|
+
suf[0] = '\0';
|
|
97
|
+
if (ns > 0 && bytes > 0)
|
|
98
|
+
snprintf(mb, sizeof mb, "\t%7.2f MB/s",
|
|
99
|
+
((double)bytes / 1e6) / ((double)ns / 1e9));
|
|
100
|
+
if (b->has_arg()) {
|
|
101
|
+
if (arg >= (1 << 20)) {
|
|
102
|
+
snprintf(suf, sizeof suf, "/%dM", arg / (1 << 20));
|
|
103
|
+
} else if (arg >= (1 << 10)) {
|
|
104
|
+
snprintf(suf, sizeof suf, "/%dK", arg / (1 << 10));
|
|
105
|
+
} else {
|
|
106
|
+
snprintf(suf, sizeof suf, "/%d", arg);
|
|
107
|
+
}
|
|
108
|
+
}
|
|
109
|
+
printf("%s%s\t%8d\t%10lld ns/op%s\n", b->name(), suf, iters,
|
|
110
|
+
(long long)ns / iters, mb);
|
|
111
|
+
fflush(stdout);
|
|
141
112
|
}
|
|
142
113
|
|
|
143
|
-
static
|
|
144
|
-
|
|
145
|
-
|
|
146
|
-
|
|
147
|
-
|
|
148
|
-
|
|
149
|
-
|
|
114
|
+
static bool WantBench(const char* name, int argc, const char** argv) {
|
|
115
|
+
if (argc == 1) return true;
|
|
116
|
+
for (int i = 1; i < argc; i++) {
|
|
117
|
+
if (RE2::PartialMatch(name, argv[i]))
|
|
118
|
+
return true;
|
|
119
|
+
}
|
|
120
|
+
return false;
|
|
150
121
|
}
|
|
151
122
|
|
|
152
123
|
int main(int argc, const char** argv) {
|
|
153
|
-
|
|
154
|
-
|
|
155
|
-
|
|
156
|
-
|
|
157
|
-
|
|
158
|
-
|
|
159
|
-
|
|
124
|
+
for (int i = 0; i < nbenchmarks; i++) {
|
|
125
|
+
Benchmark* b = benchmarks[i];
|
|
126
|
+
if (!WantBench(b->name(), argc, argv))
|
|
127
|
+
continue;
|
|
128
|
+
for (int arg = b->lo(); arg <= b->hi(); arg <<= 1)
|
|
129
|
+
RunBench(b, arg);
|
|
130
|
+
}
|
|
160
131
|
}
|
|
161
|
-
|
package/vendor/util/benchmark.h
CHANGED
|
@@ -6,38 +6,151 @@
|
|
|
6
6
|
#define UTIL_BENCHMARK_H_
|
|
7
7
|
|
|
8
8
|
#include <stdint.h>
|
|
9
|
+
#include <functional>
|
|
10
|
+
|
|
11
|
+
#include "util/logging.h"
|
|
12
|
+
#include "util/util.h"
|
|
13
|
+
|
|
14
|
+
// Globals for the old benchmark API.
|
|
15
|
+
void StartBenchmarkTiming();
|
|
16
|
+
void StopBenchmarkTiming();
|
|
17
|
+
void SetBenchmarkBytesProcessed(int64_t b);
|
|
18
|
+
void SetBenchmarkItemsProcessed(int64_t i);
|
|
19
|
+
|
|
20
|
+
namespace benchmark {
|
|
21
|
+
|
|
22
|
+
// The new benchmark API implemented as a layer over the old benchmark API.
|
|
23
|
+
// (Please refer to https://github.com/google/benchmark for documentation.)
|
|
24
|
+
class State {
|
|
25
|
+
private:
|
|
26
|
+
class Iterator {
|
|
27
|
+
public:
|
|
28
|
+
// Benchmark code looks like this:
|
|
29
|
+
//
|
|
30
|
+
// for (auto _ : state) {
|
|
31
|
+
// // ...
|
|
32
|
+
// }
|
|
33
|
+
//
|
|
34
|
+
// We try to avoid compiler warnings about such variables being unused.
|
|
35
|
+
struct ATTRIBUTE_UNUSED Value {};
|
|
36
|
+
|
|
37
|
+
explicit Iterator(int64_t iters) : iters_(iters) {}
|
|
38
|
+
|
|
39
|
+
bool operator!=(const Iterator& that) const {
|
|
40
|
+
if (iters_ != that.iters_) {
|
|
41
|
+
return true;
|
|
42
|
+
} else {
|
|
43
|
+
// We are about to stop the loop, so stop timing.
|
|
44
|
+
StopBenchmarkTiming();
|
|
45
|
+
return false;
|
|
46
|
+
}
|
|
47
|
+
}
|
|
48
|
+
|
|
49
|
+
Value operator*() const {
|
|
50
|
+
return Value();
|
|
51
|
+
}
|
|
52
|
+
|
|
53
|
+
Iterator& operator++() {
|
|
54
|
+
--iters_;
|
|
55
|
+
return *this;
|
|
56
|
+
}
|
|
57
|
+
|
|
58
|
+
private:
|
|
59
|
+
int64_t iters_;
|
|
60
|
+
};
|
|
61
|
+
|
|
62
|
+
public:
|
|
63
|
+
explicit State(int64_t iters)
|
|
64
|
+
: iters_(iters), arg_(0), has_arg_(false) {}
|
|
65
|
+
|
|
66
|
+
State(int64_t iters, int64_t arg)
|
|
67
|
+
: iters_(iters), arg_(arg), has_arg_(true) {}
|
|
68
|
+
|
|
69
|
+
Iterator begin() {
|
|
70
|
+
// We are about to start the loop, so start timing.
|
|
71
|
+
StartBenchmarkTiming();
|
|
72
|
+
return Iterator(iters_);
|
|
73
|
+
}
|
|
74
|
+
|
|
75
|
+
Iterator end() {
|
|
76
|
+
return Iterator(0);
|
|
77
|
+
}
|
|
78
|
+
|
|
79
|
+
void SetBytesProcessed(int64_t b) { SetBenchmarkBytesProcessed(b); }
|
|
80
|
+
void SetItemsProcessed(int64_t i) { SetBenchmarkItemsProcessed(i); }
|
|
81
|
+
int64_t iterations() const { return iters_; }
|
|
82
|
+
// Pretend to support multiple arguments.
|
|
83
|
+
int64_t range(int pos) const { CHECK(has_arg_); return arg_; }
|
|
84
|
+
|
|
85
|
+
private:
|
|
86
|
+
int64_t iters_;
|
|
87
|
+
int64_t arg_;
|
|
88
|
+
bool has_arg_;
|
|
89
|
+
|
|
90
|
+
State(const State&) = delete;
|
|
91
|
+
State& operator=(const State&) = delete;
|
|
92
|
+
};
|
|
93
|
+
|
|
94
|
+
} // namespace benchmark
|
|
9
95
|
|
|
10
96
|
namespace testing {
|
|
11
|
-
struct Benchmark {
|
|
12
|
-
const char* name;
|
|
13
|
-
void (*fn)(int);
|
|
14
|
-
void (*fnr)(int, int);
|
|
15
|
-
int lo;
|
|
16
|
-
int hi;
|
|
17
|
-
int threadlo;
|
|
18
|
-
int threadhi;
|
|
19
97
|
|
|
98
|
+
class Benchmark {
|
|
99
|
+
public:
|
|
100
|
+
Benchmark(const char* name, void (*func)(benchmark::State&))
|
|
101
|
+
: name_(name),
|
|
102
|
+
func_([func](int iters, int arg) {
|
|
103
|
+
benchmark::State state(iters);
|
|
104
|
+
func(state);
|
|
105
|
+
}),
|
|
106
|
+
lo_(0),
|
|
107
|
+
hi_(0),
|
|
108
|
+
has_arg_(false) {
|
|
109
|
+
Register();
|
|
110
|
+
}
|
|
111
|
+
|
|
112
|
+
Benchmark(const char* name, void (*func)(benchmark::State&), int lo, int hi)
|
|
113
|
+
: name_(name),
|
|
114
|
+
func_([func](int iters, int arg) {
|
|
115
|
+
benchmark::State state(iters, arg);
|
|
116
|
+
func(state);
|
|
117
|
+
}),
|
|
118
|
+
lo_(lo),
|
|
119
|
+
hi_(hi),
|
|
120
|
+
has_arg_(true) {
|
|
121
|
+
Register();
|
|
122
|
+
}
|
|
123
|
+
|
|
124
|
+
// Pretend to support multiple threads.
|
|
125
|
+
Benchmark* ThreadRange(int lo, int hi) { return this; }
|
|
126
|
+
|
|
127
|
+
const char* name() const { return name_; }
|
|
128
|
+
const std::function<void(int, int)>& func() const { return func_; }
|
|
129
|
+
int lo() const { return lo_; }
|
|
130
|
+
int hi() const { return hi_; }
|
|
131
|
+
bool has_arg() const { return has_arg_; }
|
|
132
|
+
|
|
133
|
+
private:
|
|
20
134
|
void Register();
|
|
21
|
-
Benchmark(const char* name, void (*f)(int)) { Clear(name); fn = f; Register(); }
|
|
22
|
-
Benchmark(const char* name, void (*f)(int, int), int l, int h) { Clear(name); fnr = f; lo = l; hi = h; Register(); }
|
|
23
|
-
void Clear(const char* n) { name = n; fn = 0; fnr = 0; lo = 0; hi = 0; threadlo = 0; threadhi = 0; }
|
|
24
|
-
Benchmark* ThreadRange(int lo, int hi) { threadlo = lo; threadhi = hi; return this; }
|
|
25
|
-
};
|
|
26
|
-
} // namespace testing
|
|
27
135
|
|
|
28
|
-
|
|
29
|
-
void
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
136
|
+
const char* name_;
|
|
137
|
+
std::function<void(int, int)> func_;
|
|
138
|
+
int lo_;
|
|
139
|
+
int hi_;
|
|
140
|
+
bool has_arg_;
|
|
33
141
|
|
|
34
|
-
|
|
142
|
+
Benchmark(const Benchmark&) = delete;
|
|
143
|
+
Benchmark& operator=(const Benchmark&) = delete;
|
|
144
|
+
};
|
|
145
|
+
|
|
146
|
+
} // namespace testing
|
|
35
147
|
|
|
36
|
-
#define BENCHMARK(f)
|
|
37
|
-
|
|
148
|
+
#define BENCHMARK(f) \
|
|
149
|
+
::testing::Benchmark* _benchmark_##f = \
|
|
150
|
+
(new ::testing::Benchmark(#f, f))
|
|
38
151
|
|
|
39
|
-
#define BENCHMARK_RANGE(f, lo, hi)
|
|
40
|
-
|
|
41
|
-
|
|
152
|
+
#define BENCHMARK_RANGE(f, lo, hi) \
|
|
153
|
+
::testing::Benchmark* _benchmark_##f = \
|
|
154
|
+
(new ::testing::Benchmark(#f, f, lo, hi))
|
|
42
155
|
|
|
43
156
|
#endif // UTIL_BENCHMARK_H_
|
package/vendor/util/flags.h
CHANGED
|
@@ -10,20 +10,17 @@
|
|
|
10
10
|
// If you want to do that, see
|
|
11
11
|
// https://gflags.github.io/gflags/
|
|
12
12
|
|
|
13
|
-
#
|
|
14
|
-
|
|
15
|
-
#define DEFINE_flag(type, name, deflt, desc) \
|
|
13
|
+
#define DEFINE_FLAG(type, name, deflt, desc) \
|
|
16
14
|
namespace re2 { type FLAGS_##name = deflt; }
|
|
17
15
|
|
|
18
|
-
#define
|
|
16
|
+
#define DECLARE_FLAG(type, name) \
|
|
19
17
|
namespace re2 { extern type FLAGS_##name; }
|
|
20
18
|
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
#define DECLARE_string(name) DECLARE_flag(std::string, name)
|
|
19
|
+
namespace re2 {
|
|
20
|
+
template <typename T>
|
|
21
|
+
T GetFlag(const T& flag) {
|
|
22
|
+
return flag;
|
|
23
|
+
}
|
|
24
|
+
} // namespace re2
|
|
28
25
|
|
|
29
26
|
#endif // UTIL_FLAGS_H_
|
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
// Copyright 2009 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 UTIL_MALLOC_COUNTER_H_
|
|
6
|
+
#define UTIL_MALLOC_COUNTER_H_
|
|
7
|
+
|
|
8
|
+
namespace testing {
|
|
9
|
+
class MallocCounter {
|
|
10
|
+
public:
|
|
11
|
+
MallocCounter(int x) {}
|
|
12
|
+
static const int THIS_THREAD_ONLY = 0;
|
|
13
|
+
long long HeapGrowth() { return 0; }
|
|
14
|
+
long long PeakHeapGrowth() { return 0; }
|
|
15
|
+
void Reset() {}
|
|
16
|
+
};
|
|
17
|
+
} // namespace testing
|
|
18
|
+
|
|
19
|
+
#endif // UTIL_MALLOC_COUNTER_H_
|
package/vendor/util/pcre.cc
CHANGED
|
@@ -35,9 +35,10 @@
|
|
|
35
35
|
// not exceed main thread stacks. Note that other threads
|
|
36
36
|
// often have smaller stacks, and therefore tightening
|
|
37
37
|
// regexp_stack_limit may frequently be necessary.
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
38
|
+
DEFINE_FLAG(int, regexp_stack_limit, 256 << 10,
|
|
39
|
+
"default PCRE stack limit (bytes)");
|
|
40
|
+
DEFINE_FLAG(int, regexp_match_limit, 1000000,
|
|
41
|
+
"default PCRE match limit (function calls)");
|
|
41
42
|
|
|
42
43
|
#ifndef USEPCRE
|
|
43
44
|
|
|
@@ -523,12 +524,12 @@ int PCRE::TryMatch(const StringPiece& text,
|
|
|
523
524
|
|
|
524
525
|
int match_limit = match_limit_;
|
|
525
526
|
if (match_limit <= 0) {
|
|
526
|
-
match_limit = FLAGS_regexp_match_limit;
|
|
527
|
+
match_limit = GetFlag(FLAGS_regexp_match_limit);
|
|
527
528
|
}
|
|
528
529
|
|
|
529
530
|
int stack_limit = stack_limit_;
|
|
530
531
|
if (stack_limit <= 0) {
|
|
531
|
-
stack_limit = FLAGS_regexp_stack_limit;
|
|
532
|
+
stack_limit = GetFlag(FLAGS_regexp_stack_limit);
|
|
532
533
|
}
|
|
533
534
|
|
|
534
535
|
pcre_extra extra = { 0 };
|
|
@@ -977,32 +978,7 @@ static bool parse_double_float(const char* str, size_t n, bool isfloat,
|
|
|
977
978
|
} else {
|
|
978
979
|
r = strtod(buf, &end);
|
|
979
980
|
}
|
|
980
|
-
if (end != buf + n)
|
|
981
|
-
#ifdef _WIN32
|
|
982
|
-
// Microsoft's strtod() doesn't handle inf and nan, so we have to
|
|
983
|
-
// handle it explicitly. Speed is not important here because this
|
|
984
|
-
// code is only called in unit tests.
|
|
985
|
-
bool pos = true;
|
|
986
|
-
const char* i = buf;
|
|
987
|
-
if ('-' == *i) {
|
|
988
|
-
pos = false;
|
|
989
|
-
++i;
|
|
990
|
-
} else if ('+' == *i) {
|
|
991
|
-
++i;
|
|
992
|
-
}
|
|
993
|
-
if (0 == _stricmp(i, "inf") || 0 == _stricmp(i, "infinity")) {
|
|
994
|
-
r = std::numeric_limits<double>::infinity();
|
|
995
|
-
if (!pos)
|
|
996
|
-
r = -r;
|
|
997
|
-
} else if (0 == _stricmp(i, "nan")) {
|
|
998
|
-
r = std::numeric_limits<double>::quiet_NaN();
|
|
999
|
-
} else {
|
|
1000
|
-
return false;
|
|
1001
|
-
}
|
|
1002
|
-
#else
|
|
1003
|
-
return false; // Leftover junk
|
|
1004
|
-
#endif
|
|
1005
|
-
}
|
|
981
|
+
if (end != buf + n) return false; // Leftover junk
|
|
1006
982
|
if (errno) return false;
|
|
1007
983
|
if (dest == NULL) return true;
|
|
1008
984
|
if (isfloat) {
|
package/vendor/util/test.cc
CHANGED
|
@@ -3,10 +3,13 @@
|
|
|
3
3
|
// license that can be found in the LICENSE file.
|
|
4
4
|
|
|
5
5
|
#include <stdio.h>
|
|
6
|
+
#include <string>
|
|
6
7
|
|
|
7
8
|
#include "util/test.h"
|
|
8
9
|
|
|
9
|
-
|
|
10
|
+
namespace testing {
|
|
11
|
+
std::string TempDir() { return "/tmp/"; }
|
|
12
|
+
} // namespace testing
|
|
10
13
|
|
|
11
14
|
struct Test {
|
|
12
15
|
void (*fn)(void);
|