aboutsummaryrefslogtreecommitdiffhomepage
path: root/src/CellBuffer.cxx
diff options
context:
space:
mode:
authorZufu Liu <unknown>2021-07-15 17:29:24 +1000
committerZufu Liu <unknown>2021-07-15 17:29:24 +1000
commit39be73514c317e7d672e0a09862571e64f8979da (patch)
treebbfb503821368eaa608174af4532f50026e3f723 /src/CellBuffer.cxx
parentf4878568f55a9c3b6eef8cc8fad9b1aa7e8ab4ce (diff)
downloadscintilla-mirror-39be73514c317e7d672e0a09862571e64f8979da.tar.gz
Feature [feature-requests:#1370] Implement SCI_ALLOCATELINES to allocate indices
to hold some number of lines. This is an optimization that can decrease reallocation overhead.
Diffstat (limited to 'src/CellBuffer.cxx')
-rw-r--r--src/CellBuffer.cxx23
1 files changed, 23 insertions, 0 deletions
diff --git a/src/CellBuffer.cxx b/src/CellBuffer.cxx
index f02d5348a..d94ffaaea 100644
--- a/src/CellBuffer.cxx
+++ b/src/CellBuffer.cxx
@@ -71,6 +71,7 @@ public:
virtual void SetLineStart(Sci::Line line, Sci::Position position) noexcept = 0;
virtual void RemoveLine(Sci::Line line) = 0;
virtual Sci::Line Lines() const noexcept = 0;
+ virtual void AllocateLines(Sci::Line lines) = 0;
virtual Sci::Line LineFromPosition(Sci::Position pos) const noexcept = 0;
virtual Sci::Position LineStart(Sci::Line line) const noexcept = 0;
virtual void InsertCharacters(Sci::Line line, CountWidths delta) noexcept = 0;
@@ -132,6 +133,11 @@ public:
const Sci::Position widthCurrent = LineWidth(line);
starts.InsertText(static_cast<POS>(line), static_cast<POS>(width - widthCurrent));
}
+ void AllocateLines(Sci::Line lines) {
+ if (lines > starts.Partitions()) {
+ starts.ReAllocate(lines);
+ }
+ }
void InsertLines(Sci::Line line, Sci::Line lines) {
// Insert multiple lines with each temporarily 1 character wide.
// The line widths will be fixed up by later measuring code.
@@ -237,6 +243,17 @@ public:
Sci::Line Lines() const noexcept override {
return static_cast<Sci::Line>(starts.Partitions());
}
+ void AllocateLines(Sci::Line lines) override {
+ if (lines > Lines()) {
+ starts.ReAllocate(lines);
+ if (FlagSet(activeIndices, LineCharacterIndexType::Utf32)) {
+ startsUTF32.AllocateLines(lines);
+ }
+ if (FlagSet(activeIndices, LineCharacterIndexType::Utf16)) {
+ startsUTF16.AllocateLines(lines);
+ }
+ }
+ }
Sci::Line LineFromPosition(Sci::Position pos) const noexcept override {
return static_cast<Sci::Line>(starts.PartitionFromPosition(static_cast<POS>(pos)));
}
@@ -789,6 +806,10 @@ Sci::Line CellBuffer::Lines() const noexcept {
return plv->Lines();
}
+void CellBuffer::AllocateLines(Sci::Line lines) {
+ plv->AllocateLines(lines);
+}
+
Sci::Position CellBuffer::LineStart(Sci::Line line) const noexcept {
if (line < 0)
return 0;
@@ -903,7 +924,9 @@ bool CellBuffer::UTF8IsCharacterBoundary(Sci::Position position) const {
void CellBuffer::ResetLineEnds() {
// Reinitialize line data -- too much work to preserve
+ const Sci::Line lines = plv->Lines();
plv->Init();
+ plv->AllocateLines(lines);
constexpr Sci::Position position = 0;
const Sci::Position length = Length();