Skip to content

Commit 1c5b90f

Browse files
authored
Merge pull request Tencent#1414 from ylavic/regex_allocator
Use passed in allocator for internal regex parser.
2 parents a632160 + b0c96f9 commit 1c5b90f

File tree

1 file changed

+11
-6
lines changed

1 file changed

+11
-6
lines changed

include/rapidjson/internal/regex.h

Lines changed: 11 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -118,15 +118,19 @@ class GenericRegex {
118118
template <typename, typename> friend class GenericRegexSearch;
119119

120120
GenericRegex(const Ch* source, Allocator* allocator = 0) :
121-
states_(allocator, 256), ranges_(allocator, 256), root_(kRegexInvalidState), stateCount_(), rangeCount_(),
121+
ownAllocator_(allocator ? 0 : RAPIDJSON_NEW(Allocator)()), allocator_(allocator ? allocator : ownAllocator_),
122+
states_(allocator_, 256), ranges_(allocator_, 256), root_(kRegexInvalidState), stateCount_(), rangeCount_(),
122123
anchorBegin_(), anchorEnd_()
123124
{
124125
GenericStringStream<Encoding> ss(source);
125126
DecodedStream<GenericStringStream<Encoding>, Encoding> ds(ss);
126127
Parse(ds);
127128
}
128129

129-
~GenericRegex() {}
130+
~GenericRegex()
131+
{
132+
RAPIDJSON_DELETE(ownAllocator_);
133+
}
130134

131135
bool IsValid() const {
132136
return root_ != kRegexInvalidState;
@@ -188,10 +192,9 @@ class GenericRegex {
188192

189193
template <typename InputStream>
190194
void Parse(DecodedStream<InputStream, Encoding>& ds) {
191-
Allocator allocator;
192-
Stack<Allocator> operandStack(&allocator, 256); // Frag
193-
Stack<Allocator> operatorStack(&allocator, 256); // Operator
194-
Stack<Allocator> atomCountStack(&allocator, 256); // unsigned (Atom per parenthesis)
195+
Stack<Allocator> operandStack(allocator_, 256); // Frag
196+
Stack<Allocator> operatorStack(allocator_, 256); // Operator
197+
Stack<Allocator> atomCountStack(allocator_, 256); // unsigned (Atom per parenthesis)
195198

196199
*atomCountStack.template Push<unsigned>() = 0;
197200

@@ -582,6 +585,8 @@ class GenericRegex {
582585
}
583586
}
584587

588+
Allocator* ownAllocator_;
589+
Allocator* allocator_;
585590
Stack<Allocator> states_;
586591
Stack<Allocator> ranges_;
587592
SizeType root_;

0 commit comments

Comments
 (0)