diff options
author | nyamatongwe <devnull@localhost> | 2010-09-24 15:25:26 +1000 |
---|---|---|
committer | nyamatongwe <devnull@localhost> | 2010-09-24 15:25:26 +1000 |
commit | b458c22e5421f4d0fd23cdf14c072d132a820937 (patch) | |
tree | aeb0fa1003068edab5071cfeec8e88ca5e3c5ba5 | |
parent | 27fe93c781719be46a2ca770f33f9cfba9cb054c (diff) | |
download | scintilla-mirror-b458c22e5421f4d0fd23cdf14c072d132a820937.tar.gz |
Added GetRange method to SplitVector as fast way to retrieve elements.
-rw-r--r-- | src/CellBuffer.cxx | 5 | ||||
-rw-r--r-- | src/SplitVector.h | 17 |
2 files changed, 18 insertions, 4 deletions
diff --git a/src/CellBuffer.cxx b/src/CellBuffer.cxx index 064ef1a2a..de1605837 100644 --- a/src/CellBuffer.cxx +++ b/src/CellBuffer.cxx @@ -351,10 +351,7 @@ void CellBuffer::GetCharRange(char *buffer, int position, int lengthRetrieve) co lengthRetrieve, substance.Length()); return; } - - for (int i=0; i<lengthRetrieve; i++) { - *buffer++ = substance.ValueAt(position + i); - } + substance.GetRange(buffer, position, lengthRetrieve); } char CellBuffer::StyleAt(int position) const { diff --git a/src/SplitVector.h b/src/SplitVector.h index 2c5c7a1d0..2e17ba3dc 100644 --- a/src/SplitVector.h +++ b/src/SplitVector.h @@ -238,6 +238,23 @@ public: DeleteRange(0, lengthBody); } + // Retrieve a range of elemetns into an array + void GetRange(T *buffer, int position, int retrieveLength) const { + // Split into up to 2 ranges, before and after the split then use memcpy on each. + int range1Length = 0; + if (position < part1Length) { + int part1AfterPosition = part1Length - position; + range1Length = retrieveLength; + if (range1Length > part1AfterPosition) + range1Length = part1AfterPosition; + } + memcpy(buffer, body + position, range1Length * sizeof(T)); + buffer += range1Length; + position = position + range1Length + gapLength; + int range2Length = retrieveLength - range1Length; + memcpy(buffer, body + position, range2Length * sizeof(T)); + } + T *BufferPointer() { RoomFor(1); GapTo(lengthBody); |