diff options
author | Neil <nyamatongwe@gmail.com> | 2022-02-02 14:25:51 +1100 |
---|---|---|
committer | Neil <nyamatongwe@gmail.com> | 2022-02-02 14:25:51 +1100 |
commit | fd2623102a9bad31258a0ef31ce6a2972ae6ddad (patch) | |
tree | 621fa123bdab1e9f4ef94613c0fbf509f2ce36e3 /src/PositionCache.cxx | |
parent | 53ca05457a1d7306defd98ee4a21eb18e6a9be8d (diff) | |
download | scintilla-mirror-fd2623102a9bad31258a0ef31ce6a2972ae6ddad.tar.gz |
Feature [feature-requests:#1427] Add multithreaded layout which improves
performance significantly for very wide lines.
Diffstat (limited to 'src/PositionCache.cxx')
-rw-r--r-- | src/PositionCache.cxx | 14 |
1 files changed, 12 insertions, 2 deletions
diff --git a/src/PositionCache.cxx b/src/PositionCache.cxx index 4025ec651..23733c3a0 100644 --- a/src/PositionCache.cxx +++ b/src/PositionCache.cxx @@ -21,6 +21,7 @@ #include <algorithm> #include <iterator> #include <memory> +#include <mutex> #include "ScintillaTypes.h" #include "ScintillaMessages.h" @@ -822,6 +823,7 @@ public: class PositionCache : public IPositionCache { std::vector<PositionCacheEntry> pces; + std::mutex mutex; uint16_t clock; bool allClear; public: @@ -837,7 +839,7 @@ public: 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; + std::string_view sv, XYPOSITION *positions, bool needsLocking) override; }; PositionCacheEntry::PositionCacheEntry() noexcept : @@ -934,7 +936,7 @@ size_t PositionCache::GetSize() const noexcept { } void PositionCache::MeasureWidths(Surface *surface, const ViewStyle &vstyle, unsigned int styleNumber, - std::string_view sv, XYPOSITION *positions) { + std::string_view sv, XYPOSITION *positions, bool needsLocking) { const Style &style = vstyle.styles[styleNumber]; if (style.monospaceASCII) { if (AllGraphicASCII(sv)) { @@ -954,6 +956,10 @@ void PositionCache::MeasureWidths(Surface *surface, const ViewStyle &vstyle, uns // Two way associative: try two probe positions. const size_t hashValue = PositionCacheEntry::Hash(styleNumber, sv); probe = hashValue % pces.size(); + std::unique_lock<std::mutex> guard(mutex, std::defer_lock); + if (needsLocking) { + guard.lock(); + } if (pces[probe].Retrieve(styleNumber, sv, positions)) { return; } @@ -971,6 +977,10 @@ void PositionCache::MeasureWidths(Surface *surface, const ViewStyle &vstyle, uns surface->MeasureWidths(fontStyle, sv, positions); if (probe < pces.size()) { // Store into cache + std::unique_lock<std::mutex> guard(mutex, std::defer_lock); + if (needsLocking) { + guard.lock(); + } clock++; if (clock > 60000) { // Since there are only 16 bits for the clock, wrap it round and |