Major changes to api and structure.
- Remove newline caching - limit petal sizes - make public facing api use points only - fix iterators (chunk & line)
This commit is contained in:
@@ -1,12 +1,12 @@
|
||||
#include "vase/iterators/line.h"
|
||||
|
||||
LineIterator::LineIterator(Shard *r, uint32_t start_line)
|
||||
: offset(offset_of(r, start_line, 0)), it(r, offset) {}
|
||||
|
||||
LineIterator::~LineIterator() {};
|
||||
LineIterator::LineIterator(Shard *r, uint32_t start_line) : it(r) {
|
||||
it.seek_line(start_line);
|
||||
}
|
||||
|
||||
bool LineIterator::next(std::string &line) {
|
||||
line.clear();
|
||||
line_offset = it.byte_offset() - remaining;
|
||||
while (true) {
|
||||
if (remaining == 0) {
|
||||
uint32_t got;
|
||||
@@ -14,12 +14,15 @@ bool LineIterator::next(std::string &line) {
|
||||
eof = true;
|
||||
break;
|
||||
}
|
||||
line_offset = it.byte_offset() - remaining;
|
||||
remaining = got;
|
||||
}
|
||||
const char *nl = (const char *)memchr(cursor, '\n', remaining);
|
||||
if (nl) {
|
||||
const char *end = nl;
|
||||
size_t len = end - cursor;
|
||||
uint32_t len = nl - cursor;
|
||||
if (len && cursor[len - 1] == '\r')
|
||||
--len;
|
||||
line.append(cursor, len);
|
||||
cursor = end + 1;
|
||||
remaining -= (uint32_t)(len + 1);
|
||||
@@ -31,3 +34,7 @@ bool LineIterator::next(std::string &line) {
|
||||
}
|
||||
return !line.empty();
|
||||
}
|
||||
|
||||
uint32_t LineIterator::byte_offset() {
|
||||
return line_offset;
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user