aboutsummaryrefslogtreecommitdiffhomepage
path: root/src/PositionCache.cxx
diff options
context:
space:
mode:
authorNeil <nyamatongwe@gmail.com>2022-01-20 08:36:24 +1100
committerNeil <nyamatongwe@gmail.com>2022-01-20 08:36:24 +1100
commita3fff53a48e63064b14f7a1842b20f260bc5a9bc (patch)
tree6d2ce6b1c61e94a0a708a3442977776f07a1d3f1 /src/PositionCache.cxx
parent5aff87386c21d5a345eff5b1982f4171577a922c (diff)
downloadscintilla-mirror-a3fff53a48e63064b14f7a1842b20f260bc5a9bc.tar.gz
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.
Diffstat (limited to 'src/PositionCache.cxx')
-rw-r--r--src/PositionCache.cxx46
1 files changed, 46 insertions, 0 deletions
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>();
+}