summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorsebres <sebres@users.sourceforge.net>2017-01-10 22:30:49 (GMT)
committersebres <sebres@users.sourceforge.net>2017-01-10 22:30:49 (GMT)
commitf6b32c8442a436357885e7193724581862452a11 (patch)
tree083deb362907e5f1d2575f74f415e38580d2b177
parent40520b8606111adeab272cb9d2fa4c7acca3e406 (diff)
downloadtcl-f6b32c8442a436357885e7193724581862452a11.zip
tcl-f6b32c8442a436357885e7193724581862452a11.tar.gz
tcl-f6b32c8442a436357885e7193724581862452a11.tar.bz2
list index logic optimized regarding greedy search (don't stop by first found - try to find longest)
-rw-r--r--generic/tclClockFmt.c15
1 files changed, 13 insertions, 2 deletions
diff --git a/generic/tclClockFmt.c b/generic/tclClockFmt.c
index daedb26..09cbfa4 100644
--- a/generic/tclClockFmt.c
+++ b/generic/tclClockFmt.c
@@ -514,7 +514,7 @@ LocaleListSearch(ClockFmtScnCmdArgs *opts,
int minLen, int maxLen)
{
Tcl_Obj **lstv;
- int lstc, i, l;
+ int lstc, i, l, lf = -1;
const char *s;
Tcl_Obj *valObj;
@@ -536,16 +536,27 @@ LocaleListSearch(ClockFmtScnCmdArgs *opts,
if ( l >= minLen && l <= maxLen
&& strncasecmp(yyInput, s, l) == 0
) {
+ /* found, try to find longest value (greedy search) */
+ if (l < maxLen && minLen != maxLen) {
+ lf = i;
+ minLen = l + 1;
+ continue;
+ }
*val = i;
yyInput += l;
break;
}
}
- /* if not found */
+ /* if found */
if (i < lstc) {
return TCL_OK;
}
+ if (lf >= 0) {
+ *val = lf;
+ yyInput += minLen - 1;
+ return TCL_OK;
+ }
return TCL_RETURN;
}