aboutsummaryrefslogtreecommitdiffhomepage
diff options
context:
space:
mode:
authornyamatongwe <devnull@localhost>2012-05-26 13:12:22 +1000
committernyamatongwe <devnull@localhost>2012-05-26 13:12:22 +1000
commit44241ccc28b561efcdbda77350bb5435b11b3d47 (patch)
treed5487a8cb36992e36f557e79c9e55270a695218e
parent032a0017a6e992fc40790214c738dbc59c084dea (diff)
downloadscintilla-mirror-44241ccc28b561efcdbda77350bb5435b11b3d47.tar.gz
Optimize case-sensitive searching by hoisting the first character of search
string into a separate variable.
-rw-r--r--src/Document.cxx15
1 files changed, 9 insertions, 6 deletions
diff --git a/src/Document.cxx b/src/Document.cxx
index d427d636d..dca0ccc51 100644
--- a/src/Document.cxx
+++ b/src/Document.cxx
@@ -1461,13 +1461,16 @@ long Document::FindText(int minPos, int maxPos, const char *search,
}
if (caseSensitive) {
const int endSearch = (startPos <= endPos) ? endPos - lengthFind + 1 : endPos;
+ const char charStartSearch = search[0];
while (forward ? (pos < endSearch) : (pos >= endSearch)) {
- bool found = (pos + lengthFind) <= limitPos;
- for (int indexSearch = 0; (indexSearch < lengthFind) && found; indexSearch++) {
- found = CharAt(pos + indexSearch) == search[indexSearch];
- }
- if (found && MatchesWordOptions(word, wordStart, pos, lengthFind)) {
- return pos;
+ if (CharAt(pos) == charStartSearch) {
+ bool found = (pos + lengthFind) <= limitPos;
+ for (int indexSearch = 1; (indexSearch < lengthFind) && found; indexSearch++) {
+ found = CharAt(pos + indexSearch) == search[indexSearch];
+ }
+ if (found && MatchesWordOptions(word, wordStart, pos, lengthFind)) {
+ return pos;
+ }
}
if (!NextCharacter(pos, increment))
break;