aboutsummaryrefslogtreecommitdiffhomepage
diff options
context:
space:
mode:
authorNeil <nyamatongwe@gmail.com>2018-02-02 14:34:55 +1100
committerNeil <nyamatongwe@gmail.com>2018-02-02 14:34:55 +1100
commit3f1c1f5fe73d9fe48af8ffc2f0dbf2107d65cf52 (patch)
tree2f662f0da33a58e1e9700b358ab695c3c04b7465
parentcc13723d8f558fb7c48f3f4ed1bb107f35b95397 (diff)
downloadscintilla-mirror-3f1c1f5fe73d9fe48af8ffc2f0dbf2107d65cf52.tar.gz
Implement SC_DOCUMENTOPTION_STYLES_NONE.
-rw-r--r--doc/ScintillaDoc.html42
-rw-r--r--doc/ScintillaHistory.html5
-rw-r--r--include/Scintilla.h1
-rw-r--r--include/Scintilla.iface1
-rw-r--r--qt/ScintillaEdit/ScintillaDocument.cpp2
-rw-r--r--src/CellBuffer.cxx27
-rw-r--r--src/CellBuffer.h3
-rw-r--r--src/Document.cxx3
-rw-r--r--src/Document.h2
-rw-r--r--src/EditModel.cxx2
-rw-r--r--src/Editor.cxx6
-rw-r--r--test/unit/testCellBuffer.cxx2
12 files changed, 75 insertions, 21 deletions
diff --git a/doc/ScintillaDoc.html b/doc/ScintillaDoc.html
index c2303c609..f9bc4259e 100644
--- a/doc/ScintillaDoc.html
+++ b/doc/ScintillaDoc.html
@@ -119,7 +119,7 @@
<h1>Scintilla Documentation</h1>
- <p>Last edited 31 January 2018 NH</p>
+ <p>Last edited 1 February 2018 NH</p>
<p>There is <a class="jump" href="Design.html">an overview of the internal design of
Scintilla</a>.<br />
@@ -5743,9 +5743,38 @@ sptr_t CallScintilla(unsigned int iMessage, uptr_t wParam, sptr_t lParam){
to allocate once rather than rely on the buffer growing as data is added.
If <code>SCI_CREATEDOCUMENT</code> fails then 0 is returned.</p>
- <p>The <code class="parameter">documentOption</code> argument may be used in future versions
- to choose between different document capabilities which affect memory allocation and performance.
- The only valid value for now is <code>SC_DOCUMENTOPTION_DEFAULT</code> (0).</p>
+ <p id="documentOption">The <code class="parameter">documentOption</code> argument
+ chooses between different document capabilities which affect memory allocation and performance with
+ <code>SC_DOCUMENTOPTION_DEFAULT</code> (0) choosing standard options.
+ <code>SC_DOCUMENTOPTION_STYLES_NONE</code> (1) stops allocation of memory to style characters
+ which saves significant memory, often 40% with the whole document treated as being style 0.
+ Lexers may still produce visual styling by using indicators.</p>
+
+ <table class="standard" summary="Document options">
+ <tbody>
+ <tr>
+ <th align="left">Symbol</th>
+ <th align="left">Value</th>
+ <th align="left">Effect</th>
+ </tr>
+ </tbody>
+
+ <tbody valign="top">
+
+ <tr>
+ <td align="left">SC_DOCUMENTOPTION_DEFAULT</td>
+ <td align="left">0</td>
+ <td align="left">Standard behaviour</td>
+ </tr>
+
+ <tr>
+ <td align="left">SC_DOCUMENTOPTION_STYLES_NONE</td>
+ <td align="left">1</td>
+ <td align="left">Stop allocation of memory for styles and treat all text as style 0.</td>
+ </tr>
+
+ </tbody>
+ </table>
<p><b id="SCI_ADDREFDOCUMENT">SCI_ADDREFDOCUMENT(&lt;unused&gt;, document *doc)</b><br />
This increases the reference count of a document by 1. If you want to replace the current
@@ -5788,9 +5817,8 @@ sptr_t CallScintilla(unsigned int iMessage, uptr_t wParam, sptr_t lParam){
to allocate once rather than rely on the buffer growing as data is added.
If <code>SCI_CREATELOADER</code> fails then 0 is returned.</p>
- <p>The <code class="parameter">documentOption</code> argument may be used in future versions
- to choose between different document capabilities which affect memory allocation and performance.
- The only valid value for now is <code>SC_DOCUMENTOPTION_DEFAULT</code> (0).</p>
+ <p>The <code class="parameter">documentOption</code> argument
+ is described in the <a class="seealso" href="#documentOption"><code>SCI_CREATEDOCUMENT</code></a> section.</p>
<h4>ILoader</h4>
diff --git a/doc/ScintillaHistory.html b/doc/ScintillaHistory.html
index 2aa2ff5b9..9e01bfcec 100644
--- a/doc/ScintillaHistory.html
+++ b/doc/ScintillaHistory.html
@@ -539,6 +539,11 @@
</li>
<li>
SCI_CREATEDOCUMENT adds a bytes argument to allocate memory for an initial size.
+ SCI_CREATELOADER and SCI_CREATEDOCUMENT add a documentOption argument to
+ allow choosing different document capabilities.
+ </li>
+ <li>
+ Add SC_DOCUMENTOPTION_STYLES_NONE option to stop allocating memory for styles.
</li>
<li>
Add SCI_GETMOVEEXTENDSSELECTION to allow applications to add more
diff --git a/include/Scintilla.h b/include/Scintilla.h
index 7ab202da5..3a0af8cf7 100644
--- a/include/Scintilla.h
+++ b/include/Scintilla.h
@@ -690,6 +690,7 @@ typedef sptr_t (*SciFnDirect)(sptr_t ptr, unsigned int iMessage, uptr_t wParam,
#define SCI_SETZOOM 2373
#define SCI_GETZOOM 2374
#define SC_DOCUMENTOPTION_DEFAULT 0
+#define SC_DOCUMENTOPTION_STYLES_NONE 1
#define SCI_CREATEDOCUMENT 2375
#define SCI_ADDREFDOCUMENT 2376
#define SCI_RELEASEDOCUMENT 2377
diff --git a/include/Scintilla.iface b/include/Scintilla.iface
index 68e528de1..d68314eda 100644
--- a/include/Scintilla.iface
+++ b/include/Scintilla.iface
@@ -1773,6 +1773,7 @@ get int GetZoom=2374(,)
enu DocumentOption=SC_DOCUMENTOPTION_
val SC_DOCUMENTOPTION_DEFAULT=0
+val SC_DOCUMENTOPTION_STYLES_NONE=1
# Create a new document object.
# Starts with reference count of 1 and not selected into editor.
diff --git a/qt/ScintillaEdit/ScintillaDocument.cpp b/qt/ScintillaEdit/ScintillaDocument.cpp
index 1ba39be32..5e80a33bd 100644
--- a/qt/ScintillaEdit/ScintillaDocument.cpp
+++ b/qt/ScintillaEdit/ScintillaDocument.cpp
@@ -91,7 +91,7 @@ void WatcherHelper::NotifyErrorOccurred(Document *, void *, int status) {
ScintillaDocument::ScintillaDocument(QObject *parent, void *pdoc_) :
QObject(parent), pdoc(pdoc_), docWatcher(0) {
if (!pdoc) {
- pdoc = new Document();
+ pdoc = new Document(SC_DOCUMENTOPTION_DEFAULT);
}
docWatcher = new WatcherHelper(this);
(static_cast<Document *>(pdoc))->AddRef();
diff --git a/src/CellBuffer.cxx b/src/CellBuffer.cxx
index 1884a497a..513c9a9b8 100644
--- a/src/CellBuffer.cxx
+++ b/src/CellBuffer.cxx
@@ -342,7 +342,8 @@ void UndoHistory::CompletedRedoStep() {
currentAction++;
}
-CellBuffer::CellBuffer() {
+CellBuffer::CellBuffer(bool hasStyles_) :
+ hasStyles(hasStyles_) {
readOnly = false;
utf8LineEnds = 0;
collectingUndo = true;
@@ -369,7 +370,7 @@ void CellBuffer::GetCharRange(char *buffer, Sci::Position position, Sci::Positio
}
char CellBuffer::StyleAt(Sci::Position position) const {
- return style.ValueAt(position);
+ return hasStyles ? style.ValueAt(position) : 0;
}
void CellBuffer::GetStyleRange(unsigned char *buffer, Sci::Position position, Sci::Position lengthRetrieve) const {
@@ -377,6 +378,10 @@ void CellBuffer::GetStyleRange(unsigned char *buffer, Sci::Position position, Sc
return;
if (position < 0)
return;
+ if (!hasStyles) {
+ std::fill(buffer, buffer + lengthRetrieve, static_cast<unsigned char>(0));
+ return;
+ }
if ((position + lengthRetrieve) > style.Length()) {
Platform::DebugPrintf("Bad GetStyleRange %d for %d of %d\n", position,
lengthRetrieve, style.Length());
@@ -414,6 +419,9 @@ const char *CellBuffer::InsertString(Sci::Position position, const char *s, Sci:
}
bool CellBuffer::SetStyleAt(Sci::Position position, char styleValue) {
+ if (!hasStyles) {
+ return false;
+ }
const char curVal = style.ValueAt(position);
if (curVal != styleValue) {
style.SetValueAt(position, styleValue);
@@ -424,6 +432,9 @@ bool CellBuffer::SetStyleAt(Sci::Position position, char styleValue) {
}
bool CellBuffer::SetStyleFor(Sci::Position position, Sci::Position lengthStyle, char styleValue) {
+ if (!hasStyles) {
+ return false;
+ }
bool changed = false;
PLATFORM_ASSERT(lengthStyle == 0 ||
(lengthStyle > 0 && lengthStyle + position <= style.Length()));
@@ -462,7 +473,9 @@ Sci::Position CellBuffer::Length() const {
void CellBuffer::Allocate(Sci::Position newSize) {
substance.ReAllocate(newSize);
- style.ReAllocate(newSize);
+ if (hasStyles) {
+ style.ReAllocate(newSize);
+ }
}
void CellBuffer::SetLineEndTypes(int utf8LineEnds_) {
@@ -608,7 +621,9 @@ void CellBuffer::BasicInsertString(Sci::Position position, const char *s, Sci::P
}
substance.InsertFromArray(position, s, 0, insertLength);
- style.InsertValue(position, insertLength, 0);
+ if (hasStyles) {
+ style.InsertValue(position, insertLength, 0);
+ }
Sci::Line lineInsert = lv.LineFromPosition(position) + 1;
bool atLineStart = lv.LineStart(lineInsert-1) == position;
@@ -738,7 +753,9 @@ void CellBuffer::BasicDeleteChars(Sci::Position position, Sci::Position deleteLe
}
}
substance.DeleteRange(position, deleteLength);
- style.DeleteRange(position, deleteLength);
+ if (hasStyles) {
+ style.DeleteRange(position, deleteLength);
+ }
}
bool CellBuffer::SetUndoCollection(bool collectUndo) {
diff --git a/src/CellBuffer.h b/src/CellBuffer.h
index a12dc207f..7c999a36e 100644
--- a/src/CellBuffer.h
+++ b/src/CellBuffer.h
@@ -133,6 +133,7 @@ public:
*/
class CellBuffer {
private:
+ bool hasStyles;
SplitVector<char> substance;
SplitVector<char> style;
bool readOnly;
@@ -151,7 +152,7 @@ private:
public:
- CellBuffer();
+ CellBuffer(bool hasStyles_);
// Deleted so CellBuffer objects can not be copied.
CellBuffer(const CellBuffer &) = delete;
void operator=(const CellBuffer &) = delete;
diff --git a/src/Document.cxx b/src/Document.cxx
index 55ddc7588..a6f408f3e 100644
--- a/src/Document.cxx
+++ b/src/Document.cxx
@@ -90,7 +90,8 @@ int LexInterface::LineEndTypesSupported() {
return 0;
}
-Document::Document() {
+Document::Document(int options) :
+ cb((options & SC_DOCUMENTOPTION_STYLES_NONE) == 0) {
refCount = 0;
#ifdef _WIN32
eolMode = SC_EOL_CRLF;
diff --git a/src/Document.h b/src/Document.h
index 9f22f154a..bd956ccbf 100644
--- a/src/Document.h
+++ b/src/Document.h
@@ -265,7 +265,7 @@ public:
DecorationList decorations;
- Document();
+ Document(int options);
// Deleted so Document objects can not be copied.
Document(const Document &) = delete;
void operator=(const Document &) = delete;
diff --git a/src/EditModel.cxx b/src/EditModel.cxx
index 0e00bcfe0..08888ba38 100644
--- a/src/EditModel.cxx
+++ b/src/EditModel.cxx
@@ -69,7 +69,7 @@ EditModel::EditModel() {
hotspot = Range(Sci::invalidPosition);
hoverIndicatorPos = Sci::invalidPosition;
wrapWidth = LineLayout::wrapWidthInfinite;
- pdoc = new Document();
+ pdoc = new Document(SC_DOCUMENTOPTION_DEFAULT);
pdoc->AddRef();
}
diff --git a/src/Editor.cxx b/src/Editor.cxx
index 84ae3e318..b6e572c24 100644
--- a/src/Editor.cxx
+++ b/src/Editor.cxx
@@ -5162,7 +5162,7 @@ void Editor::SetDocPointer(Document *document) {
pdoc->RemoveWatcher(this, 0);
pdoc->Release();
if (document == NULL) {
- pdoc = new Document();
+ pdoc = new Document(SC_DOCUMENTOPTION_DEFAULT);
} else {
pdoc = document;
}
@@ -7554,7 +7554,7 @@ sptr_t Editor::WndProc(unsigned int iMessage, uptr_t wParam, sptr_t lParam) {
return 0;
case SCI_CREATEDOCUMENT: {
- Document *doc = new Document();
+ Document *doc = new Document(static_cast<int>(lParam));
doc->AddRef();
doc->Allocate(static_cast<int>(wParam));
return reinterpret_cast<sptr_t>(doc);
@@ -7569,7 +7569,7 @@ sptr_t Editor::WndProc(unsigned int iMessage, uptr_t wParam, sptr_t lParam) {
break;
case SCI_CREATELOADER: {
- Document *doc = new Document();
+ Document *doc = new Document(static_cast<int>(lParam));
doc->AddRef();
doc->Allocate(static_cast<int>(wParam));
doc->SetUndoCollection(false);
diff --git a/test/unit/testCellBuffer.cxx b/test/unit/testCellBuffer.cxx
index d71bab88d..0efe35014 100644
--- a/test/unit/testCellBuffer.cxx
+++ b/test/unit/testCellBuffer.cxx
@@ -25,7 +25,7 @@ TEST_CASE("CellBuffer") {
const char sText[] = "Scintilla";
const Sci::Position sLength = static_cast<Sci::Position>(strlen(sText));
- CellBuffer cb;
+ CellBuffer cb(true);
SECTION("InsertOneLine") {
bool startSequence = false;