1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
|
# HG changeset patch
# User Neil <nyamatongwe@gmail.com>
# Date 1517542495 -39600
# Node ID 431b814a54a62d81c8069655bbbebec7bda782e3
# Parent 44ff2195a2026367e556e7dd9ef83af81a07219e
Implement SC_DOCUMENTOPTION_STYLES_NONE.
diff -r 44ff2195a202 -r 431b814a54a6 doc/ScintillaDoc.html
--- a/doc/ScintillaDoc.html Fri Feb 02 08:37:32 2018 +1100
+++ b/doc/ScintillaDoc.html Fri Feb 02 14:34:55 2018 +1100
@@ -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 @@
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(<unused>, 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 @@
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 -r 44ff2195a202 -r 431b814a54a6 doc/ScintillaHistory.html
--- a/doc/ScintillaHistory.html Fri Feb 02 08:37:32 2018 +1100
+++ b/doc/ScintillaHistory.html Fri Feb 02 14:34:55 2018 +1100
@@ -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 -r 44ff2195a202 -r 431b814a54a6 include/Scintilla.h
--- a/include/Scintilla.h Fri Feb 02 08:37:32 2018 +1100
+++ b/include/Scintilla.h Fri Feb 02 14:34:55 2018 +1100
@@ -690,6 +690,7 @@
#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 -r 44ff2195a202 -r 431b814a54a6 include/Scintilla.iface
--- a/include/Scintilla.iface Fri Feb 02 08:37:32 2018 +1100
+++ b/include/Scintilla.iface Fri Feb 02 14:34:55 2018 +1100
@@ -1773,6 +1773,7 @@
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 -r 44ff2195a202 -r 431b814a54a6 qt/ScintillaEdit/ScintillaDocument.cpp
--- a/qt/ScintillaEdit/ScintillaDocument.cpp Fri Feb 02 08:37:32 2018 +1100
+++ b/qt/ScintillaEdit/ScintillaDocument.cpp Fri Feb 02 14:34:55 2018 +1100
@@ -91,7 +91,7 @@
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 -r 44ff2195a202 -r 431b814a54a6 src/CellBuffer.cxx
--- a/src/CellBuffer.cxx Fri Feb 02 08:37:32 2018 +1100
+++ b/src/CellBuffer.cxx Fri Feb 02 14:34:55 2018 +1100
@@ -342,7 +342,8 @@
currentAction++;
}
-CellBuffer::CellBuffer() {
+CellBuffer::CellBuffer(bool hasStyles_) :
+ hasStyles(hasStyles_) {
readOnly = false;
utf8LineEnds = 0;
collectingUndo = true;
@@ -369,7 +370,7 @@
}
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 @@
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 @@
}
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::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 @@
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 @@
}
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 @@
}
}
substance.DeleteRange(position, deleteLength);
- style.DeleteRange(position, deleteLength);
+ if (hasStyles) {
+ style.DeleteRange(position, deleteLength);
+ }
}
bool CellBuffer::SetUndoCollection(bool collectUndo) {
diff -r 44ff2195a202 -r 431b814a54a6 src/CellBuffer.h
--- a/src/CellBuffer.h Fri Feb 02 08:37:32 2018 +1100
+++ b/src/CellBuffer.h Fri Feb 02 14:34:55 2018 +1100
@@ -133,6 +133,7 @@
*/
class CellBuffer {
private:
+ bool hasStyles;
SplitVector<char> substance;
SplitVector<char> style;
bool readOnly;
@@ -151,7 +152,7 @@
public:
- CellBuffer();
+ CellBuffer(bool hasStyles_);
~CellBuffer();
/// Retrieving positions outside the range of the buffer works and returns 0
diff -r 44ff2195a202 -r 431b814a54a6 src/Document.cxx
--- a/src/Document.cxx Fri Feb 02 08:37:32 2018 +1100
+++ b/src/Document.cxx Fri Feb 02 14:34:55 2018 +1100
@@ -90,7 +90,8 @@
return 0;
}
-Document::Document() {
+Document::Document(int options) :
+ cb((options & SC_DOCUMENTOPTION_STYLES_NONE) == 0) {
refCount = 0;
#ifdef _WIN32
eolMode = SC_EOL_CRLF;
diff -r 44ff2195a202 -r 431b814a54a6 src/Document.h
--- a/src/Document.h Fri Feb 02 08:37:32 2018 +1100
+++ b/src/Document.h Fri Feb 02 14:34:55 2018 +1100
@@ -265,7 +265,7 @@
DecorationList decorations;
- Document();
+ Document(int options);
virtual ~Document();
int AddRef();
diff -r 44ff2195a202 -r 431b814a54a6 src/EditModel.cxx
--- a/src/EditModel.cxx Fri Feb 02 08:37:32 2018 +1100
+++ b/src/EditModel.cxx Fri Feb 02 14:34:55 2018 +1100
@@ -69,7 +69,7 @@
hotspot = Range(Sci::invalidPosition);
hoverIndicatorPos = Sci::invalidPosition;
wrapWidth = LineLayout::wrapWidthInfinite;
- pdoc = new Document();
+ pdoc = new Document(SC_DOCUMENTOPTION_DEFAULT);
pdoc->AddRef();
}
diff -r 44ff2195a202 -r 431b814a54a6 src/Editor.cxx
--- a/src/Editor.cxx Fri Feb 02 08:37:32 2018 +1100
+++ b/src/Editor.cxx Fri Feb 02 14:34:55 2018 +1100
@@ -5162,7 +5162,7 @@
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 @@
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 @@
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 -r 44ff2195a202 -r 431b814a54a6 test/unit/testCellBuffer.cxx
--- a/test/unit/testCellBuffer.cxx Fri Feb 02 08:37:32 2018 +1100
+++ b/test/unit/testCellBuffer.cxx Fri Feb 02 14:34:55 2018 +1100
@@ -25,7 +25,7 @@
const char sText[] = "Scintilla";
const Sci::Position sLength = static_cast<Sci::Position>(strlen(sText));
- CellBuffer cb;
+ CellBuffer cb(true);
SECTION("InsertOneLine") {
bool startSequence = false;
|