diff options
author | Neil <nyamatongwe@gmail.com> | 2019-05-02 14:14:08 +1000 |
---|---|---|
committer | Neil <nyamatongwe@gmail.com> | 2019-05-02 14:14:08 +1000 |
commit | fd00af6bd9cb38ab9719bce0c1360c395c026a8d (patch) | |
tree | 57691e97c9f237898f5a10a4ede135a29d7b88b4 | |
parent | e703a397f626208f54703d8af54f31f21c88259d (diff) | |
download | scintilla-mirror-fd00af6bd9cb38ab9719bce0c1360c395c026a8d.tar.gz |
Optimize SCI_GETTEXT by calling Document::GetCharRange instead of looping for
each byte.
-rw-r--r-- | src/Editor.cxx | 9 | ||||
-rw-r--r-- | test/simpleTests.py | 7 |
2 files changed, 10 insertions, 6 deletions
diff --git a/src/Editor.cxx b/src/Editor.cxx index 352a133ae..42b71e3c8 100644 --- a/src/Editor.cxx +++ b/src/Editor.cxx @@ -5796,11 +5796,10 @@ sptr_t Editor::WndProc(unsigned int iMessage, uptr_t wParam, sptr_t lParam) { if (wParam == 0) return 0; char *ptr = CharPtrFromSPtr(lParam); - size_t iChar = 0; - for (; iChar < wParam - 1; iChar++) - ptr[iChar] = pdoc->CharAt(iChar); - ptr[iChar] = '\0'; - return iChar; + const Sci_Position len = wParam - 1; + pdoc->GetCharRange(ptr, 0, len); + ptr[len] = '\0'; + return len; } case SCI_SETTEXT: { diff --git a/test/simpleTests.py b/test/simpleTests.py index 9a170a2f9..e4512b617 100644 --- a/test/simpleTests.py +++ b/test/simpleTests.py @@ -540,9 +540,14 @@ class TestSimple(unittest.TestCase): def testGetSet(self): self.ed.SetContents(b"abc") self.assertEquals(self.ed.TextLength, 3) - result = ctypes.create_string_buffer(b"\0" * 5) + # String buffer containing exactly 5 digits + result = ctypes.create_string_buffer(b"12345", 5) + self.assertEquals(result.raw, b"12345") length = self.ed.GetText(4, result) + self.assertEquals(length, 3) self.assertEquals(result.value, b"abc") + # GetText has written the 3 bytes of text and a terminating NUL but left the final digit 5 + self.assertEquals(result.raw, b"abc\x005") def testAppend(self): self.ed.SetContents(b"abc") |