From 7d47304ca36474000293f267dda39483113c86e3 Mon Sep 17 00:00:00 2001 From: Neil Date: Fri, 7 May 2021 22:46:43 +1000 Subject: Overallocate line layout cache so that don't reallocate too often. --- src/PositionCache.cxx | 15 +++++++++++++-- 1 file changed, 13 insertions(+), 2 deletions(-) (limited to 'src') 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()) { -- cgit v1.2.3