MCPcopy Create free account
hub / github.com/FirebirdSQL/firebird / PostVisit

Method PostVisit

extern/re2/re2/simplify.cc:230–303  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

228}
229
230Regexp* CoalesceWalker::PostVisit(Regexp* re,
231 Regexp* parent_arg,
232 Regexp* pre_arg,
233 Regexp** child_args,
234 int nchild_args) {
235 if (re->nsub() == 0)
236 return re->Incref();
237
238 if (re->op() != kRegexpConcat) {
239 if (!ChildArgsChanged(re, child_args))
240 return re->Incref();
241
242 // Something changed. Build a new op.
243 Regexp* nre = new Regexp(re->op(), re->parse_flags());
244 nre->AllocSub(re->nsub());
245 Regexp** nre_subs = nre->sub();
246 for (int i = 0; i < re->nsub(); i++)
247 nre_subs[i] = child_args[i];
248 // Repeats and Captures have additional data that must be copied.
249 if (re->op() == kRegexpRepeat) {
250 nre->min_ = re->min();
251 nre->max_ = re->max();
252 } else if (re->op() == kRegexpCapture) {
253 nre->cap_ = re->cap();
254 }
255 return nre;
256 }
257
258 bool can_coalesce = false;
259 for (int i = 0; i < re->nsub(); i++) {
260 if (i+1 < re->nsub() &&
261 CanCoalesce(child_args[i], child_args[i+1])) {
262 can_coalesce = true;
263 break;
264 }
265 }
266 if (!can_coalesce) {
267 if (!ChildArgsChanged(re, child_args))
268 return re->Incref();
269
270 // Something changed. Build a new op.
271 Regexp* nre = new Regexp(re->op(), re->parse_flags());
272 nre->AllocSub(re->nsub());
273 Regexp** nre_subs = nre->sub();
274 for (int i = 0; i < re->nsub(); i++)
275 nre_subs[i] = child_args[i];
276 return nre;
277 }
278
279 for (int i = 0; i < re->nsub(); i++) {
280 if (i+1 < re->nsub() &&
281 CanCoalesce(child_args[i], child_args[i+1]))
282 DoCoalesce(&child_args[i], &child_args[i+1]);
283 }
284 // Determine how many empty matches were left by DoCoalesce.
285 int n = 0;
286 for (int i = n; i < re->nsub(); i++) {
287 if (child_args[i]->op() == kRegexpEmptyMatch)

Callers

nothing calls this directly

Calls 11

ChildArgsChangedFunction · 0.85
nsubMethod · 0.80
parse_flagsMethod · 0.80
AllocSubMethod · 0.80
minMethod · 0.80
maxMethod · 0.80
IncrefMethod · 0.45
opMethod · 0.45
subMethod · 0.45
capMethod · 0.45
DecrefMethod · 0.45

Tested by

no test coverage detected