From 5bbf68518b63ae8c848a26e251443d66c66a6017 Mon Sep 17 00:00:00 2001 From: zufuliu Date: Sun, 8 Dec 2024 19:09:20 +0800 Subject: [PATCH] Weekly Scintilla sync up. --- scintilla/src/CaseFolder.cxx | 13 ++++---- scintilla/src/CellBuffer.cxx | 58 ++++++++++++++++++--------------- scintilla/src/CellBuffer.h | 10 +++--- scintilla/src/Document.cxx | 5 ++- scintilla/src/Document.h | 2 +- scintilla/src/EditModel.cxx | 7 ++-- scintilla/src/EditModel.h | 2 +- scintilla/src/Editor.cxx | 12 ++++--- scintilla/src/Partitioning.h | 2 +- scintilla/src/PerLine.h | 6 ++-- scintilla/src/PositionCache.cxx | 2 +- scintilla/src/RunStyles.cxx | 26 +++++++++++---- scintilla/src/SparseVector.h | 4 +-- scintilla/src/SplitVector.h | 23 +++++++++---- scintilla/src/Style.cxx | 2 +- scintilla/src/UndoHistory.cxx | 3 +- scintilla/src/UndoHistory.h | 2 +- src/Edit.cpp | 3 ++ version.txt | 2 +- 19 files changed, 109 insertions(+), 75 deletions(-) diff --git a/scintilla/src/CaseFolder.cxx b/scintilla/src/CaseFolder.cxx index 236c9a7174..f7938db7fa 100644 --- a/scintilla/src/CaseFolder.cxx +++ b/scintilla/src/CaseFolder.cxx @@ -35,16 +35,15 @@ CaseFolderTable::CaseFolderTable() noexcept { size_t CaseFolderTable::Fold(char *folded, size_t sizeFolded, const char *mixed, size_t lenMixed) { if (lenMixed > sizeFolded) { return 0; - } else { - for (size_t i = 0; i < lenMixed; i++) { - folded[i] = mapping[IndexFromChar(mixed[i])]; - } - return lenMixed; } + for (size_t i = 0; i < lenMixed; i++) { + folded[i] = mapping[IndexFromChar(mixed[i])]; + } + return lenMixed; } void CaseFolderTable::SetTranslation(char ch, char chTranslation) noexcept { - mapping[static_cast(ch)] = chTranslation; + mapping[IndexFromChar(ch)] = chTranslation; } CaseFolderUnicode::CaseFolderUnicode() { @@ -53,7 +52,7 @@ CaseFolderUnicode::CaseFolderUnicode() { size_t CaseFolderUnicode::Fold(char *folded, size_t sizeFolded, const char *mixed, size_t lenMixed) { if ((lenMixed == 1) && (sizeFolded > 0)) { - folded[0] = mapping[static_cast(mixed[0])]; + folded[0] = mapping[IndexFromChar(mixed[0])]; return 1; } else { return converter->CaseConvertString(folded, sizeFolded, mixed, lenMixed); diff --git a/scintilla/src/CellBuffer.cxx b/scintilla/src/CellBuffer.cxx index 7c1f171379..00e5209238 100644 --- a/scintilla/src/CellBuffer.cxx +++ b/scintilla/src/CellBuffer.cxx @@ -97,6 +97,8 @@ class ILineVector { using namespace Scintilla; using namespace Scintilla::Internal; +namespace { + template class LineStartIndex final { // line_cast(): cast Sci::Line to either 32-bit or 64-bit value @@ -334,28 +336,23 @@ class LineVector final : public ILineVector { } }; -SplitView::SplitView(const SplitVector &instance) noexcept { - length = instance.Length(); - length1 = instance.GapPosition(); - if (length1 == 0) { - // Assign segment2 to segment1 / length1 to avoid useless test against 0 length1 - length1 = length; - } - segment1 = instance.ElementPointer(0); - segment2 = instance.ElementPointer(length1) - length1; +std::unique_ptr LineVectorCreate(bool largeDocument) { + if (largeDocument) + return std::make_unique>(); + else + return std::make_unique>(); +} + } CellBuffer::CellBuffer(bool hasStyles_, bool largeDocument_) : - hasStyles(hasStyles_), largeDocument(largeDocument_) { + hasStyles(hasStyles_), largeDocument(largeDocument_), + uh{std::make_unique()}, + plv{LineVectorCreate(largeDocument_)} { readOnly = false; utf8Substance = false; utf8LineEnds = LineEndType::Default; collectingUndo = true; - uh = std::make_unique(); - if (largeDocument) - plv = std::make_unique>(); - else - plv = std::make_unique>(); } CellBuffer::~CellBuffer() noexcept = default; @@ -364,10 +361,6 @@ char CellBuffer::CharAt(Sci::Position position) const noexcept { return substance.ValueAt(position); } -unsigned char CellBuffer::UCharAt(Sci::Position position) const noexcept { - return substance.ValueAt(position); -} - void CellBuffer::GetCharRange(char *buffer, Sci::Position position, Sci::Position lengthRetrieve) const noexcept { if ((position | lengthRetrieve) <= 0) { return; @@ -425,7 +418,18 @@ Sci::Position CellBuffer::GapPosition() const noexcept { } SplitView CellBuffer::AllView() const noexcept { - return SplitView(substance); + const size_t length = substance.Length(); + size_t length1 = substance.GapPosition(); + if (length1 == 0) { + // Assign segment2 to segment1 / length1 to avoid useless test against 0 length1 + length1 = length; + } + return SplitView { + substance.ElementPointer(0), + length1, + substance.ElementPointer(length1) - length1, + length + }; } // The char* returned is to an allocation owned by the undo history @@ -705,7 +709,7 @@ void CellBuffer::ResetLineEnds() { unsigned char chBeforePrev = 0; unsigned char chPrev = 0; for (Sci::Position i = 0; i < length; i++) { - const unsigned char ch = substance.ValueAt(position + i); + const unsigned char ch = substance[position + 1]; if (ch == '\r') { InsertLine(lineInsert, (position + i) + 1, atLineStart); lineInsert++; @@ -1260,11 +1264,13 @@ void CellBuffer::BasicDeleteChars(const Sci::Position position, const Sci::Posit } else { RemoveLine(lineRemove); } - } else if (utf8LineEnds != LineEndType::Default && !UTF8IsAscii(ch)) { - const unsigned char next3[3] = { ch, chNext, - static_cast(substance.ValueAt(position + i + 2)) }; - if (UTF8IsSeparator(next3) || UTF8IsNEL(next3)) { - RemoveLine(lineRemove); + } else if (utf8LineEnds != LineEndType::Default) { + if (!UTF8IsAscii(ch)) { + const unsigned char next3[3] = { ch, chNext, + static_cast(substance.ValueAt(position + i + 2)) }; + if (UTF8IsSeparator(next3) || UTF8IsNEL(next3)) { + RemoveLine(lineRemove); + } } } diff --git a/scintilla/src/CellBuffer.h b/scintilla/src/CellBuffer.h index 4e0257e3a2..cff04156e3 100644 --- a/scintilla/src/CellBuffer.h +++ b/scintilla/src/CellBuffer.h @@ -48,8 +48,6 @@ struct SplitView { const char *segment2 = nullptr; size_t length = 0; - SplitView(const SplitVector &instance) noexcept; - char operator[](size_t position) const noexcept { if (position < length1) { return segment1[position]; @@ -84,11 +82,11 @@ class CellBuffer { SplitVector style; bool collectingUndo; - std::unique_ptr uh; + const std::unique_ptr uh; std::unique_ptr changeHistory; - std::unique_ptr plv; + const std::unique_ptr plv; bool UTF8LineEndOverlaps(Sci::Position position) const noexcept; bool UTF8IsCharacterBoundary(Sci::Position position) const; @@ -110,7 +108,9 @@ class CellBuffer { /// Retrieving positions outside the range of the buffer works and returns 0 char CharAt(Sci::Position position) const noexcept; - unsigned char UCharAt(Sci::Position position) const noexcept; + unsigned char UCharAt(Sci::Position position) const noexcept { + return CharAt(position); + } void GetCharRange(char *buffer, Sci::Position position, Sci::Position lengthRetrieve) const noexcept; char StyleAt(Sci::Position position) const noexcept; void GetStyleRange(unsigned char *buffer, Sci::Position position, Sci::Position lengthRetrieve) const noexcept; diff --git a/scintilla/src/Document.cxx b/scintilla/src/Document.cxx index 81c4253c79..4cd2a105a5 100644 --- a/scintilla/src/Document.cxx +++ b/scintilla/src/Document.cxx @@ -142,7 +142,8 @@ CharacterExtracted::CharacterExtracted(const unsigned char *charBytes, size_t wi Document::Document(DocumentOption options) : cb(!FlagSet(options, DocumentOption::StylesNone), FlagSet(options, DocumentOption::TextLarge)), - durationStyleOneUnit(1e-6) { + durationStyleOneUnit(1e-6), + decorations{DecorationListCreate(IsLarge())} { perLineData[ldMarkers] = std::make_unique(); perLineData[ldLevels] = std::make_unique(); @@ -151,8 +152,6 @@ Document::Document(DocumentOption options) : perLineData[ldAnnotation] = std::make_unique(); perLineData[ldEOLAnnotation] = std::make_unique(); - decorations = DecorationListCreate(IsLarge()); - cb.SetPerLine(this); cb.SetUTF8Substance(CpUtf8 == dbcsCodePage); } diff --git a/scintilla/src/Document.h b/scintilla/src/Document.h index 3d8318bef7..d4bd556652 100644 --- a/scintilla/src/Document.h +++ b/scintilla/src/Document.h @@ -329,7 +329,7 @@ class Document : PerLine, public Scintilla::IDocument, public Scintilla::ILoader uint8_t asciiBackwardSafeChar = 0xff; ActionDuration durationStyleOneUnit; - std::unique_ptr decorations; + const std::unique_ptr decorations; explicit Document(Scintilla::DocumentOption options); // Deleted so Document objects can not be copied. diff --git a/scintilla/src/EditModel.cxx b/scintilla/src/EditModel.cxx index 5be12f0db3..b7c56547f8 100644 --- a/scintilla/src/EditModel.cxx +++ b/scintilla/src/EditModel.cxx @@ -58,7 +58,10 @@ using namespace Scintilla::Internal; Caret::Caret() noexcept : active(false), on(false), period(500) {} -EditModel::EditModel() : durationWrapOneUnit(0.01 / 64), durationWrapOneThread(0.01 / 16) { +EditModel::EditModel() : + reprs{std::make_unique()}, + pcs{ContractionStateCreate(false)}, + durationWrapOneUnit(0.01 / 64), durationWrapOneThread(0.01 / 16) { inOverstrike = false; trackLineWidth = false; hasFocus = false; @@ -77,11 +80,9 @@ EditModel::EditModel() : durationWrapOneUnit(0.01 / 64), durationWrapOneThread(0 hotspotSingleLine = true; hoverIndicatorPos = Sci::invalidPosition; wrapWidth = LineLayout::wrapWidthInfinite; - reprs = std::make_unique(); // before setting a lexer, style buffer is useless. pdoc = new Document(DocumentOption::StylesNone); pdoc->AddRef(); - pcs = ContractionStateCreate(pdoc->IsLarge()); SYSTEM_INFO info; GetNativeSystemInfo(&info); diff --git a/scintilla/src/EditModel.h b/scintilla/src/EditModel.h index eabc3996ea..5972c11eaa 100644 --- a/scintilla/src/EditModel.h +++ b/scintilla/src/EditModel.h @@ -28,7 +28,7 @@ class EditModel { bool primarySelection; int xOffset; ///< Horizontal scrolled amount in pixels - std::unique_ptr reprs; + const std::unique_ptr reprs; Caret caret; SelectionPosition posDrag; Sci::Position braces[2]; diff --git a/scintilla/src/Editor.cxx b/scintilla/src/Editor.cxx index 2bf951f0d2..bbf76a5892 100644 --- a/scintilla/src/Editor.cxx +++ b/scintilla/src/Editor.cxx @@ -516,10 +516,14 @@ void Editor::RedrawSelMargin(Sci::Line line, bool allAfter) noexcept { } PRectangle Editor::RectangleFromRange(Range r, int overlap) const noexcept { - const Sci::Line minLine = pcs->DisplayFromDoc( - pdoc->SciLineFromPosition(r.First())); - const Sci::Line maxLine = pcs->DisplayLastFromDoc( - pdoc->SciLineFromPosition(r.Last())); + const Sci::Line docLineFirst = pdoc->SciLineFromPosition(r.First()); + const Sci::Line minLine = pcs->DisplayFromDoc(docLineFirst); + Sci::Line docLineLast = docLineFirst; // Common case where range is wholly in one document line + if (r.Last() >= pdoc->LineStart(docLineFirst + 1)) { + // Range covers multiple lines so need last line + docLineLast = pdoc->SciLineFromPosition(r.Last()); + } + const Sci::Line maxLine = pcs->DisplayLastFromDoc(docLineLast); const PRectangle rcClientDrawing = GetClientDrawingRectangle(); PRectangle rc; const int leftTextOverlap = ((xOffset == 0) && (vs.leftMarginWidth > 0)) ? 1 : 0; diff --git a/scintilla/src/Partitioning.h b/scintilla/src/Partitioning.h index 274bc04b8a..f6f5d08f09 100644 --- a/scintilla/src/Partitioning.h +++ b/scintilla/src/Partitioning.h @@ -202,7 +202,7 @@ class Partitioning { T upper = partition; do { const T middle = (upper + lower + 1) / 2; // Round high - T posMiddle = body.ValueAt(middle); + T posMiddle = body[middle]; if (middle > stepPartition) posMiddle += stepLength; if (pos < posMiddle) { diff --git a/scintilla/src/PerLine.h b/scintilla/src/PerLine.h index 980e05ae5e..52c493ec9f 100644 --- a/scintilla/src/PerLine.h +++ b/scintilla/src/PerLine.h @@ -63,7 +63,7 @@ class LineLevels final : public PerLine { SplitVector levels; Scintilla::FoldLevel GetFoldLevel(Sci::Line line) const noexcept; public: - LineLevels() = default; + LineLevels() noexcept = default; void Init() override; bool IsActive() const noexcept override; void InsertLine(Sci::Line line) override; @@ -80,7 +80,7 @@ class LineLevels final : public PerLine { class LineState final : public PerLine { SplitVector lineStates; public: - LineState() = default; + LineState() noexcept = default; void Init() override; bool IsActive() const noexcept override; void InsertLine(Sci::Line line) override; @@ -94,7 +94,7 @@ class LineState final : public PerLine { class LineAnnotation : public PerLine { SplitVector> annotations; public: - LineAnnotation() = default; + LineAnnotation() noexcept = default; [[nodiscard]] bool Empty() const noexcept; void Init() override; diff --git a/scintilla/src/PositionCache.cxx b/scintilla/src/PositionCache.cxx index a551daec05..68507a0d04 100644 --- a/scintilla/src/PositionCache.cxx +++ b/scintilla/src/PositionCache.cxx @@ -799,7 +799,7 @@ LineLayout *LineLayoutCache::Retrieve(Sci::Line lineNumber, Sci::Line lineCaret, //printf("USE line=%zd/%zd, caret=%zd/%zd top=%zd, pos=%zu, clock=%d\n", // lineNumber, ret->lineNumber, lineCaret, lastCaretSlot, topLine, pos, styleClock_); ret->Free(); - new (ret) LineLayout(lineNumber, maxChars); + ::new (ret) LineLayout(lineNumber, maxChars); } else { //printf("HIT line=%zd, caret=%zd/%zd top=%zd, pos=%zu, clock=%d, validity=%d\n", // lineNumber, lineCaret, lastCaretSlot, topLine, pos, styleClock_, ret->validity); diff --git a/scintilla/src/RunStyles.cxx b/scintilla/src/RunStyles.cxx index c8b48197f8..41ecf3948d 100644 --- a/scintilla/src/RunStyles.cxx +++ b/scintilla/src/RunStyles.cxx @@ -81,8 +81,6 @@ void RunStyles::RemoveRunIfSameAsPrevious(DISTANCE run) { template RunStyles::RunStyles() { - starts = Partitioning(8); - styles = SplitVector