diff options
author | Neil <nyamatongwe@gmail.com> | 2021-05-07 22:46:43 +1000 |
---|---|---|
committer | Neil <nyamatongwe@gmail.com> | 2021-05-07 22:46:43 +1000 |
commit | 7d47304ca36474000293f267dda39483113c86e3 (patch) | |
tree | a8d4360cff501c9f9e10147e6bab73fa996fedb4 /src/PositionCache.cxx | |
parent | cdf89374e4bbf0d4a02100968b38b263dee239e1 (diff) | |
download | scintilla-mirror-7d47304ca36474000293f267dda39483113c86e3.tar.gz |
Overallocate line layout cache so that don't reallocate too often.
Diffstat (limited to 'src/PositionCache.cxx')
-rw-r--r-- | src/PositionCache.cxx | 15 |
1 files changed, 13 insertions, 2 deletions
diff --git a/src/PositionCache.cxx b/src/PositionCache.cxx index 18971dc99..9ca6db7a3 100644 --- a/src/PositionCache.cxx +++ b/src/PositionCache.cxx @@ -368,6 +368,17 @@ LineLayoutCache::LineLayoutCache() : LineLayoutCache::~LineLayoutCache() = default; +namespace { + +constexpr size_t AlignUp(size_t value, size_t alignment) noexcept { + return ((value - 1) / alignment + 1) * alignment; +} + +constexpr size_t alignmentLLC = 20; + +} + + size_t LineLayoutCache::EntryForLine(Sci::Line line) const noexcept { switch (level) { case Cache::none: @@ -388,9 +399,9 @@ void LineLayoutCache::AllocateForLevel(Sci::Line linesOnScreen, Sci::Line linesI if (level == Cache::caret) { lengthForLevel = 1; } else if (level == Cache::page) { - lengthForLevel = linesOnScreen + 1; + lengthForLevel = AlignUp(linesOnScreen + 1, alignmentLLC); } else if (level == Cache::document) { - lengthForLevel = linesInDoc; + lengthForLevel = AlignUp(linesInDoc, alignmentLLC); } if (lengthForLevel != cache.size()) { |