diff options
author | Neil <nyamatongwe@gmail.com> | 2014-05-03 12:45:42 +1000 |
---|---|---|
committer | Neil <nyamatongwe@gmail.com> | 2014-05-03 12:45:42 +1000 |
commit | a1b2702f9718b1658167976d3740931a7d3433d0 (patch) | |
tree | 863f46f61a09fd6ecc4e02276213b2b009978634 /src/PositionCache.cxx | |
parent | c883320da5c7b1a4eca28e936b48e37f3afa9d74 (diff) | |
download | scintilla-mirror-a1b2702f9718b1658167976d3740931a7d3433d0.tar.gz |
Using unsigned int for cache index to avoid casts and potential for failure.
Diffstat (limited to 'src/PositionCache.cxx')
-rw-r--r-- | src/PositionCache.cxx | 9 |
1 files changed, 5 insertions, 4 deletions
diff --git a/src/PositionCache.cxx b/src/PositionCache.cxx index 820fd4895..5f3fd03de 100644 --- a/src/PositionCache.cxx +++ b/src/PositionCache.cxx @@ -646,18 +646,18 @@ void PositionCache::MeasureWidths(Surface *surface, ViewStyle &vstyle, unsigned const char *s, unsigned int len, XYPOSITION *positions, Document *pdoc) { allClear = false; - int probe = -1; + unsigned int probe = pces.size(); // Out of bounds if ((!pces.empty()) && (len < 30)) { // Only store short strings in the cache so it doesn't churn with // long comments with only a single comment. // Two way associative: try two probe positions. unsigned int hashValue = PositionCacheEntry::Hash(styleNumber, s, len); - probe = static_cast<int>(hashValue % pces.size()); + probe = hashValue % pces.size(); if (pces[probe].Retrieve(styleNumber, s, len, positions)) { return; } - int probe2 = static_cast<int>((hashValue * 37) % pces.size()); + unsigned int probe2 = (hashValue * 37) % pces.size(); if (pces[probe2].Retrieve(styleNumber, s, len, positions)) { return; } @@ -682,7 +682,8 @@ void PositionCache::MeasureWidths(Surface *surface, ViewStyle &vstyle, unsigned } else { surface->MeasureWidths(vstyle.styles[styleNumber].font, s, len, positions); } - if (probe >= 0) { + if (probe < pces.size()) { + // Store into cache clock++; if (clock > 60000) { // Since there are only 16 bits for the clock, wrap it round and |