diff options
author | Andreas Kling <andreas.kling@nokia.com> | 2010-06-17 00:17:32 +0200 |
---|---|---|
committer | Andreas Kling <andreas.kling@nokia.com> | 2010-06-17 01:50:29 +0200 |
commit | b768d155c5b40c66f7b83ca5e52ad6dda78c2fe8 (patch) | |
tree | b9d0e0f43b9091cb7031fd10ce28f825b23b8b6e /src/corelib/io/qiodevice_p.h | |
parent | 6dffaee6ab0bbeddd9e0cb16ff4545c3cb09bfe9 (diff) |
Implement QIODevice::peek() using read() + ungetBlock().
The previous implementation was doing ungetChar() in a loop.
Task-number: QTBUG-9654
Reviewed-by: João Abecasis <joao.abecasis@nokia.com>
Reviewed-by: mread
Diffstat (limited to 'src/corelib/io/qiodevice_p.h')
-rw-r--r-- | src/corelib/io/qiodevice_p.h | 9 |
1 files changed, 9 insertions, 0 deletions
diff --git a/src/corelib/io/qiodevice_p.h b/src/corelib/io/qiodevice_p.h index 94dadca76d..225a0b90a2 100644 --- a/src/corelib/io/qiodevice_p.h +++ b/src/corelib/io/qiodevice_p.h @@ -151,6 +151,15 @@ public: len++; *first = c; } + void ungetBlock(const char* block, int size) { + if ((first - buf) < size) { + // underflow, the existing valid data needs to move to the end of the (potentially bigger) buffer + makeSpace(len + size, freeSpaceAtStart); + memcpy(first - size, block, size); + } + first -= size; + len += size; + } private: enum FreeSpacePos {freeSpaceAtStart, freeSpaceAtEnd}; |