re2 1.21.2 → 1.21.4
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/README.md +2 -0
- package/lib/addon.cc +26 -5
- package/lib/exec.cc +2 -1
- package/lib/match.cc +2 -1
- package/lib/replace.cc +2 -1
- package/lib/search.cc +2 -1
- package/lib/split.cc +2 -1
- package/lib/test.cc +2 -1
- package/lib/wrapped_re2.h +24 -0
- package/package.json +7 -7
package/README.md
CHANGED
|
@@ -353,6 +353,8 @@ console.log('re2_res : ' + re2_res); // prints: re2_res : abc,a,b,c
|
|
|
353
353
|
|
|
354
354
|
## Release history
|
|
355
355
|
|
|
356
|
+
- 1.21.4 *Fixed a regression reported by [caroline-matsec](https://github.com/caroline-matsec), thx! Added pre-compilation targets for Alpine Linux on ARM. Updated deps.*
|
|
357
|
+
- 1.21.3 *Fixed an empty string regression reported by [Rhys Arkins](https://github.com/rarkins), thx! Updated deps.*
|
|
356
358
|
- 1.21.2 *Fixed another memory regression reported by [matthewvalentine](https://github.com/matthewvalentine), thx! Updated deps. Added more tests and benchmarks.*
|
|
357
359
|
- 1.21.1 *Fixed a memory regression reported by [matthewvalentine](https://github.com/matthewvalentine), thx! Updated deps.*
|
|
358
360
|
- 1.21.0 *Fixed the performance problem reported by [matthewvalentine](https://github.com/matthewvalentine) (thx!). The change improves performance for multiple use cases.*
|
package/lib/addon.cc
CHANGED
|
@@ -112,10 +112,19 @@ void WrappedRE2::dropCache()
|
|
|
112
112
|
lastStringValue.clear();
|
|
113
113
|
}
|
|
114
114
|
|
|
115
|
-
const StrVal&
|
|
115
|
+
const StrVal &WrappedRE2::prepareArgument(const v8::Local<v8::Value> &arg, bool ignoreLastIndex)
|
|
116
116
|
{
|
|
117
117
|
size_t startFrom = ignoreLastIndex ? 0 : lastIndex;
|
|
118
118
|
|
|
119
|
+
if (!lastString.IsEmpty())
|
|
120
|
+
{
|
|
121
|
+
lastString.ClearWeak();
|
|
122
|
+
}
|
|
123
|
+
if (!lastCache.IsEmpty())
|
|
124
|
+
{
|
|
125
|
+
lastCache.ClearWeak();
|
|
126
|
+
}
|
|
127
|
+
|
|
119
128
|
if (lastString == arg && !node::Buffer::HasInstance(arg) && !lastCache.IsEmpty())
|
|
120
129
|
{
|
|
121
130
|
// we have a properly cached string
|
|
@@ -130,7 +139,6 @@ const StrVal& WrappedRE2::prepareArgument(const v8::Local<v8::Value> &arg, bool
|
|
|
130
139
|
// no need to cache buffers
|
|
131
140
|
|
|
132
141
|
lastString.Reset(arg);
|
|
133
|
-
static_cast<v8::PersistentBase<v8::Value> &>(lastString).SetWeak();
|
|
134
142
|
|
|
135
143
|
auto argSize = node::Buffer::Length(arg);
|
|
136
144
|
lastStringValue.reset(arg, argSize, argSize, startFrom, true);
|
|
@@ -149,14 +157,12 @@ const StrVal& WrappedRE2::prepareArgument(const v8::Local<v8::Value> &arg, bool
|
|
|
149
157
|
}
|
|
150
158
|
|
|
151
159
|
lastString.Reset(arg);
|
|
152
|
-
static_cast<v8::PersistentBase<v8::Value> &>(lastString).SetWeak();
|
|
153
160
|
|
|
154
161
|
auto s = t.ToLocalChecked();
|
|
155
162
|
auto argLength = Nan::DecodeBytes(s);
|
|
156
163
|
|
|
157
164
|
auto buffer = node::Buffer::New(v8::Isolate::GetCurrent(), s).ToLocalChecked();
|
|
158
165
|
lastCache.Reset(buffer);
|
|
159
|
-
static_cast<v8::PersistentBase<v8::Object> &>(lastCache).SetWeak();
|
|
160
166
|
|
|
161
167
|
auto argSize = node::Buffer::Length(buffer);
|
|
162
168
|
lastStringValue.reset(buffer, argSize, argLength, startFrom);
|
|
@@ -164,6 +170,19 @@ const StrVal& WrappedRE2::prepareArgument(const v8::Local<v8::Value> &arg, bool
|
|
|
164
170
|
return lastStringValue;
|
|
165
171
|
};
|
|
166
172
|
|
|
173
|
+
void WrappedRE2::doneWithLastString()
|
|
174
|
+
{
|
|
175
|
+
if (!lastString.IsEmpty())
|
|
176
|
+
{
|
|
177
|
+
static_cast<v8::PersistentBase<v8::Value> &>(lastString).SetWeak();
|
|
178
|
+
}
|
|
179
|
+
|
|
180
|
+
if (!lastCache.IsEmpty())
|
|
181
|
+
{
|
|
182
|
+
static_cast<v8::PersistentBase<v8::Object> &>(lastCache).SetWeak();
|
|
183
|
+
}
|
|
184
|
+
}
|
|
185
|
+
|
|
167
186
|
// StrVal
|
|
168
187
|
|
|
169
188
|
void StrVal::setIndex(size_t newIndex)
|
|
@@ -204,12 +223,14 @@ void StrVal::setIndex(size_t newIndex)
|
|
|
204
223
|
index = newIndex;
|
|
205
224
|
}
|
|
206
225
|
|
|
226
|
+
static char null_buffer[] = {'\0'};
|
|
227
|
+
|
|
207
228
|
void StrVal::reset(const v8::Local<v8::Value> &arg, size_t argSize, size_t argLength, size_t newIndex, bool buffer)
|
|
208
229
|
{
|
|
209
230
|
clear();
|
|
210
231
|
isBuffer = buffer;
|
|
211
232
|
size = argSize;
|
|
212
233
|
length = argLength;
|
|
213
|
-
data = node::Buffer::Data(arg);
|
|
234
|
+
data = size ? node::Buffer::Data(arg) : null_buffer;
|
|
214
235
|
setIndex(newIndex);
|
|
215
236
|
}
|
package/lib/exec.cc
CHANGED
package/lib/match.cc
CHANGED
package/lib/replace.cc
CHANGED
|
@@ -497,7 +497,8 @@ NAN_METHOD(WrappedRE2::Replace)
|
|
|
497
497
|
return;
|
|
498
498
|
}
|
|
499
499
|
|
|
500
|
-
|
|
500
|
+
PrepareLastString prep(re2, info[0]);
|
|
501
|
+
StrVal& replacee = prep;
|
|
501
502
|
if (replacee.isBad) return; // throws an exception
|
|
502
503
|
|
|
503
504
|
if (!replacee.isValidIndex)
|
package/lib/search.cc
CHANGED
package/lib/split.cc
CHANGED
|
@@ -19,7 +19,8 @@ NAN_METHOD(WrappedRE2::Split)
|
|
|
19
19
|
return;
|
|
20
20
|
}
|
|
21
21
|
|
|
22
|
-
|
|
22
|
+
PrepareLastString prep(re2, info[0]);
|
|
23
|
+
StrVal& str = prep;
|
|
23
24
|
if (str.isBad) return; // throws an exception
|
|
24
25
|
|
|
25
26
|
size_t limit = std::numeric_limits<size_t>::max();
|
package/lib/test.cc
CHANGED
package/lib/wrapped_re2.h
CHANGED
|
@@ -119,6 +119,30 @@ private:
|
|
|
119
119
|
|
|
120
120
|
void dropCache();
|
|
121
121
|
const StrVal &prepareArgument(const v8::Local<v8::Value> &arg, bool ignoreLastIndex = false);
|
|
122
|
+
void doneWithLastString();
|
|
123
|
+
|
|
124
|
+
friend class PrepareLastString;
|
|
125
|
+
};
|
|
126
|
+
|
|
127
|
+
struct PrepareLastString
|
|
128
|
+
{
|
|
129
|
+
PrepareLastString(WrappedRE2 *re2, const v8::Local<v8::Value> &arg, bool ignoreLastIndex = false) : re2(re2) {
|
|
130
|
+
re2->prepareArgument(arg, ignoreLastIndex);
|
|
131
|
+
}
|
|
132
|
+
|
|
133
|
+
~PrepareLastString() {
|
|
134
|
+
re2->doneWithLastString();
|
|
135
|
+
}
|
|
136
|
+
|
|
137
|
+
operator const StrVal&() const {
|
|
138
|
+
return re2->lastStringValue;
|
|
139
|
+
}
|
|
140
|
+
|
|
141
|
+
operator StrVal&() {
|
|
142
|
+
return re2->lastStringValue;
|
|
143
|
+
}
|
|
144
|
+
|
|
145
|
+
WrappedRE2 *re2;
|
|
122
146
|
};
|
|
123
147
|
|
|
124
148
|
// utilities
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "re2",
|
|
3
|
-
"version": "1.21.
|
|
3
|
+
"version": "1.21.4",
|
|
4
4
|
"description": "Bindings for RE2: fast, safe alternative to backtracking regular expression engines.",
|
|
5
5
|
"homepage": "https://github.com/uhop/node-re2",
|
|
6
6
|
"bugs": "https://github.com/uhop/node-re2/issues",
|
|
@@ -16,13 +16,13 @@
|
|
|
16
16
|
],
|
|
17
17
|
"dependencies": {
|
|
18
18
|
"install-artifact-from-github": "^1.3.5",
|
|
19
|
-
"nan": "^2.
|
|
20
|
-
"node-gyp": "^10.
|
|
19
|
+
"nan": "^2.20.0",
|
|
20
|
+
"node-gyp": "^10.2.0"
|
|
21
21
|
},
|
|
22
22
|
"devDependencies": {
|
|
23
|
-
"@types/node": "^
|
|
23
|
+
"@types/node": "^22.5.0",
|
|
24
24
|
"heya-unit": "^0.3.0",
|
|
25
|
-
"typescript": "^5.4
|
|
25
|
+
"typescript": "^5.5.4"
|
|
26
26
|
},
|
|
27
27
|
"scripts": {
|
|
28
28
|
"test": "node tests/tests.js",
|
|
@@ -34,8 +34,8 @@
|
|
|
34
34
|
"build": "node-gyp -j max build",
|
|
35
35
|
"rebuild:dev": "node-gyp -j max rebuild --debug",
|
|
36
36
|
"rebuild": "node-gyp -j max rebuild",
|
|
37
|
-
"clean": "node-gyp clean",
|
|
38
|
-
"
|
|
37
|
+
"clean": "node-gyp clean && node-gyp configure",
|
|
38
|
+
"clean-build": "node-gyp clean"
|
|
39
39
|
},
|
|
40
40
|
"github": "https://github.com/uhop/node-re2",
|
|
41
41
|
"repository": {
|