diff options
author | dgp <dgp@users.sourceforge.net> | 2017-08-10 17:03:53 (GMT) |
---|---|---|
committer | dgp <dgp@users.sourceforge.net> | 2017-08-10 17:03:53 (GMT) |
commit | 8ccd8d10efecf3891466ee0df15700557ee170aa (patch) | |
tree | 84d168be09660df884bd93b669ec1c23a7b3836c /generic/tclRegexp.c | |
parent | c2982f8f62f8b7e7faf9e500f53dca8941299548 (diff) | |
download | tcl-8ccd8d10efecf3891466ee0df15700557ee170aa.zip tcl-8ccd8d10efecf3891466ee0df15700557ee170aa.tar.gz tcl-8ccd8d10efecf3891466ee0df15700557ee170aa.tar.bz2 |
Backport [array names -regexp] should support backrefs
Diffstat (limited to 'generic/tclRegexp.c')
-rw-r--r-- | generic/tclRegexp.c | 15 |
1 files changed, 11 insertions, 4 deletions
diff --git a/generic/tclRegexp.c b/generic/tclRegexp.c index ea25d4b..cfe6388 100644 --- a/generic/tclRegexp.c +++ b/generic/tclRegexp.c @@ -502,10 +502,17 @@ Tcl_RegExpMatchObj( { Tcl_RegExp re; - re = Tcl_GetRegExpFromObj(interp, patternObj, - TCL_REG_ADVANCED | TCL_REG_NOSUB); - if (re == NULL) { - return -1; + /* + * For performance reasons, first try compiling the RE without support for + * subexpressions. On failure, try again without TCL_REG_NOSUB in case the + * RE has backreferences in it. Closely related to [Bug 1366683]. If this + * still fails, an error message will be left in the interpreter. + */ + + if (!(re = Tcl_GetRegExpFromObj(interp, patternObj, + TCL_REG_ADVANCED | TCL_REG_NOSUB)) + && !(re = Tcl_GetRegExpFromObj(interp, patternObj, TCL_REG_ADVANCED))) { + return -1; } return Tcl_RegExpExecObj(interp, re, textObj, 0 /* offset */, 0 /* nmatches */, 0 /* flags */); |