diff options
author | nyamatongwe <unknown> | 2002-08-06 13:01:36 +0000 |
---|---|---|
committer | nyamatongwe <unknown> | 2002-08-06 13:01:36 +0000 |
commit | f0cd18b40a558de587a485f8b166b70f6e517b60 (patch) | |
tree | 0b56271ed9b793314949540de9705ab45bdfd246 | |
parent | 8d5165fcb061fb2d443ba301c459635c2ecde3bb (diff) | |
download | scintilla-mirror-f0cd18b40a558de587a485f8b166b70f6e517b60.tar.gz |
Speed up to creating WordList through using a lookup table for separators.
-rw-r--r-- | src/PropSet.cxx | 31 |
1 files changed, 18 insertions, 13 deletions
diff --git a/src/PropSet.cxx b/src/PropSet.cxx index 296799691..b527c385c 100644 --- a/src/PropSet.cxx +++ b/src/PropSet.cxx @@ -411,33 +411,38 @@ bool PropSet::GetNext(char ** key, char ** val) { return false; } -static bool iswordsep(char ch, bool onlyLineEnds) { - if (!isspace(ch)) - return false; - if (!onlyLineEnds) - return true; - return ch == '\r' || ch == '\n'; -} - /** * Creates an array that points into each word in the string and puts \0 terminators * after each word. */ static char **ArrayFromWordList(char *wordlist, int *len, bool onlyLineEnds = false) { - char prev = '\n'; + int prev = '\n'; int words = 0; + // For rapid determination of whether a character is a separator, build + // a look up table. + bool wordSeparator[256]; + for (int i=0;i<256; i++) { + wordSeparator[i] = false; + } + wordSeparator['\r'] = true; + wordSeparator['\n'] = true; + if (!onlyLineEnds) { + wordSeparator[' '] = true; + wordSeparator['\t'] = true; + } for (int j = 0; wordlist[j]; j++) { - if (!iswordsep(wordlist[j], onlyLineEnds) && iswordsep(prev, onlyLineEnds)) + int curr = static_cast<unsigned char>(wordlist[j]); + if (!wordSeparator[curr] && wordSeparator[prev]) words++; - prev = wordlist[j]; + prev = curr; } - char **keywords = new char * [words + 1]; + char **keywords = new char *[words + 1]; if (keywords) { words = 0; prev = '\0'; size_t slen = strlen(wordlist); for (size_t k = 0; k < slen; k++) { - if (!iswordsep(wordlist[k], onlyLineEnds)) { + if (!wordSeparator[static_cast<unsigned char>(wordlist[k])]) { if (!prev) { keywords[words] = &wordlist[k]; words++; |