diff options
-rw-r--r-- | src/EditView.cxx | 11 | ||||
-rw-r--r-- | src/EditView.h | 2 | ||||
-rw-r--r-- | src/Editor.cxx | 6 | ||||
-rw-r--r-- | src/PositionCache.cxx | 46 | ||||
-rw-r--r-- | src/PositionCache.h | 41 |
5 files changed, 65 insertions, 41 deletions
diff --git a/src/EditView.cxx b/src/EditView.cxx index 444fb3283..527b829bf 100644 --- a/src/EditView.cxx +++ b/src/EditView.cxx @@ -191,7 +191,8 @@ EditView::EditView() { additionalCaretsVisible = true; imeCaretBlockOverride = false; llc.SetLevel(LineCache::Caret); - posCache.SetSize(0x400); + posCache = CreatePositionCache(); + posCache->SetSize(0x400); tabArrowHeight = 4; customDrawTabArrow = nullptr; customDrawWrapMarker = nullptr; @@ -484,7 +485,7 @@ void EditView::LayoutLine(const EditModel &model, Surface *surface, const ViewSt // ts.representation->stringRep is UTF-8 which only matches cache if document is UTF-8 // or it only contains ASCII which is a subset of all currently supported encodings. if ((CpUtf8 == model.pdoc->dbcsCodePage) || ViewIsASCII(ts.representation->stringRep)) { - posCache.MeasureWidths(surface, vstyle, StyleControlChar, ts.representation->stringRep, + posCache->MeasureWidths(surface, vstyle, StyleControlChar, ts.representation->stringRep, positionsRepr); } else { surface->MeasureWidthsUTF8(vstyle.styles[StyleControlChar].font.get(), ts.representation->stringRep, positionsRepr); @@ -502,7 +503,7 @@ void EditView::LayoutLine(const EditModel &model, Surface *surface, const ViewSt // Over half the segments are single characters and of these about half are space characters. ll->positions[ts.start + 1] = vstyle.styles[ll->styles[ts.start]].spaceWidth; } else { - posCache.MeasureWidths(surface, vstyle, ll->styles[ts.start], + posCache->MeasureWidths(surface, vstyle, ll->styles[ts.start], std::string_view(&ll->chars[ts.start], ts.length), &ll->positions[ts.start + 1]); } } @@ -2587,7 +2588,7 @@ static ColourRGBA InvertedLight(ColourRGBA orig) noexcept { Sci::Position EditView::FormatRange(bool draw, const RangeToFormat *pfr, Surface *surface, Surface *surfaceMeasure, const EditModel &model, const ViewStyle &vs) { // Can't use measurements cached for screen - posCache.Clear(); + posCache->Clear(); ViewStyle vsPrint(vs); vsPrint.technology = Technology::Default; @@ -2756,7 +2757,7 @@ Sci::Position EditView::FormatRange(bool draw, const RangeToFormat *pfr, Surface } // Clear cache so measurements are not used for screen - posCache.Clear(); + posCache->Clear(); return nPrintPos; } diff --git a/src/EditView.h b/src/EditView.h index bac59ed31..e2101d745 100644 --- a/src/EditView.h +++ b/src/EditView.h @@ -81,7 +81,7 @@ public: std::unique_ptr<Surface> pixmapIndentGuideHighlight; LineLayoutCache llc; - PositionCache posCache; + std::unique_ptr<IPositionCache> posCache; int tabArrowHeight; // draw arrow heads this many pixels above/below line midpoint /** Some platforms, notably PLAT_CURSES, do not support Scintilla's native diff --git a/src/Editor.cxx b/src/Editor.cxx index a4d60019f..838f1830e 100644 --- a/src/Editor.cxx +++ b/src/Editor.cxx @@ -269,7 +269,7 @@ void Editor::InvalidateStyleData() { vs.technology = technology; DropGraphics(); view.llc.Invalidate(LineLayout::ValidLevel::invalid); - view.posCache.Clear(); + view.posCache->Clear(); } void Editor::InvalidateStyleRedraw() { @@ -6801,11 +6801,11 @@ sptr_t Editor::WndProc(Message iMessage, uptr_t wParam, sptr_t lParam) { return static_cast<sptr_t>(view.llc.GetLevel()); case Message::SetPositionCache: - view.posCache.SetSize(wParam); + view.posCache->SetSize(wParam); break; case Message::GetPositionCache: - return view.posCache.GetSize(); + return view.posCache->GetSize(); case Message::SetScrollWidth: PLATFORM_ASSERT(wParam > 0); diff --git a/src/PositionCache.cxx b/src/PositionCache.cxx index bedc843df..deee4c262 100644 --- a/src/PositionCache.cxx +++ b/src/PositionCache.cxx @@ -799,6 +799,48 @@ bool BreakFinder::More() const noexcept { return (subBreak >= 0) || (nextBreak < lineRange.end); } +class PositionCacheEntry { + uint16_t styleNumber; + uint16_t len; + uint16_t clock; + std::unique_ptr<XYPOSITION[]> positions; +public: + PositionCacheEntry() noexcept; + // Copy constructor not currently used, but needed for being element in std::vector. + PositionCacheEntry(const PositionCacheEntry &); + PositionCacheEntry(PositionCacheEntry &&) noexcept = default; + // Deleted so PositionCacheEntry objects can not be assigned. + void operator=(const PositionCacheEntry &) = delete; + void operator=(PositionCacheEntry &&) = delete; + ~PositionCacheEntry(); + void Set(unsigned int styleNumber_, std::string_view sv, const XYPOSITION *positions_, uint16_t clock_); + void Clear() noexcept; + bool Retrieve(unsigned int styleNumber_, std::string_view sv, XYPOSITION *positions_) const noexcept; + static size_t Hash(unsigned int styleNumber_, std::string_view sv) noexcept; + bool NewerThan(const PositionCacheEntry &other) const noexcept; + void ResetClock() noexcept; +}; + +class PositionCache : public IPositionCache { + std::vector<PositionCacheEntry> pces; + uint16_t clock; + bool allClear; +public: + PositionCache(); + // Deleted so LineAnnotation objects can not be copied. + PositionCache(const PositionCache &) = delete; + PositionCache(PositionCache &&) = delete; + void operator=(const PositionCache &) = delete; + void operator=(PositionCache &&) = delete; + ~PositionCache() override = default; + + void Clear() noexcept override; + void SetSize(size_t size_) override; + size_t GetSize() const noexcept override; + void MeasureWidths(Surface *surface, const ViewStyle &vstyle, unsigned int styleNumber, + std::string_view sv, XYPOSITION *positions) override; +}; + PositionCacheEntry::PositionCacheEntry() noexcept : styleNumber(0), len(0), clock(0) { } @@ -943,3 +985,7 @@ void PositionCache::MeasureWidths(Surface *surface, const ViewStyle &vstyle, uns pces[probe].Set(styleNumber, sv, positions, clock); } } + +std::unique_ptr<IPositionCache> Scintilla::Internal::CreatePositionCache() { + return std::make_unique<PositionCache>(); +} diff --git a/src/PositionCache.h b/src/PositionCache.h index 1cbc94495..e8c9293d1 100644 --- a/src/PositionCache.h +++ b/src/PositionCache.h @@ -163,28 +163,6 @@ public: Sci::Line linesOnScreen, Sci::Line linesInDoc); }; -class PositionCacheEntry { - uint16_t styleNumber; - uint16_t len; - uint16_t clock; - std::unique_ptr<XYPOSITION []> positions; -public: - PositionCacheEntry() noexcept; - // Copy constructor not currently used, but needed for being element in std::vector. - PositionCacheEntry(const PositionCacheEntry &); - PositionCacheEntry(PositionCacheEntry &&) noexcept = default; - // Deleted so PositionCacheEntry objects can not be assigned. - void operator=(const PositionCacheEntry &) = delete; - void operator=(PositionCacheEntry &&) = delete; - ~PositionCacheEntry(); - void Set(unsigned int styleNumber_, std::string_view sv, const XYPOSITION *positions_, uint16_t clock_); - void Clear() noexcept; - bool Retrieve(unsigned int styleNumber_, std::string_view sv, XYPOSITION *positions_) const noexcept; - static size_t Hash(unsigned int styleNumber_, std::string_view sv) noexcept; - bool NewerThan(const PositionCacheEntry &other) const noexcept; - void ResetClock() noexcept; -}; - class Representation { public: static constexpr size_t maxLength = 200; @@ -269,19 +247,18 @@ public: bool More() const noexcept; }; -class PositionCache { - std::vector<PositionCacheEntry> pces; - uint16_t clock; - bool allClear; +class IPositionCache { public: - PositionCache(); - void Clear() noexcept; - void SetSize(size_t size_); - size_t GetSize() const noexcept; - void MeasureWidths(Surface *surface, const ViewStyle &vstyle, unsigned int styleNumber, - std::string_view sv, XYPOSITION *positions); + virtual ~IPositionCache() = default; + virtual void Clear() noexcept = 0; + virtual void SetSize(size_t size_) = 0; + virtual size_t GetSize() const noexcept = 0; + virtual void MeasureWidths(Surface *surface, const ViewStyle &vstyle, unsigned int styleNumber, + std::string_view sv, XYPOSITION *positions) = 0; }; +std::unique_ptr<IPositionCache> CreatePositionCache(); + } #endif |