From e3bbb7a3c92a659a7082bd38eb6786b5666acd78 Mon Sep 17 00:00:00 2001 From: Kovid Goyal Date: Sun, 20 Nov 2016 14:11:07 +0530 Subject: [PATCH] Move savepoints functions into screen.c --- kitty/data-types.h | 7 +++---- kitty/savepoints.c | 21 --------------------- kitty/screen.c | 13 +++++++++++++ 3 files changed, 16 insertions(+), 25 deletions(-) delete mode 100644 kitty/savepoints.c diff --git a/kitty/data-types.h b/kitty/data-types.h index 1f092cc67..9607eac77 100644 --- a/kitty/data-types.h +++ b/kitty/data-types.h @@ -221,6 +221,8 @@ typedef struct { } ScreenModes; PyTypeObject ScreenModes_Type; +#define SAVEPOINTS_SZ 256 + typedef struct { unsigned int current_charset; uint16_t *g0_charset, *g1_charset; @@ -231,13 +233,13 @@ typedef struct { } Savepoint; -#define SAVEPOINTS_SZ 256 typedef struct { Savepoint buf[SAVEPOINTS_SZ]; index_type start_of_data, count; } SavepointBuffer; + #define PARSER_BUF_SZ 8192 #define READ_BUF_SZ (1024*1024) @@ -277,7 +279,6 @@ Cursor* alloc_cursor(); LineBuf* alloc_linebuf(unsigned int, unsigned int); HistoryBuf* alloc_historybuf(unsigned int, unsigned int); ChangeTracker* alloc_change_tracker(unsigned int, unsigned int); -Savepoint* alloc_savepoint(); int init_LineBuf(PyObject *); int init_HistoryBuf(PyObject *); int init_Cursor(PyObject *); @@ -293,8 +294,6 @@ PyObject* parse_bytes_dump(PyObject UNUSED *, PyObject *); PyObject* parse_bytes(PyObject UNUSED *, PyObject *); 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 cursor_reset(Cursor*); Cursor* cursor_copy(Cursor*); void cursor_copy_to(Cursor *src, Cursor *dest); diff --git a/kitty/savepoints.c b/kitty/savepoints.c deleted file mode 100644 index 240983050..000000000 --- a/kitty/savepoints.c +++ /dev/null @@ -1,21 +0,0 @@ -/* - * savepoints.c - * Copyright (C) 2016 Kovid Goyal - * - * Distributed under terms of the GPL3 license. - */ - -#include "data-types.h" - -Savepoint* savepoints_push(SavepointBuffer *self) { - 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->count == 0) return NULL; - self->count--; - return self->buf + ((self->start_of_data + self->count) % SAVEPOINTS_SZ); -} diff --git a/kitty/screen.c b/kitty/screen.c index e29ccb318..e06082ba4 100644 --- a/kitty/screen.c +++ b/kitty/screen.c @@ -567,6 +567,19 @@ void screen_linefeed(Screen *self, uint8_t UNUSED ch) { screen_ensure_bounds(self, false); } +static inline Savepoint* savepoints_push(SavepointBuffer *self) { + 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; +} + +static inline Savepoint* savepoints_pop(SavepointBuffer *self) { + if (self->count == 0) return NULL; + self->count--; + return self->buf + ((self->start_of_data + self->count) % SAVEPOINTS_SZ); +} + void screen_save_cursor(Screen *self) { SavepointBuffer *pts = self->linebuf == self->main_linebuf ? &self->main_savepoints : &self->alt_savepoints; Savepoint *sp = savepoints_push(pts);