From f07caccbf33acd188cbe4961ece30251102351cc Mon Sep 17 00:00:00 2001 From: Neil Date: Mon, 30 Mar 2026 18:30:55 +1100 Subject: Feature [feature-requests:#1582]. Improve performance of Document::SetStyles. Report changed range for Document::SetStyleFor. --- src/CellBuffer.h | 24 +++++++++++++++++++++--- 1 file changed, 21 insertions(+), 3 deletions(-) (limited to 'src/CellBuffer.h') diff --git a/src/CellBuffer.h b/src/CellBuffer.h index 1b035597a..e48eded4d 100644 --- a/src/CellBuffer.h +++ b/src/CellBuffer.h @@ -66,6 +66,24 @@ struct SplitView { } }; +struct ChangedRange { + Sci::Position start = Sci::invalidPosition; + Sci::Position end = Sci::invalidPosition; + ChangedRange() noexcept = default; + ChangedRange(Sci::Position start_, Sci::Position end_) noexcept : start(start_), end(end_) {} + [[nodiscard]] bool Empty() const noexcept { + return start < 0; + } + void Merge(const ChangedRange &cr2) noexcept { + if (cr2.start >= 0) { + if (start < 0) { + *this = cr2; + } else { + end = cr2.end; + } + } + } +}; /** * Holder for an expandable array of characters that supports undo and line markers. @@ -141,9 +159,9 @@ public: const char *InsertString(Sci::Position position, const char *s, Sci::Position insertLength, bool &startSequence); /// Setting styles for positions outside the range of the buffer is safe and has no effect. - /// @return true if the style of a character is changed. - bool SetStyleAt(Sci::Position position, char styleValue) noexcept; - bool SetStyleFor(Sci::Position position, Sci::Position lengthStyle, char styleValue) noexcept; + /// @return range where style of characters changed. + ChangedRange SetStyles(Sci::Position position, const char *styles, Sci::Position length) noexcept; + ChangedRange SetStyleFor(Sci::Position position, Sci::Position lengthStyle, char styleValue) noexcept; const char *DeleteChars(Sci::Position position, Sci::Position deleteLength, bool &startSequence); -- cgit v1.2.3