diff options
author | sebres <sebres@users.sourceforge.net> | 2024-05-07 20:09:14 (GMT) |
---|---|---|
committer | sebres <sebres@users.sourceforge.net> | 2024-05-07 20:09:14 (GMT) |
commit | cdbaf8e74d60061a08cc3aef5953ac83c0b977c3 (patch) | |
tree | 218dd6cfa4532714d5683b0e76e402353a9c5b28 | |
parent | 08964b5dd95a0738137112d24780d2fad6126793 (diff) | |
download | tcl-cdbaf8e74d60061a08cc3aef5953ac83c0b977c3.zip tcl-cdbaf8e74d60061a08cc3aef5953ac83c0b977c3.tar.gz tcl-cdbaf8e74d60061a08cc3aef5953ac83c0b977c3.tar.bz2 |
code review (optimization by parse of word tokens in clock format)
-rw-r--r-- | generic/tclClockFmt.c | 67 |
1 files changed, 36 insertions, 31 deletions
diff --git a/generic/tclClockFmt.c b/generic/tclClockFmt.c index fdac4fb..b08dc72 100644 --- a/generic/tclClockFmt.c +++ b/generic/tclClockFmt.c @@ -2139,16 +2139,13 @@ EstimateTokenCount( return ++tokcnt; } -#define AllocTokenInChain(tok, chain, tokCnt, type) \ - if (++(tok) >= (chain) + (tokCnt)) { \ - chain = (type)attemptckrealloc((char *)(chain), \ +#define AllocTokenInChain(tok, chain, tokCnt, type) \ + if (++(tok) >= (chain) + (tokCnt)) { \ + chain = (type)ckrealloc((char *)(chain), \ (tokCnt + CLOCK_MIN_TOK_CHAIN_BLOCK_SIZE) * sizeof(*(tok))); \ - if ((chain) == NULL) { \ - goto done; \ - } \ - (tok) = (chain) + (tokCnt); \ - (tokCnt) += CLOCK_MIN_TOK_CHAIN_BLOCK_SIZE; \ - } \ + (tok) = (chain) + (tokCnt); \ + (tokCnt) += CLOCK_MIN_TOK_CHAIN_BLOCK_SIZE; \ + } \ memset(tok, 0, sizeof(*(tok))); /* @@ -2281,7 +2278,7 @@ ClockGetOrParseScanFormat( continue; } default: - if (*p == ' ' || isspace(UCHAR(*p))) { + if (isspace(UCHAR(*p))) { tok->map = &ScnSpaceTokenMap; tok->tokWord.start = p++; while (p < e && isspace(UCHAR(*p))) { @@ -2295,29 +2292,34 @@ ClockGetOrParseScanFormat( tokCnt++; continue; } - word_tok: - { + word_tok: + { ClockScanToken *wordTok = tok; if (tok > scnTok && (tok - 1)->map == &ScnWordTokenMap) { + /* further with previous word token */ wordTok = tok - 1; - } - /* new word token */ - if (wordTok == tok) { + } else { + /* new word token */ wordTok->tokWord.start = p; wordTok->map = &ScnWordTokenMap; + } + + do { + if (isspace(UCHAR(*p))) { + fss->scnSpaceCount++; + } + p = Tcl_UtfNext(p); + } while (p < e && *p != '%'); + wordTok->tokWord.end = p; + + if (wordTok == tok) { AllocTokenInChain(tok, scnTok, fss->scnTokC, ClockScanToken *); - wordTok = tok - 1; tokCnt++; } - if (isspace(UCHAR(*p))) { - fss->scnSpaceCount++; } - p = Tcl_UtfNext(p); - wordTok->tokWord.end = p; break; } - } } /* calculate end distance value for each tokens */ @@ -2349,9 +2351,8 @@ ClockGetOrParseScanFormat( fss->scnTok = scnTok; fss->scnTokC = tokCnt; } - done: - Tcl_MutexUnlock(&ClockFmtMutex); + Tcl_MutexUnlock(&ClockFmtMutex); return fss; } @@ -3335,24 +3336,28 @@ ClockGetOrParseFmtFormat( continue; } default: - word_tok: { + word_tok: + { ClockFormatToken *wordTok = tok; if (tok > fmtTok && (tok - 1)->map == &FmtWordTokenMap) { wordTok = tok - 1; - } - if (wordTok == tok) { + } else { wordTok->tokWord.start = p; wordTok->map = &FmtWordTokenMap; + } + do { + p = Tcl_UtfNext(p); + } while (p < e && *p != '%'); + wordTok->tokWord.end = p; + + if (wordTok == tok) { AllocTokenInChain(tok, fmtTok, fss->fmtTokC, ClockFormatToken *); - wordTok = tok - 1; tokCnt++; } - p = Tcl_UtfNext(p); - wordTok->tokWord.end = p; + } break; } - } } /* correct count of real used tokens and free mem if desired @@ -3368,7 +3373,7 @@ ClockGetOrParseFmtFormat( fss->fmtTok = fmtTok; fss->fmtTokC = tokCnt; } - done: + Tcl_MutexUnlock(&ClockFmtMutex); return fss; } |