diff options
author | Neil <nyamatongwe@gmail.com> | 2025-02-15 11:16:22 +1100 |
---|---|---|
committer | Neil <nyamatongwe@gmail.com> | 2025-02-15 11:16:22 +1100 |
commit | 99497f846e812b5333eca87fe9f9812eab7daaf0 (patch) | |
tree | f915260d6857fa9a3b1c1e1639d809e0321d7a44 /src/PositionCache.cxx | |
parent | b4f518b2c7c5676b14b80518ddf75a77f39f00b4 (diff) | |
download | scintilla-mirror-99497f846e812b5333eca87fe9f9812eab7daaf0.tar.gz |
Minor changes to reduce warnings from Clang-Tidy.
Diffstat (limited to 'src/PositionCache.cxx')
-rw-r--r-- | src/PositionCache.cxx | 49 |
1 files changed, 21 insertions, 28 deletions
diff --git a/src/PositionCache.cxx b/src/PositionCache.cxx index 596e6f513..df5e5acf9 100644 --- a/src/PositionCache.cxx +++ b/src/PositionCache.cxx @@ -155,7 +155,7 @@ int LineLayout::LineStart(int line) const noexcept { int LineLayout::LineLength(int line) const noexcept { if (!lineStarts) { return numCharsInLine; - } if (line >= lines - 1) { + } else if (line >= lines - 1) { return numCharsInLine - lineStarts[line]; } else { return lineStarts[line + 1] - lineStarts[line]; @@ -421,8 +421,7 @@ ScreenLine::ScreenLine( tabWidthMinimumPixels(tabWidthMinimumPixels_) { } -ScreenLine::~ScreenLine() { -} +ScreenLine::~ScreenLine() = default; std::string_view ScreenLine::Text() const { return std::string_view(&ll->chars[start], len); @@ -510,7 +509,6 @@ bool AllGraphicASCII(std::string_view text) { size_t LineLayoutCache::EntryForLine(Sci::Line line) const noexcept { switch (level) { case LineCache::None: - return 0; case LineCache::Caret: return 0; case LineCache::Page: @@ -664,9 +662,10 @@ namespace { // Simply pack the (maximum 4) character bytes into an int constexpr unsigned int KeyFromString(std::string_view charBytes) noexcept { PLATFORM_ASSERT(charBytes.length() <= 4); + constexpr int byteMultiplier = 0x100; unsigned int k=0; for (const unsigned char uc : charBytes) { - k = k * 0x100 + uc; + k = k * byteMultiplier + uc; } return k; } @@ -694,16 +693,16 @@ namespace Scintilla::Internal { const char *ControlCharacterString(unsigned char ch) noexcept { if (ch < std::size(repsC0)) { return repsC0[ch]; - } else { - return "BAD"; } + return "BAD"; } void Hexits(char *hexits, int ch) noexcept { + constexpr int hexDivisor = 0x10; hexits[0] = 'x'; - hexits[1] = "0123456789ABCDEF"[ch / 0x10]; - hexits[2] = "0123456789ABCDEF"[ch % 0x10]; + hexits[1] = "0123456789ABCDEF"[ch / hexDivisor]; + hexits[2] = "0123456789ABCDEF"[ch % hexDivisor]; hexits[3] = 0; } @@ -996,10 +995,10 @@ bool BreakFinder::More() const noexcept { } class PositionCacheEntry { - uint16_t styleNumber; - uint16_t len; - uint16_t clock; - bool unicode; + uint16_t styleNumber = 0; + uint16_t len = 0; + uint16_t clock = 0; + bool unicode = false; std::unique_ptr<XYPOSITION[]> positions; public: PositionCacheEntry() noexcept; @@ -1014,15 +1013,16 @@ public: void Clear() noexcept; bool Retrieve(unsigned int styleNumber_, bool unicode_, std::string_view sv, XYPOSITION *positions_) const noexcept; static size_t Hash(unsigned int styleNumber_, bool unicode_, std::string_view sv) noexcept; - bool NewerThan(const PositionCacheEntry &other) const noexcept; + [[nodiscard]] bool NewerThan(const PositionCacheEntry &other) const noexcept; void ResetClock() noexcept; }; class PositionCache : public IPositionCache { - std::vector<PositionCacheEntry> pces; + static constexpr size_t defaultCacheSize = 0x400; + std::vector<PositionCacheEntry> pces{ defaultCacheSize }; std::mutex mutex; - uint16_t clock; - bool allClear; + uint16_t clock = 1; + bool allClear = true; public: PositionCache(); // Deleted so LineAnnotation objects can not be copied. @@ -1034,14 +1034,12 @@ public: void Clear() noexcept override; void SetSize(size_t size_) override; - size_t GetSize() const noexcept override; + [[nodiscard]] size_t GetSize() const noexcept override; void MeasureWidths(Surface *surface, const ViewStyle &vstyle, unsigned int styleNumber, bool unicode, std::string_view sv, XYPOSITION *positions, bool needsLocking) override; }; -PositionCacheEntry::PositionCacheEntry() noexcept : - styleNumber(0), len(0), clock(0), unicode(false) { -} +PositionCacheEntry::PositionCacheEntry() noexcept = default; // Copy constructor not currently used, but needed for being element in std::vector. PositionCacheEntry::PositionCacheEntry(const PositionCacheEntry &other) : @@ -1087,9 +1085,8 @@ bool PositionCacheEntry::Retrieve(unsigned int styleNumber_, bool unicode_, std: positions_[i] = positions[i]; } return true; - } else { - return false; } + return false; } size_t PositionCacheEntry::Hash(unsigned int styleNumber_, bool unicode_, std::string_view sv) noexcept { @@ -1108,11 +1105,7 @@ void PositionCacheEntry::ResetClock() noexcept { } } -PositionCache::PositionCache() { - clock = 1; - pces.resize(0x400); - allClear = true; -} +PositionCache::PositionCache() = default; void PositionCache::Clear() noexcept { if (!allClear) { |