Merge "Add uint reading method to BufferWithExtendableBuffer."

This commit is contained in:
Keisuke Kuroyanagi 2013-10-29 04:42:08 +00:00 committed by Android (Google) Code Review
commit 2ed52f95e7
3 changed files with 34 additions and 0 deletions

View file

@ -23,6 +23,20 @@ const int BufferWithExtendableBuffer::NEAR_BUFFER_LIMIT_THRESHOLD_PERCENTILE = 9
// TODO: Needs to allocate larger memory corresponding to the current vector size.
const size_t BufferWithExtendableBuffer::EXTEND_ADDITIONAL_BUFFER_SIZE_STEP = 128 * 1024;
uint32_t BufferWithExtendableBuffer::readUintAndAdvancePosition(const int size,
int *const pos) const {
const bool readingPosIsInAdditionalBuffer = isInAdditionalBuffer(*pos);
if (readingPosIsInAdditionalBuffer) {
*pos -= mOriginalBufferSize;
}
const int value = ByteArrayUtils::readUintAndAdvancePosition(
getBuffer(readingPosIsInAdditionalBuffer), size, pos);
if (readingPosIsInAdditionalBuffer) {
*pos += mOriginalBufferSize;
}
return value;
}
bool BufferWithExtendableBuffer::writeUintAndAdvancePosition(const uint32_t data, const int size,
int *const pos) {
if (!(size >= 1 && size <= 4)) {

View file

@ -71,6 +71,8 @@ class BufferWithExtendableBuffer {
}
}
uint32_t readUintAndAdvancePosition(const int size, int *const pos) const;
AK_FORCE_INLINE int getOriginalBufferSize() const {
return mOriginalBufferSize;
}

View file

@ -114,6 +114,24 @@ class ByteArrayUtils {
return buffer[(*pos)++];
}
static AK_FORCE_INLINE int readUintAndAdvancePosition(const uint8_t *const buffer,
const int size, int *const pos) {
// size must be in 1 to 4.
ASSERT(size >= 1 && size <= 4);
switch (size) {
case 1:
return ByteArrayUtils::readUint8AndAdvancePosition(buffer, pos);
case 2:
return ByteArrayUtils::readUint16AndAdvancePosition(buffer, pos);
case 3:
return ByteArrayUtils::readUint24AndAdvancePosition(buffer, pos);
case 4:
return ByteArrayUtils::readUint32AndAdvancePosition(buffer, pos);
default:
return 0;
}
}
/**
* Code Point Reading
*