Perfect
- Make original buffer use a disk backed mapping to save memory. - rearrange api function headers for search etc. - fix bugs with iterators. - support uint64_t for all byte and line offsets to allow for much larger files to be opened. - and more minor bug fixes.
This commit is contained in:
@@ -10,7 +10,7 @@ AppendBuffer::~AppendBuffer() {
|
||||
free(p);
|
||||
}
|
||||
|
||||
uint32_t AppendBuffer::key(char c) {
|
||||
uint64_t AppendBuffer::append(char c) {
|
||||
if (t_offset == APPEND_CHUNK_SIZE) {
|
||||
t_current = (TChunk *)malloc(sizeof(TChunk));
|
||||
buf.push_back(t_current);
|
||||
@@ -20,15 +20,15 @@ uint32_t AppendBuffer::key(char c) {
|
||||
return current_offset++;
|
||||
}
|
||||
|
||||
uint32_t AppendBuffer::append(const char *text, uint32_t length) {
|
||||
uint32_t start = current_offset;
|
||||
uint64_t AppendBuffer::append(const char *text, uint64_t length) {
|
||||
uint64_t start = current_offset;
|
||||
while (length > 0) {
|
||||
if (t_offset == APPEND_CHUNK_SIZE) {
|
||||
t_current = (TChunk *)malloc(sizeof(TChunk));
|
||||
buf.push_back(t_current);
|
||||
t_offset = 0;
|
||||
}
|
||||
uint32_t copy = std::min(length, APPEND_CHUNK_SIZE - t_offset);
|
||||
uint64_t copy = std::min(length, APPEND_CHUNK_SIZE - t_offset);
|
||||
memcpy((*t_current) + t_offset, text, copy);
|
||||
t_offset += copy;
|
||||
current_offset += copy;
|
||||
@@ -38,18 +38,18 @@ uint32_t AppendBuffer::append(const char *text, uint32_t length) {
|
||||
return start;
|
||||
}
|
||||
|
||||
const char *AppendBuffer::read(uint32_t pos, uint32_t *out_len) {
|
||||
const char *AppendBuffer::read(uint64_t pos, uint64_t *out_len) {
|
||||
if (pos >= current_offset)
|
||||
return nullptr;
|
||||
uint32_t local_offset = pos % APPEND_CHUNK_SIZE;
|
||||
uint64_t local_offset = pos % APPEND_CHUNK_SIZE;
|
||||
if (out_len) {
|
||||
uint32_t remaining = current_offset - pos;
|
||||
uint32_t until_chunk_end = APPEND_CHUNK_SIZE - local_offset;
|
||||
uint64_t remaining = current_offset - pos;
|
||||
uint64_t until_chunk_end = APPEND_CHUNK_SIZE - local_offset;
|
||||
*out_len = std::min(remaining, until_chunk_end);
|
||||
}
|
||||
return &(*buf[pos / APPEND_CHUNK_SIZE])[local_offset];
|
||||
}
|
||||
|
||||
inline uint32_t AppendBuffer::length() {
|
||||
inline uint64_t AppendBuffer::length() {
|
||||
return current_offset;
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user