Simplify SavepointBuffer implementation
This commit is contained in:
parent
91a68f0089
commit
46ec0d4e9c
@ -235,8 +235,7 @@ typedef struct {
|
||||
|
||||
typedef struct {
|
||||
Savepoint buf[SAVEPOINTS_SZ];
|
||||
Savepoint *start_of_data;
|
||||
Savepoint *end_of_data;
|
||||
index_type start_of_data, count;
|
||||
} SavepointBuffer;
|
||||
|
||||
#define PARSER_BUF_SZ 8192
|
||||
@ -296,7 +295,6 @@ uint16_t* translation_table(char);
|
||||
uint32_t decode_utf8(uint32_t*, uint32_t*, uint8_t byte);
|
||||
Savepoint* savepoints_pop(SavepointBuffer *);
|
||||
Savepoint* savepoints_push(SavepointBuffer *);
|
||||
void savepoints_init(SavepointBuffer *);
|
||||
void cursor_reset(Cursor*);
|
||||
Cursor* cursor_copy(Cursor*);
|
||||
void cursor_copy_to(Cursor *src, Cursor *dest);
|
||||
|
||||
@ -7,26 +7,15 @@
|
||||
|
||||
#include "data-types.h"
|
||||
|
||||
#define ADVANCE(x) \
|
||||
self->x = (self->x >= self->buf + SAVEPOINTS_SZ - 1) ? self->buf : self->x + 1;
|
||||
|
||||
#define RETREAT(x) \
|
||||
self->x = self->x == self->buf ? self->buf + SAVEPOINTS_SZ - 1 : self->x - 1;
|
||||
|
||||
Savepoint* savepoints_push(SavepointBuffer *self) {
|
||||
Savepoint *ans = self->end_of_data;
|
||||
ADVANCE(end_of_data);
|
||||
if (self->end_of_data == self->start_of_data) ADVANCE(start_of_data);
|
||||
Savepoint *ans = self->buf + ((self->start_of_data + self->count) % SAVEPOINTS_SZ);
|
||||
if (self->count == SAVEPOINTS_SZ) self->start_of_data = (self->start_of_data + 1) % SAVEPOINTS_SZ;
|
||||
else self->count++;
|
||||
return ans;
|
||||
}
|
||||
|
||||
Savepoint* savepoints_pop(SavepointBuffer *self) {
|
||||
if (self->start_of_data == self->end_of_data) return NULL;
|
||||
RETREAT(end_of_data);
|
||||
return self->end_of_data;
|
||||
}
|
||||
|
||||
void savepoints_init(SavepointBuffer *self) {
|
||||
self->end_of_data = self->buf;
|
||||
self->start_of_data = self->buf;
|
||||
if (self->count == 0) return NULL;
|
||||
self->count--;
|
||||
return self->buf + ((self->start_of_data + self->count) % SAVEPOINTS_SZ);
|
||||
}
|
||||
|
||||
@ -39,7 +39,6 @@ new(PyTypeObject *type, PyObject *args, PyObject UNUSED *kwds) {
|
||||
if (self->cursor == NULL || self->main_linebuf == NULL || self->alt_linebuf == NULL || self->change_tracker == NULL || self->tabstops == NULL) {
|
||||
Py_CLEAR(self); return NULL;
|
||||
}
|
||||
savepoints_init(&self->main_savepoints); savepoints_init(&self->alt_savepoints);
|
||||
}
|
||||
return (PyObject*) self;
|
||||
}
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user