diff options
author | nyamatongwe <devnull@localhost> | 2000-04-05 00:43:35 +0000 |
---|---|---|
committer | nyamatongwe <devnull@localhost> | 2000-04-05 00:43:35 +0000 |
commit | 79f23a6ce721bbf1f4ae89d0f2bc86d83fbe52b7 (patch) | |
tree | f7f0730f68c2c83f2c8eab420cfe3c0e81be6188 | |
parent | 78562c158305d7d238cb12ba4cd186517364b6d9 (diff) | |
download | scintilla-mirror-79f23a6ce721bbf1f4ae89d0f2bc86d83fbe52b7.tar.gz |
Moved performance critical functionality back up into Accessor from
sub classes.
-rw-r--r-- | include/Accessor.h | 39 | ||||
-rw-r--r-- | include/WindowAccessor.h | 31 | ||||
-rw-r--r-- | src/DocumentAccessor.cxx | 2 | ||||
-rw-r--r-- | src/DocumentAccessor.h | 31 | ||||
-rw-r--r-- | src/WindowAccessor.cxx | 2 |
5 files changed, 39 insertions, 66 deletions
diff --git a/include/Accessor.h b/include/Accessor.h index b420397e2..aa3ba8e3b 100644 --- a/include/Accessor.h +++ b/include/Accessor.h @@ -11,11 +11,42 @@ typedef bool (*PFNIsCommentLeader)(Accessor &styler, int pos, int len); // Interface to data in a Scintilla class Accessor { +protected: + enum {extremePosition=0x7FFFFFFF}; + // bufferSize is a trade off between time taken to copy the characters and retrieval overhead + // slopSize positions the buffer before the desired position in case there is some backtracking + enum {bufferSize=4000, slopSize=bufferSize/8}; + char buf[bufferSize+1]; + int startPos; + int endPos; + int codePage; + + virtual bool InternalIsLeadByte(char ch)=0; + virtual void Fill(int position)=0; public: - virtual void SetCodePage(int codePage_)=0; - virtual char operator[](int position)=0; - virtual char SafeGetCharAt(int position, char chDefault=' ')=0; - virtual bool IsLeadByte(char ch)=0; + Accessor() : startPos(extremePosition), endPos(0), codePage(0) { } + char operator[](int position) { + if (position < startPos || position >= endPos) { + Fill(position); + } + return buf[position - startPos]; + } + char SafeGetCharAt(int position, char chDefault=' ') { + // Safe version of operator[], returning a defined value for invalid position + if (position < startPos || position >= endPos) { + Fill(position); + if (position < startPos || position >= endPos) { + // Position is outside range of document + return chDefault; + } + } + return buf[position - startPos]; + } + bool IsLeadByte(char ch) { + return codePage && InternalIsLeadByte(ch); + } + void SetCodePage(int codePage_) { codePage = codePage_; } + virtual char StyleAt(int position)=0; virtual int GetLine(int position)=0; virtual int LineStart(int line)=0; diff --git a/include/WindowAccessor.h b/include/WindowAccessor.h index a24ef9fa3..9f1750d52 100644 --- a/include/WindowAccessor.h +++ b/include/WindowAccessor.h @@ -4,16 +4,9 @@ class WindowAccessor : public Accessor { protected: - // bufferSize is a trade off between time taken to copy the characters and SendMessage overhead - // slopSize positions the buffer before the desired position in case there is some backtracking - enum {bufferSize=4000, slopSize=bufferSize/8}; - char buf[bufferSize+1]; WindowID id; PropSet &props; - int startPos; - int endPos; int lenDoc; - int codePage; char styleBuf[bufferSize]; int validLen; @@ -25,29 +18,7 @@ protected: void Fill(int position); public: WindowAccessor(WindowID id_, PropSet &props_) : - id(id_), props(props_), startPos(0x7FFFFFFF), endPos(0), - lenDoc(-1), codePage(0), validLen(0), chFlags(0) { - } - void SetCodePage(int codePage_) { codePage = codePage_; } - char operator[](int position) { - if (position < startPos || position >= endPos) { - Fill(position); - } - return buf[position - startPos]; - } - char SafeGetCharAt(int position, char chDefault=' ') { - // Safe version of operator[], returning a defined value for invalid position - if (position < startPos || position >= endPos) { - Fill(position); - if (position < startPos || position >= endPos) { - // Position is outside range of document - return chDefault; - } - } - return buf[position - startPos]; - } - bool IsLeadByte(char ch) { - return codePage && InternalIsLeadByte(ch); + id(id_), props(props_), lenDoc(-1), validLen(0), chFlags(0) { } char StyleAt(int position); int GetLine(int position); diff --git a/src/DocumentAccessor.cxx b/src/DocumentAccessor.cxx index a69f4a445..dd156fa24 100644 --- a/src/DocumentAccessor.cxx +++ b/src/DocumentAccessor.cxx @@ -111,7 +111,7 @@ void DocumentAccessor::SetLevel(int line, int level) { } void DocumentAccessor::Flush() { - startPos = 0x7FFFFFFF; + startPos = extremePosition; lenDoc = -1; if (validLen > 0) { pdoc->SetStyles(validLen, styleBuf); diff --git a/src/DocumentAccessor.h b/src/DocumentAccessor.h index f0577b355..18eff84be 100644 --- a/src/DocumentAccessor.h +++ b/src/DocumentAccessor.h @@ -6,16 +6,9 @@ class Document; class DocumentAccessor : public Accessor { protected: - // bufferSize is a trade off between time taken to copy the characters and SendMessage overhead - // slopSize positions the buffer before the desired position in case there is some backtracking - enum {bufferSize=4000, slopSize=bufferSize/8}; - char buf[bufferSize+1]; Document *pdoc; PropSet &props; - int startPos; - int endPos; int lenDoc; - int codePage; char styleBuf[bufferSize]; int validLen; @@ -27,29 +20,7 @@ protected: void Fill(int position); public: DocumentAccessor(Document *pdoc_, PropSet &props_) : - pdoc(pdoc_), props(props_), startPos(0x7FFFFFFF), endPos(0), - lenDoc(-1), codePage(0), validLen(0), chFlags(0) { - } - void SetCodePage(int codePage_) { codePage = codePage_; } - char operator[](int position) { - if (position < startPos || position >= endPos) { - Fill(position); - } - return buf[position - startPos]; - } - char SafeGetCharAt(int position, char chDefault=' ') { - // Safe version of operator[], returning a defined value for invalid position - if (position < startPos || position >= endPos) { - Fill(position); - if (position < startPos || position >= endPos) { - // Position is outside range of document - return chDefault; - } - } - return buf[position - startPos]; - } - bool IsLeadByte(char ch) { - return codePage && InternalIsLeadByte(ch); + pdoc(pdoc_), props(props_), lenDoc(-1), validLen(0), chFlags(0) { } char StyleAt(int position); int GetLine(int position); diff --git a/src/WindowAccessor.cxx b/src/WindowAccessor.cxx index 0c33acd88..d04c0142d 100644 --- a/src/WindowAccessor.cxx +++ b/src/WindowAccessor.cxx @@ -109,7 +109,7 @@ void WindowAccessor::SetLevel(int line, int level) { } void WindowAccessor::Flush() { - startPos = 0x7FFFFFFF; + startPos = extremePosition; lenDoc = -1; if (validLen > 0) { Platform::SendScintilla(id, SCI_SETSTYLINGEX, validLen, |