mirror of
https://github.com/mozilla/gecko-dev.git
synced 2025-01-12 06:52:25 +00:00
Bug 1628835: Change parenCount to pairCount r=tcampbell
A regexp with N sets of capturing parens will have N+1 capture groups, with the extra capture containing the entire matching string. Our old implementation stored `parenCount` in the RegExpShared and then added 1 to it whenever it was used. A much simpler answer is to just add 1 when initializing the regexp. Differential Revision: https://phabricator.services.mozilla.com/D70693 --HG-- extra : moz-landing-system : lando
This commit is contained in:
parent
1736e700e0
commit
54ca602cfd
@ -2114,12 +2114,11 @@ static bool PrepareAndExecuteRegExp(JSContext* cx, MacroAssembler& masm,
|
||||
}
|
||||
|
||||
// Don't handle RegExps with excessive parens.
|
||||
masm.load32(Address(temp1, RegExpShared::offsetOfParenCount()), temp2);
|
||||
masm.branch32(Assembler::AboveOrEqual, temp2,
|
||||
masm.load32(Address(temp1, RegExpShared::offsetOfPairCount()), temp2);
|
||||
masm.branch32(Assembler::Above, temp2,
|
||||
Imm32(RegExpObject::MaxPairCount), failure);
|
||||
|
||||
// Fill in the paren count in the MatchPairs on the stack.
|
||||
masm.add32(Imm32(1), temp2);
|
||||
masm.store32(temp2, pairCountAddress);
|
||||
|
||||
// Load the code pointer for the type of input string we have, and compute
|
||||
|
@ -946,7 +946,7 @@ bool js::StringHasRegExpMetaChars(JSLinearString* str) {
|
||||
/* RegExpShared */
|
||||
|
||||
RegExpShared::RegExpShared(JSAtom* source, RegExpFlags flags)
|
||||
: headerAndSource(source), parenCount(0), flags(flags) {}
|
||||
: headerAndSource(source), pairCount_(0), flags(flags) {}
|
||||
|
||||
void RegExpShared::traceChildren(JSTracer* trc) {
|
||||
// Discard code to avoid holding onto ExecutablePools.
|
||||
@ -1057,7 +1057,7 @@ void RegExpShared::useAtomMatch(HandleAtom pattern) {
|
||||
MOZ_ASSERT(kind() == RegExpShared::Kind::Unparsed);
|
||||
kind_ = RegExpShared::Kind::Atom;
|
||||
patternAtom_ = pattern;
|
||||
parenCount = 0;
|
||||
pairCount_ = 1;
|
||||
}
|
||||
|
||||
#else // !ENABLE_NEW_REGEXP
|
||||
@ -1082,7 +1082,8 @@ bool RegExpShared::compile(JSContext* cx, MutableHandleRegExpShared re,
|
||||
return false;
|
||||
}
|
||||
|
||||
re->parenCount = data.capture_count;
|
||||
// Add one to account for the whole-match capture.
|
||||
re->pairCount_ = data.capture_count + 1;
|
||||
|
||||
JitCodeTables tables;
|
||||
irregexp::RegExpCode code = irregexp::CompilePattern(
|
||||
|
@ -102,7 +102,7 @@ class RegExpShared : public gc::TenuredCell {
|
||||
|
||||
RegExpCompilation compilationArray[2];
|
||||
|
||||
uint32_t parenCount;
|
||||
uint32_t pairCount_;
|
||||
JS::RegExpFlags flags;
|
||||
|
||||
#ifdef ENABLE_NEW_REGEXP
|
||||
@ -156,13 +156,13 @@ class RegExpShared : public gc::TenuredCell {
|
||||
|
||||
/* Accessors */
|
||||
|
||||
size_t getParenCount() const {
|
||||
size_t pairCount() const {
|
||||
#ifdef ENABLE_NEW_REGEXP
|
||||
MOZ_ASSERT(kind() != Kind::Unparsed);
|
||||
#else
|
||||
MOZ_ASSERT(isCompiled());
|
||||
#endif
|
||||
return parenCount;
|
||||
return pairCount_;
|
||||
}
|
||||
|
||||
#ifdef ENABLE_NEW_REGEXP
|
||||
@ -172,8 +172,6 @@ class RegExpShared : public gc::TenuredCell {
|
||||
void useAtomMatch(HandleAtom pattern);
|
||||
#endif
|
||||
|
||||
/* Accounts for the "0" (whole match) pair. */
|
||||
size_t pairCount() const { return getParenCount() + 1; }
|
||||
|
||||
JSAtom* getSource() const { return headerAndSource.ptr(); }
|
||||
|
||||
@ -209,8 +207,8 @@ class RegExpShared : public gc::TenuredCell {
|
||||
|
||||
static size_t offsetOfFlags() { return offsetof(RegExpShared, flags); }
|
||||
|
||||
static size_t offsetOfParenCount() {
|
||||
return offsetof(RegExpShared, parenCount);
|
||||
static size_t offsetOfPairCount() {
|
||||
return offsetof(RegExpShared, pairCount_);
|
||||
}
|
||||
|
||||
static size_t offsetOfJitCode(bool latin1) {
|
||||
|
Loading…
x
Reference in New Issue
Block a user