diff options
author | sebres <sebres@users.sourceforge.net> | 2017-05-16 09:16:43 (GMT) |
---|---|---|
committer | sebres <sebres@users.sourceforge.net> | 2017-05-16 09:16:43 (GMT) |
commit | 3880f148a1f58dbcc23a04aa669f2e02426db96d (patch) | |
tree | 641a7b94b4e5029ab24cfe6515616c9e6fb935da /generic | |
parent | 6c6c26cc2c64879e95a6909e50120af806292a81 (diff) | |
download | tcl-3880f148a1f58dbcc23a04aa669f2e02426db96d.zip tcl-3880f148a1f58dbcc23a04aa669f2e02426db96d.tar.gz tcl-3880f148a1f58dbcc23a04aa669f2e02426db96d.tar.bz2 |
optimized special case "-now" of base (by scan or add) or clock value (by format): bypass integer recognition if it looks like option "-now"
Diffstat (limited to 'generic')
-rw-r--r-- | generic/tclClock.c | 13 |
1 files changed, 9 insertions, 4 deletions
diff --git a/generic/tclClock.c b/generic/tclClock.c index 17c19c3..80740c8 100644 --- a/generic/tclClock.c +++ b/generic/tclClock.c @@ -3110,14 +3110,19 @@ ClockParseFmtScnArgs( /* Base (by scan or add) or clock value (by format) */ if (opts->baseObj != NULL) { - if (TclGetWideIntFromObj(NULL, opts->baseObj, &baseVal) != TCL_OK) { + register Tcl_Obj *baseObj = opts->baseObj; + /* bypass integer recognition if looks like option "-now" */ + if ( + (baseObj->length == 4 && baseObj->bytes && *(baseObj->bytes+1) == 'n') || + TclGetWideIntFromObj(NULL, baseObj, &baseVal) != TCL_OK + ) { /* we accept "-now" as current date-time */ const char *const nowOpts[] = { "-now", NULL }; int idx; - if (Tcl_GetIndexFromObj(NULL, opts->baseObj, nowOpts, "seconds or -now", + if (Tcl_GetIndexFromObj(NULL, baseObj, nowOpts, "seconds or -now", TCL_EXACT, &idx) == TCL_OK ) { goto baseNow; @@ -3125,7 +3130,7 @@ ClockParseFmtScnArgs( Tcl_SetObjResult(interp, Tcl_ObjPrintf( "expected integer but got \"%s\"", - Tcl_GetString(opts->baseObj))); + Tcl_GetString(baseObj))); Tcl_SetErrorCode(interp, "TCL", "VALUE", "INTEGER", NULL); i = 1; goto badOption; @@ -3135,7 +3140,7 @@ ClockParseFmtScnArgs( * that it isn't. */ - if (opts->baseObj->typePtr == &tclBignumType) { + if (baseObj->typePtr == &tclBignumType) { Tcl_SetObjResult(interp, dataPtr->literals[LIT_INTEGER_VALUE_TOO_LARGE]); return TCL_ERROR; } |