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 | ed3d8a5c300d7029bc85bc0c012386ae933e230f (patch) | |
tree | 84d168be09660df884bd93b669ec1c23a7b3836c /generic | |
parent | d6e5a5012c055c7737f8f12ba124248812b4422a (diff) | |
download | tcl-ed3d8a5c300d7029bc85bc0c012386ae933e230f.zip tcl-ed3d8a5c300d7029bc85bc0c012386ae933e230f.tar.gz tcl-ed3d8a5c300d7029bc85bc0c012386ae933e230f.tar.bz2 |
Backport [array names -regexp] should support backrefs
Diffstat (limited to 'generic')
-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 */); |