From a3fff53a48e63064b14f7a1842b20f260bc5a9bc Mon Sep 17 00:00:00 2001 From: Neil Date: Thu, 20 Jan 2022 08:36:24 +1100 Subject: Hide details of PositionCache. Move class declarations of PositionCache and PositionCacheEntry into cxx file and only define IPositionCache interface and CreatePositionCache factory function in header. --- src/PositionCache.cxx | 46 ++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 46 insertions(+) (limited to 'src/PositionCache.cxx') 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 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 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 Scintilla::Internal::CreatePositionCache() { + return std::make_unique(); +} -- cgit v1.2.3