diff options
author | nyamatongwe <unknown> | 2005-11-24 06:50:01 +0000 |
---|---|---|
committer | nyamatongwe <unknown> | 2005-11-24 06:50:01 +0000 |
commit | 70b447768bdfb629a38431adbb40e9544102e0b3 (patch) | |
tree | ac36f936c8087afe00454e291186a7b2ca770051 /src | |
parent | fd9891e3e2bb9f782c85fc8ab8b3e356ada0be56 (diff) | |
download | scintilla-mirror-70b447768bdfb629a38431adbb40e9544102e0b3.tar.gz |
Patch from John Ehresman that tracks the number of layouts
in use and adds assertions that this is always only 0 or 1.
It also sets the length of the cache array if the array shrinks
or grows without being reallocated.
Diffstat (limited to 'src')
-rw-r--r-- | src/Editor.cxx | 29 | ||||
-rw-r--r-- | src/Editor.h | 1 |
2 files changed, 21 insertions, 9 deletions
diff --git a/src/Editor.cxx b/src/Editor.cxx index 3bb3cab09..bb0f7ff53 100644 --- a/src/Editor.cxx +++ b/src/Editor.cxx @@ -188,7 +188,7 @@ void LineLayout::RestoreBracesHighlight(Range rangeLine, Position braces[]) { LineLayoutCache::LineLayoutCache() : level(0), length(0), size(0), cache(0), - allInvalidated(false), styleClock(-1) { + allInvalidated(false), styleClock(-1), useCount(0) { Allocate(0); } @@ -197,6 +197,7 @@ LineLayoutCache::~LineLayoutCache() { } void LineLayoutCache::Allocate(int length_) { + PLATFORM_ASSERT(cache == NULL); allInvalidated = false; length = length_; size = length; @@ -211,6 +212,7 @@ void LineLayoutCache::Allocate(int length_) { } void LineLayoutCache::AllocateForLevel(int linesOnScreen, int linesInDoc) { + PLATFORM_ASSERT(useCount == 0); int lengthForLevel = 0; if (level == llcCaret) { lengthForLevel = 1; @@ -221,23 +223,28 @@ void LineLayoutCache::AllocateForLevel(int linesOnScreen, int linesInDoc) { } if (lengthForLevel > size) { Deallocate(); - } else if (lengthForLevel < length) { - for (int i = lengthForLevel; i < length; i++) { - delete cache[i]; - cache[i] = 0; - } - } - if (!cache) { Allocate(lengthForLevel); + } else { + if (lengthForLevel < length) { + for (int i = lengthForLevel; i < length; i++) { + delete cache[i]; + cache[i] = 0; + } + } + length = lengthForLevel; } + PLATFORM_ASSERT(length == lengthForLevel); + PLATFORM_ASSERT(cache != NULL || length == 0); } void LineLayoutCache::Deallocate() { + PLATFORM_ASSERT(useCount == 0); for (int i = 0; i < length; i++) delete cache[i]; delete []cache; cache = 0; length = 0; + size = 0; } void LineLayoutCache::Invalidate(LineLayout::validLevel validity_) { @@ -283,6 +290,7 @@ LineLayout *LineLayoutCache::Retrieve(int lineNumber, int lineCaret, int maxChar pos = lineNumber; } if (pos >= 0) { + PLATFORM_ASSERT(useCount == 0); if (cache && (pos < length)) { if (cache[pos]) { if ((cache[pos]->lineNumber != lineNumber) || @@ -298,6 +306,7 @@ LineLayout *LineLayoutCache::Retrieve(int lineNumber, int lineCaret, int maxChar cache[pos]->lineNumber = lineNumber; cache[pos]->inCache = true; ret = cache[pos]; + useCount++; } } } @@ -315,7 +324,9 @@ void LineLayoutCache::Dispose(LineLayout *ll) { if (ll) { if (!ll->inCache) { delete ll; - } + } else { + useCount--; + } } } diff --git a/src/Editor.h b/src/Editor.h index 1207425dd..5370f5b2e 100644 --- a/src/Editor.h +++ b/src/Editor.h @@ -105,6 +105,7 @@ class LineLayoutCache { LineLayout **cache; bool allInvalidated; int styleClock; + int useCount; void Allocate(int length_); void AllocateForLevel(int linesOnScreen, int linesInDoc); public: |