am 2ed52f95: Merge "Add uint reading method to BufferWithExtendableBuffer."
* commit '2ed52f95e7679388c0ce3a51d660149aa601fa77': Add uint reading method to BufferWithExtendableBuffer.main
commit
94130d0234
|
@ -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.
|
// TODO: Needs to allocate larger memory corresponding to the current vector size.
|
||||||
const size_t BufferWithExtendableBuffer::EXTEND_ADDITIONAL_BUFFER_SIZE_STEP = 128 * 1024;
|
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,
|
bool BufferWithExtendableBuffer::writeUintAndAdvancePosition(const uint32_t data, const int size,
|
||||||
int *const pos) {
|
int *const pos) {
|
||||||
if (!(size >= 1 && size <= 4)) {
|
if (!(size >= 1 && size <= 4)) {
|
||||||
|
|
|
@ -71,6 +71,8 @@ class BufferWithExtendableBuffer {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
uint32_t readUintAndAdvancePosition(const int size, int *const pos) const;
|
||||||
|
|
||||||
AK_FORCE_INLINE int getOriginalBufferSize() const {
|
AK_FORCE_INLINE int getOriginalBufferSize() const {
|
||||||
return mOriginalBufferSize;
|
return mOriginalBufferSize;
|
||||||
}
|
}
|
||||||
|
|
|
@ -114,6 +114,24 @@ class ByteArrayUtils {
|
||||||
return buffer[(*pos)++];
|
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
|
* Code Point Reading
|
||||||
*
|
*
|
||||||
|
|
Loading…
Reference in New Issue