[vte] Abstract rowdata functions away from GArray
- From: Behdad Esfahbod <behdad src gnome org>
- To: svn-commits-list gnome org
- Cc:
- Subject: [vte] Abstract rowdata functions away from GArray
- Date: Thu, 27 Aug 2009 17:45:05 +0000 (UTC)
commit d3f87acad23aa0b50f2d15756ccd12e173ddbcf7
Author: Behdad Esfahbod <behdad behdad org>
Date: Wed Aug 26 01:06:27 2009 -0400
Abstract rowdata functions away from GArray
src/ring.c | 17 +++---
src/ring.h | 31 ++++++++++-
src/vte.c | 171 +++++++++++++++++++++++++---------------------------------
src/vteseq.c | 146 ++++++++++++++-----------------------------------
4 files changed, 153 insertions(+), 212 deletions(-)
---
diff --git a/src/ring.c b/src/ring.c
index 5793e6c..a145739 100644
--- a/src/ring.c
+++ b/src/ring.c
@@ -25,14 +25,13 @@
#include "debug.h"
#include "ring.h"
-
static VteRowData *
_vte_row_data_init (VteRowData *row)
{
- if (row->cells)
- g_array_set_size (row->cells, 0);
+ if (row->_cells)
+ g_array_set_size (row->_cells, 0);
else
- row->cells = g_array_new(FALSE, TRUE, sizeof(struct vte_charcell));
+ row->_cells = g_array_new(FALSE, TRUE, sizeof(struct vte_charcell));
row->soft_wrapped = 0;
return row;
}
@@ -40,9 +39,9 @@ _vte_row_data_init (VteRowData *row)
static void
_vte_row_data_fini (VteRowData *row)
{
- if (row->cells)
- g_array_free(row->cells, TRUE);
- row->cells = NULL;
+ if (row->_cells)
+ g_array_free(row->_cells, TRUE);
+ row->_cells = NULL;
}
static void
@@ -50,7 +49,7 @@ _vte_ring_move (VteRing *ring, unsigned int to, unsigned int from)
{
_vte_row_data_fini (&ring->array[to]);
ring->array[to] = ring->array[from];
- ring->array[from].cells = NULL;
+ ring->array[from]._cells = NULL;
}
@@ -67,7 +66,7 @@ _vte_ring_validate (VteRing * ring)
max = ring->delta + ring->length;
for (i = ring->delta; i < max; i++) {
g_assert(_vte_ring_contains(ring, i));
- g_assert(_vte_ring_index(ring, i)->cells != NULL);
+ g_assert(_vte_ring_index(ring, i)->_cells != NULL);
}
}
#else
diff --git a/src/ring.h b/src/ring.h
index ac96d86..1d45b9c 100644
--- a/src/ring.h
+++ b/src/ring.h
@@ -63,10 +63,39 @@ struct vte_charcell {
};
typedef struct _VteRowData {
- GArray *cells;
+ GArray *_cells;
guchar soft_wrapped: 1;
} VteRowData;
+
+#define _vte_row_data_get(__row, __col) ((const struct vte_charcell *) _vte_row_data_get_writable (__row, __col))
+#define _vte_row_data_get_writable(__row, __col) (G_UNLIKELY ((__row)->_cells->len <= (unsigned int) __col) ? NULL : \
+ &g_array_index (__row->_cells, struct vte_charcell, __col))
+#define _vte_row_data_length(__row) ((__row)->_cells->len + 0)
+#define _vte_row_data_insert(__row, __pos, __cell) g_array_insert_val ((__row)->_cells, __pos, *(__cell))
+#define _vte_row_data_append(__row, __cell) g_array_append_val ((__row)->_cells, *(__cell))
+#define _vte_row_data_remove(__row, __col) g_array_remove_index ((__row)->_cells, __col)
+#define _vte_row_data_fill(__row, __cell, __len) G_STMT_START { \
+ int __i = (__len) - (__row)->_cells->len; \
+ while (__i-- > 0) \
+ _vte_row_data_append (__row, __cell); \
+ } G_STMT_END
+
+#define _vte_row_data_set_length(__row, __len) g_array_set_size ((__row)->_cells, __len)
+
+#if 0
+const struct vte_charcell *_vte_row_data_get (VteRowData *row, unsigned int col);
+struct vte_charcell *_vte_row_data_get_writable (VteRowData *row, unsigned int col);
+unsigned int _vte_row_data_length (VteRowData *row);
+void _vte_row_data_insert (VteRowData *row, int pos, const struct vte_charcell *cell);
+void _vte_row_data_append (VteRowData *row, const struct vte_charcell *cell);
+void _vte_row_data_remove (VteRowData *row, unsigned int col);
+void _vte_row_data_fill (VteRowData *row, const struct vte_charcell *cell, int len);
+void _vte_row_data_set_length (VteRowData *row, int len);
+#endif
+
+
+
typedef struct _VteRing VteRing;
struct _VteRing {
diff --git a/src/vte.c b/src/vte.c
index 6e46ffd..d682bdc 100644
--- a/src/vte.c
+++ b/src/vte.c
@@ -279,14 +279,11 @@ G_DEFINE_TYPE(VteTerminal, vte_terminal, GTK_TYPE_WIDGET)
* Only the first %VTE_LEGACY_COLOR_SET_SIZE colors have dim versions. */
static const guchar corresponding_dim_index[] = {16,88,28,100,18,90,30,102};
-/* Append a single item to a GArray a given number of times. Centralizing all
- * of the places we do this may let me do something more clever later. */
static void
vte_g_array_fill(GArray *array, gconstpointer item, guint final_size)
{
- if (array->len >= final_size) {
+ if (array->len >= final_size)
return;
- }
final_size -= array->len;
do {
@@ -519,33 +516,17 @@ _vte_terminal_find_row_data(VteTerminal *terminal, glong row)
return rowdata;
}
/* Find the character an the given position in the backscroll buffer. */
-static struct vte_charcell *
+static const struct vte_charcell *
vte_terminal_find_charcell(VteTerminal *terminal, gulong col, glong row)
{
VteRowData *rowdata;
- struct vte_charcell *ret = NULL;
+ const struct vte_charcell *ret = NULL;
VteScreen *screen;
screen = terminal->pvt->screen;
if (_vte_ring_contains(screen->row_data, row)) {
rowdata = _vte_ring_index(screen->row_data, row);
- if (rowdata->cells->len > col) {
- ret = &g_array_index(rowdata->cells,
- struct vte_charcell,
- col);
- }
- }
- return ret;
-}
-
-/* Find the character in the given position in the given row. */
-static inline struct vte_charcell *
-_vte_row_data_find_charcell(VteRowData *rowdata, gulong col)
-{
- struct vte_charcell *ret = NULL;
- if (rowdata->cells->len > col) {
- ret = &g_array_index(rowdata->cells,
- struct vte_charcell,
- col);
+ if (_vte_row_data_length (rowdata) > col)
+ ret = _vte_row_data_get (rowdata, col);
}
return ret;
}
@@ -612,11 +593,11 @@ _vte_invalidate_cell(VteTerminal *terminal, glong col, glong row)
columns = 1;
row_data = _vte_terminal_find_row_data(terminal, row);
if (row_data != NULL) {
- struct vte_charcell *cell;
- cell = _vte_row_data_find_charcell(row_data, col);
+ const struct vte_charcell *cell;
+ cell = _vte_row_data_get (row_data, col);
if (cell != NULL) {
while (cell->attr.fragment && col> 0) {
- cell = _vte_row_data_find_charcell(row_data, --col);
+ cell = _vte_row_data_get (row_data, --col);
}
columns = cell->attr.columns;
if (cell->c != 0 &&
@@ -643,7 +624,7 @@ void
_vte_invalidate_cursor_once(VteTerminal *terminal, gboolean periodic)
{
VteScreen *screen;
- struct vte_charcell *cell;
+ const struct vte_charcell *cell;
gssize preedit_width;
glong column, row;
gint columns;
@@ -665,9 +646,7 @@ _vte_invalidate_cursor_once(VteTerminal *terminal, gboolean periodic)
row = screen->cursor_current.row;
column = screen->cursor_current.col;
columns = 1;
- cell = vte_terminal_find_charcell(terminal,
- column,
- screen->cursor_current.row);
+ cell = vte_terminal_find_charcell(terminal, column, screen->cursor_current.row);
while ((cell != NULL) && (cell->attr.fragment) && (column > 0)) {
column--;
cell = vte_terminal_find_charcell(terminal,
@@ -2315,9 +2294,8 @@ vte_terminal_ensure_cursor(VteTerminal *terminal)
screen = terminal->pvt->screen;
v = screen->cursor_current.col;
- if (G_UNLIKELY ((glong) row->cells->len < v)) { /* pad */
- vte_g_array_fill (row->cells, &screen->basic_defaults, v);
- }
+ if (G_UNLIKELY ((glong) _vte_row_data_length (row) < v)) /* pad */
+ _vte_row_data_fill (row, &screen->basic_defaults, v);
return row;
}
@@ -2829,10 +2807,11 @@ _vte_terminal_cleanup_tab_fragments_at_cursor (VteTerminal *terminal)
VteRowData *row = _vte_terminal_ensure_row (terminal);
VteScreen *screen = terminal->pvt->screen;
long col = screen->cursor_current.col;
- struct vte_charcell *cell = _vte_row_data_find_charcell(row, col);
+ const struct vte_charcell *pcell = _vte_row_data_get (row, col);
- if (G_UNLIKELY (cell != NULL && cell->c == '\t')) {
+ if (G_UNLIKELY (pcell != NULL && pcell->c == '\t')) {
long i, num_columns;
+ struct vte_charcell *cell = _vte_row_data_get_writable (row, col);
_vte_debug_print(VTE_DEBUG_MISC,
"Cleaning tab fragments at %ld",
@@ -2840,11 +2819,11 @@ _vte_terminal_cleanup_tab_fragments_at_cursor (VteTerminal *terminal)
/* go back to the beginning of the tab */
while (cell->attr.fragment && col > 0)
- cell = _vte_row_data_find_charcell(row, --col);
+ cell = _vte_row_data_get_writable (row, --col);
num_columns = cell->attr.columns;
for (i = 0; i < num_columns; i++) {
- cell = _vte_row_data_find_charcell(row, col++);
+ cell = _vte_row_data_get_writable (row, col++);
if (G_UNLIKELY (!cell))
break;
*cell = screen->fill_defaults;
@@ -2873,9 +2852,7 @@ _vte_terminal_cursor_down (VteTerminal *terminal)
if (screen->fill_defaults.attr.back != VTE_DEF_BG) {
VteRowData *rowdata;
rowdata = _vte_terminal_ensure_row (terminal);
- vte_g_array_fill (rowdata->cells,
- &screen->fill_defaults,
- terminal->column_count);
+ _vte_row_data_fill (rowdata, &screen->fill_defaults, terminal->column_count);
}
if (screen->scrolling_restricted) {
@@ -2921,9 +2898,7 @@ _vte_terminal_cursor_down (VteTerminal *terminal)
if (screen->fill_defaults.attr.back != VTE_DEF_BG) {
VteRowData *rowdata;
rowdata = _vte_terminal_ensure_row (terminal);
- vte_g_array_fill (rowdata->cells,
- &screen->fill_defaults,
- terminal->column_count);
+ _vte_row_data_fill (rowdata, &screen->fill_defaults, terminal->column_count);
}
} else {
/* Otherwise, just move the cursor down. */
@@ -3026,7 +3001,7 @@ _vte_terminal_insert_char(VteTerminal *terminal, gunichar c,
if (!row->soft_wrapped)
row = NULL;
else
- col = row->cells->len;
+ col = _vte_row_data_length (row);
}
}
} else {
@@ -3039,14 +3014,14 @@ _vte_terminal_insert_char(VteTerminal *terminal, gunichar c,
/* Combine it on the previous cell */
col--;
- cell = _vte_row_data_find_charcell(row, col);
+ cell = _vte_row_data_get_writable (row, col);
if (G_UNLIKELY (!cell))
goto not_inserted;
/* Find the previous cell */
while (cell->attr.fragment && col > 0) {
- cell = _vte_row_data_find_charcell(row, --col);
+ cell = _vte_row_data_get_writable (row, --col);
}
if (G_UNLIKELY (!cell || cell->c == '\t'))
goto not_inserted;
@@ -3057,7 +3032,7 @@ _vte_terminal_insert_char(VteTerminal *terminal, gunichar c,
/* And set it */
columns = cell->attr.columns;
for (i = 0; i < columns; i++) {
- cell = _vte_row_data_find_charcell(row, col++);
+ cell = _vte_row_data_get_writable (row, col++);
cell->c = c;
}
@@ -3079,32 +3054,30 @@ _vte_terminal_insert_char(VteTerminal *terminal, gunichar c,
if (insert) {
for (i = 0; i < columns; i++)
- g_array_insert_val(row->cells, col + i,
- screen->color_defaults);
+ _vte_row_data_insert (row, col + i, &screen->color_defaults);
} else {
- if (G_LIKELY ((glong) row->cells->len < col + columns)) {
- g_array_set_size (row->cells, col + columns);
- }
+ if (G_LIKELY ((glong) _vte_row_data_length (row) < col + columns))
+ _vte_row_data_set_length (row, col + columns);
}
/* Convert any wide characters we may have broken into single
* cells. (#514632) */
if (G_LIKELY (col > 0)) {
glong col2 = col - 1;
- struct vte_charcell *cell = _vte_row_data_find_charcell(row, col2);
+ struct vte_charcell *cell = _vte_row_data_get_writable (row, col2);
while (cell != NULL && cell->attr.fragment && col2 > 0) {
- cell = _vte_row_data_find_charcell(row, --col2);
+ cell = _vte_row_data_get_writable (row, --col2);
}
cell->attr.columns = col - col2;
}
{
glong col2 = col + columns;
- struct vte_charcell *cell = _vte_row_data_find_charcell(row, col2);
+ struct vte_charcell *cell = _vte_row_data_get_writable (row, col2);
while (cell != NULL && cell->attr.fragment) {
cell->attr.fragment = 0;
cell->attr.columns = 1;
cell->c = 0;
- cell = _vte_row_data_find_charcell(row, ++col2);
+ cell = _vte_row_data_get_writable (row, ++col2);
}
}
@@ -3112,8 +3085,7 @@ _vte_terminal_insert_char(VteTerminal *terminal, gunichar c,
attr.columns = columns;
if (G_UNLIKELY (c == '_' && terminal->pvt->flags.ul)) {
- struct vte_charcell *pcell =
- &g_array_index (row->cells, struct vte_charcell, col);
+ const struct vte_charcell *pcell = _vte_row_data_get (row, col);
/* Handle overstrike-style underlining. */
if (pcell->c != 0) {
/* restore previous contents */
@@ -3124,20 +3096,25 @@ _vte_terminal_insert_char(VteTerminal *terminal, gunichar c,
attr.underline = 1;
}
}
- g_array_index(row->cells, struct vte_charcell, col).c = c;
- g_array_index(row->cells, struct vte_charcell, col).attr = attr;
- col++;
+
+
+ {
+ struct vte_charcell *pcell = _vte_row_data_get_writable (row, col);
+ pcell->c = c;
+ pcell->attr = attr;
+ col++;
+ }
/* insert wide-char fragments */
attr.fragment = 1;
for (i = 1; i < columns; i++) {
- g_array_index(row->cells, struct vte_charcell, col).c = c;
- g_array_index(row->cells, struct vte_charcell, col).attr = attr;
+ struct vte_charcell *pcell = _vte_row_data_get_writable (row, col);
+ pcell->c = c;
+ pcell->attr = attr;
col++;
}
- if (G_UNLIKELY ((long) row->cells->len > terminal->column_count)) {
- g_array_set_size(row->cells, terminal->column_count);
- }
+ if (G_UNLIKELY ((long) _vte_row_data_length (row) > terminal->column_count))
+ _vte_row_data_set_length (row, terminal->column_count);
/* Signal that this part of the window needs drawing. */
if (G_UNLIKELY (invalidate_now)) {
@@ -5163,7 +5140,7 @@ static gboolean
vte_same_class(VteTerminal *terminal, glong acol, glong arow,
glong bcol, glong brow)
{
- struct vte_charcell *pcell = NULL;
+ const struct vte_charcell *pcell = NULL;
gboolean word_char;
if ((pcell = vte_terminal_find_charcell(terminal, acol, arow)) != NULL && pcell->c != 0) {
word_char = vte_terminal_is_word_char(terminal, _vte_unistr_get_base (pcell->c));
@@ -5780,7 +5757,7 @@ vte_terminal_get_text_range_maybe_wrapped(VteTerminal *terminal,
{
long col, row, last_empty, last_emptycol, last_nonempty, last_nonemptycol;
VteScreen *screen;
- struct vte_charcell *pcell = NULL;
+ const struct vte_charcell *pcell = NULL;
GString *string;
struct _VteCharAttributes attr;
struct vte_palette_entry fore, back, *palette;
@@ -5804,7 +5781,7 @@ vte_terminal_get_text_range_maybe_wrapped(VteTerminal *terminal,
attr.column = col;
pcell = NULL;
if (row_data != NULL) {
- while ((pcell = _vte_row_data_find_charcell(row_data, col))) {
+ while ((pcell = _vte_row_data_get (row_data, col))) {
attr.column = col;
@@ -5861,7 +5838,7 @@ vte_terminal_get_text_range_maybe_wrapped(VteTerminal *terminal,
col = last_emptycol + 1;
if (row_data != NULL) {
- while ((pcell = _vte_row_data_find_charcell(row_data, col))) {
+ while ((pcell = _vte_row_data_get (row_data, col))) {
col++;
if (pcell->attr.fragment)
@@ -5898,7 +5875,7 @@ vte_terminal_get_text_range_maybe_wrapped(VteTerminal *terminal,
/* Make sure that the attributes array is as long as the string. */
if (attributes) {
- vte_g_array_fill(attributes, &attr, string->len);
+ vte_g_array_fill (attributes, &attr, string->len);
}
}
/* Sanity check. */
@@ -6107,9 +6084,9 @@ find_start_column (VteTerminal *terminal, glong col, glong row)
if (G_UNLIKELY (col < 0))
return col;
if (row_data != NULL) {
- struct vte_charcell *cell = _vte_row_data_find_charcell(row_data, col);
+ const struct vte_charcell *cell = _vte_row_data_get (row_data, col);
while (cell != NULL && cell->attr.fragment && col > 0) {
- cell = _vte_row_data_find_charcell(row_data, --col);
+ cell = _vte_row_data_get (row_data, --col);
}
}
return MAX(col, 0);
@@ -6122,9 +6099,9 @@ find_end_column (VteTerminal *terminal, glong col, glong row)
if (G_UNLIKELY (col < 0))
return col;
if (row_data != NULL) {
- struct vte_charcell *cell = _vte_row_data_find_charcell(row_data, col);
+ const struct vte_charcell *cell = _vte_row_data_get (row_data, col);
while (cell != NULL && cell->attr.fragment && col > 0) {
- cell = _vte_row_data_find_charcell(row_data, --col);
+ cell = _vte_row_data_get (row_data, --col);
}
if (cell) {
columns = cell->attr.columns - 1;
@@ -6210,7 +6187,7 @@ vte_terminal_extend_selection_expand (VteTerminal *terminal)
long i, j;
VteScreen *screen;
VteRowData *rowdata;
- struct vte_charcell *cell;
+ const struct vte_charcell *cell;
struct selection_cell_coords *sc, *ec;
if (terminal->pvt->selection_block_mode)
@@ -6228,9 +6205,8 @@ vte_terminal_extend_selection_expand (VteTerminal *terminal)
rowdata = _vte_terminal_find_row_data(terminal, sc->row);
if (rowdata != NULL) {
/* Find the last non-empty character on the first line. */
- for (i = rowdata->cells->len; i > 0; i--) {
- cell = &g_array_index(rowdata->cells,
- struct vte_charcell, i - 1);
+ for (i = _vte_row_data_length (rowdata); i > 0; i--) {
+ cell = _vte_row_data_get (rowdata, i - 1);
if (cell->attr.fragment || cell->c != 0)
break;
}
@@ -6257,9 +6233,8 @@ vte_terminal_extend_selection_expand (VteTerminal *terminal)
rowdata = _vte_terminal_find_row_data(terminal, ec->row);
if (rowdata != NULL) {
/* Find the last non-empty character on the last line. */
- for (i = rowdata->cells->len; i > 0; i--) {
- cell = &g_array_index(rowdata->cells,
- struct vte_charcell, i - 1);
+ for (i = _vte_row_data_length (rowdata); i > 0; i--) {
+ cell = _vte_row_data_get (rowdata, i - 1);
if (cell->attr.fragment || cell->c != 0)
break;
}
@@ -6268,7 +6243,7 @@ vte_terminal_extend_selection_expand (VteTerminal *terminal)
if (ec->col >= i) {
ec->col = MAX(ec->col,
MAX(terminal->column_count - 1,
- (long) rowdata->cells->len));
+ (long) _vte_row_data_length (rowdata)));
}
} else {
/* Snap to the rightmost column, only if selecting anything of
@@ -6400,7 +6375,7 @@ vte_terminal_extend_selection_expand (VteTerminal *terminal)
if (_vte_ring_contains(screen->row_data, ec->row)) {
rowdata = _vte_ring_index(screen->row_data, ec->row);
if (rowdata != NULL) {
- ec->col = MAX(ec->col, (long) rowdata->cells->len);
+ ec->col = MAX(ec->col, (long) _vte_row_data_length (rowdata));
}
}
break;
@@ -9968,7 +9943,7 @@ vte_terminal_draw_rows(VteTerminal *terminal,
gboolean underline, nunderline, bold, nbold, hilite, nhilite, reverse,
selected, nselected, strikethrough, nstrikethrough;
guint item_count;
- struct vte_charcell *cell;
+ const struct vte_charcell *cell;
VteRowData *row_data;
reverse = terminal->pvt->screen->reverse_mode;
@@ -9989,16 +9964,16 @@ vte_terminal_draw_rows(VteTerminal *terminal,
* making the drawing area a little wider. */
i = start_column;
if (row_data != NULL) {
- cell = _vte_row_data_find_charcell(row_data, i);
+ cell = _vte_row_data_get (row_data, i);
if (cell != NULL) {
while (cell->attr.fragment && i > 0) {
- cell = _vte_row_data_find_charcell(row_data, --i);
+ cell = _vte_row_data_get (row_data, --i);
}
}
/* Walk the line. */
do {
/* Get the character cell's contents. */
- cell = _vte_row_data_find_charcell(row_data, i);
+ cell = _vte_row_data_get (row_data, i);
/* Find the colors for this cell. */
selected = vte_cell_is_selected(terminal, i, row, NULL);
vte_terminal_determine_colors(terminal, cell,
@@ -10012,7 +9987,7 @@ vte_terminal_draw_rows(VteTerminal *terminal,
while (j < end_column){
/* Retrieve the cell. */
- cell = _vte_row_data_find_charcell(row_data, j);
+ cell = _vte_row_data_get (row_data, j);
/* Don't render fragments of multicolumn characters
* which have the same attributes as the initial
* portions. */
@@ -10104,18 +10079,18 @@ vte_terminal_draw_rows(VteTerminal *terminal,
/* Back up in case this is a multicolumn character,
* making the drawing area a little wider. */
i = start_column;
- cell = _vte_row_data_find_charcell(row_data, i);
+ cell = _vte_row_data_get (row_data, i);
if (cell == NULL) {
goto fg_skip_row;
}
while (cell->attr.fragment && i > 0) {
- cell = _vte_row_data_find_charcell(row_data, --i);
+ cell = _vte_row_data_get (row_data, --i);
}
/* Walk the line. */
do {
/* Get the character cell's contents. */
- cell = _vte_row_data_find_charcell(row_data, i);
+ cell = _vte_row_data_get (row_data, i);
if (cell == NULL) {
goto fg_skip_row;
}
@@ -10127,7 +10102,7 @@ vte_terminal_draw_rows(VteTerminal *terminal,
if (++i >= end_column) {
goto fg_skip_row;
}
- cell = _vte_row_data_find_charcell(row_data, i);
+ cell = _vte_row_data_get (row_data, i);
if (cell == NULL) {
goto fg_skip_row;
}
@@ -10181,7 +10156,7 @@ vte_terminal_draw_rows(VteTerminal *terminal,
while (j < end_column &&
item_count < G_N_ELEMENTS(items)) {
/* Retrieve the cell. */
- cell = _vte_row_data_find_charcell(row_data, j);
+ cell = _vte_row_data_get (row_data, j);
if (cell == NULL) {
goto fg_next_row;
}
@@ -10288,10 +10263,10 @@ fg_next_row:
* multicolumn character, making the drawing
* area a little wider. */
j = start_column;
- cell = _vte_row_data_find_charcell(row_data, j);
+ cell = _vte_row_data_get (row_data, j);
} while (cell == NULL);
while (cell->attr.fragment && j > 0) {
- cell = _vte_row_data_find_charcell(row_data, --j);
+ cell = _vte_row_data_get (row_data, --j);
}
} while (TRUE);
fg_draw:
@@ -10447,7 +10422,7 @@ vte_terminal_paint_cursor(VteTerminal *terminal)
{
VteScreen *screen;
GdkColor color;
- struct vte_charcell *cell;
+ const struct vte_charcell *cell;
struct _vte_draw_text_request item;
int row, drow, col;
long width, height, delta, cursor_width;
diff --git a/src/vteseq.c b/src/vteseq.c
index 1b518a5..ca3b771 100644
--- a/src/vteseq.c
+++ b/src/vteseq.c
@@ -86,33 +86,12 @@ vte_terminal_find_charcell(VteTerminal *terminal, glong col, glong row)
screen = terminal->pvt->screen;
if (_vte_ring_contains(screen->row_data, row)) {
rowdata = _vte_ring_index(screen->row_data, row);
- if ((glong) rowdata->cells->len > col) {
- ret = &g_array_index(rowdata->cells,
- struct vte_charcell,
- col);
- }
+ if ((glong) _vte_row_data_length (rowdata) > col)
+ ret = _vte_row_data_get_writable (rowdata, col);
}
return ret;
}
-/* Append a single item to a GArray a given number of times. Centralizing all
- * of the places we do this may let me do something more clever later.
- * Dupped from vte.c. */
-static void
-vte_g_array_fill(GArray *array, gpointer item, guint final_size)
-{
- g_assert(array != NULL);
- if (array->len >= final_size) {
- return;
- }
- g_assert(item != NULL);
-
- final_size -= array->len;
- do {
- g_array_append_vals(array, item, 1);
- } while (--final_size);
-}
-
/* Check how long a string of unichars is. Slow version. */
static gssize
vte_unichar_strlen(gunichar *c)
@@ -327,14 +306,11 @@ _vte_terminal_clear_current_line (VteTerminal *terminal)
rowdata = _vte_ring_index(screen->row_data, screen->cursor_current.row);
g_assert(rowdata != NULL);
/* Remove it. */
- if (rowdata->cells->len > 0) {
- g_array_set_size(rowdata->cells, 0);
- }
+ if (_vte_row_data_length (rowdata) > 0)
+ _vte_row_data_set_length (rowdata, 0);
/* Add enough cells to the end of the line to fill out the
* row. */
- vte_g_array_fill(rowdata->cells,
- &screen->fill_defaults,
- terminal->column_count);
+ _vte_row_data_fill (rowdata, &screen->fill_defaults, terminal->column_count);
rowdata->soft_wrapped = 0;
/* Repaint this row. */
_vte_invalidate_cells(terminal,
@@ -358,19 +334,13 @@ _vte_terminal_clear_above_current (VteTerminal *terminal)
* which corresponds to the cursor. */
for (i = screen->insert_delta; i < screen->cursor_current.row; i++) {
if (_vte_ring_next(screen->row_data) > i) {
- guint len;
/* Get the data for the row we're erasing. */
rowdata = _vte_ring_index(screen->row_data, i);
g_assert(rowdata != NULL);
/* Remove it. */
- len = rowdata->cells->len;
- if (len > 0) {
- g_array_set_size(rowdata->cells, 0);
- }
+ _vte_row_data_set_length (rowdata, 0);
/* Add new cells until we fill the row. */
- vte_g_array_fill(rowdata->cells,
- &screen->fill_defaults,
- terminal->column_count);
+ _vte_row_data_fill (rowdata, &screen->fill_defaults, terminal->column_count);
rowdata->soft_wrapped = 0;
/* Repaint the row. */
_vte_invalidate_cells(terminal,
@@ -959,8 +929,7 @@ vte_sequence_handler_al (VteTerminal *terminal, GValueArray *params)
_vte_ring_remove (terminal->pvt->screen->row_data, end);
rowdata = _vte_ring_insert (terminal->pvt->screen->row_data, start);
/* Add enough cells to it so that it has the default columns. */
- vte_g_array_fill(rowdata->cells, &screen->fill_defaults,
- terminal->column_count);
+ _vte_row_data_fill (rowdata, &screen->fill_defaults, terminal->column_count);
/* Adjust the scrollbars if necessary. */
_vte_terminal_adjust_adjustments(terminal);
}
@@ -1041,16 +1010,13 @@ vte_sequence_handler_cb (VteTerminal *terminal, GValueArray *params)
* attributes. If there is no such character cell, we need
* to add one. */
for (i = 0; i <= screen->cursor_current.col; i++) {
- if (i < (glong) rowdata->cells->len) {
+ if (i < (glong) _vte_row_data_length (rowdata)) {
/* Muck with the cell in this location. */
- pcell = &g_array_index(rowdata->cells,
- struct vte_charcell,
- i);
+ pcell = _vte_row_data_get_writable (rowdata, i);
*pcell = screen->color_defaults;
} else {
/* Add new cells until we have one here. */
- g_array_append_val(rowdata->cells,
- screen->color_defaults);
+ _vte_row_data_append (rowdata, &screen->color_defaults);
}
}
/* Repaint this row. */
@@ -1079,9 +1045,8 @@ vte_sequence_handler_cd (VteTerminal *terminal, GValueArray *params)
rowdata = _vte_ring_index(screen->row_data, i);
/* Clear everything to the right of the cursor. */
if ((rowdata != NULL) &&
- ((glong) rowdata->cells->len > screen->cursor_current.col)) {
- g_array_set_size(rowdata->cells,
- screen->cursor_current.col);
+ ((glong) _vte_row_data_length (rowdata) > screen->cursor_current.col)) {
+ _vte_row_data_set_length (rowdata, screen->cursor_current.col);
}
}
/* Now for the rest of the lines. */
@@ -1091,9 +1056,8 @@ vte_sequence_handler_cd (VteTerminal *terminal, GValueArray *params)
/* Get the data for the row we're removing. */
rowdata = _vte_ring_index(screen->row_data, i);
/* Remove it. */
- if ((rowdata != NULL) && (rowdata->cells->len > 0)) {
- g_array_set_size(rowdata->cells, 0);
- }
+ if (rowdata != NULL)
+ _vte_row_data_set_length (rowdata, 0);
}
/* Now fill the cleared areas. */
for (i = screen->cursor_current.row;
@@ -1107,9 +1071,7 @@ vte_sequence_handler_cd (VteTerminal *terminal, GValueArray *params)
rowdata = _vte_ring_append(screen->row_data);
}
/* Pad out the row. */
- vte_g_array_fill(rowdata->cells,
- &screen->fill_defaults,
- terminal->column_count);
+ _vte_row_data_fill (rowdata, &screen->fill_defaults, terminal->column_count);
rowdata->soft_wrapped = 0;
/* Repaint this row. */
_vte_invalidate_cells(terminal,
@@ -1134,16 +1096,14 @@ vte_sequence_handler_ce (VteTerminal *terminal, GValueArray *params)
g_assert(rowdata != NULL);
/* Remove the data at the end of the array until the current column
* is the end of the array. */
- if ((glong) rowdata->cells->len > screen->cursor_current.col) {
- g_array_set_size(rowdata->cells, screen->cursor_current.col);
+ if ((glong) _vte_row_data_length (rowdata) > screen->cursor_current.col) {
+ _vte_row_data_set_length (rowdata, screen->cursor_current.col);
/* We've modified the display. Make a note of it. */
terminal->pvt->text_deleted_flag = TRUE;
}
if (screen->fill_defaults.attr.back != VTE_DEF_BG) {
/* Add enough cells to fill out the row. */
- vte_g_array_fill(rowdata->cells,
- &screen->fill_defaults,
- terminal->column_count);
+ _vte_row_data_fill (rowdata, &screen->fill_defaults, terminal->column_count);
}
rowdata->soft_wrapped = 0;
/* Repaint this row. */
@@ -1398,14 +1358,12 @@ vte_sequence_handler_dc (VteTerminal *terminal, GValueArray *params)
rowdata = _vte_ring_index(screen->row_data, screen->cursor_current.row);
g_assert(rowdata != NULL);
col = screen->cursor_current.col;
- len = rowdata->cells->len;
+ len = _vte_row_data_length (rowdata);
/* Remove the column. */
if (col < len) {
- g_array_remove_index(rowdata->cells, col);
+ _vte_row_data_remove (rowdata, col);
if (screen->fill_defaults.attr.back != VTE_DEF_BG) {
- vte_g_array_fill (rowdata->cells,
- &screen->fill_defaults,
- terminal->column_count);
+ _vte_row_data_fill (rowdata, &screen->fill_defaults, terminal->column_count);
len = terminal->column_count;
}
/* Repaint this row. */
@@ -1542,18 +1500,14 @@ vte_sequence_handler_ec (VteTerminal *terminal, GValueArray *params)
for (i = 0; i < count; i++) {
col = screen->cursor_current.col + i;
if (col >= 0) {
- if (col < (glong) rowdata->cells->len) {
+ if (col < (glong) _vte_row_data_length (rowdata)) {
/* Replace this cell with the current
* defaults. */
- cell = &g_array_index(rowdata->cells,
- struct vte_charcell,
- col);
+ cell = _vte_row_data_get_writable (rowdata, col);
*cell = screen->color_defaults;
} else {
/* Add new cells until we have one here. */
- vte_g_array_fill(rowdata->cells,
- &screen->color_defaults,
- col);
+ _vte_row_data_fill (rowdata, &screen->color_defaults, col);
}
}
}
@@ -2108,26 +2062,23 @@ vte_sequence_handler_ta (VteTerminal *terminal, GValueArray *params)
*/
/* Get rid of trailing empty cells: bug 545924 */
- if ((glong) rowdata->cells->len > col)
+ if ((glong) _vte_row_data_length (rowdata) > col)
{
- struct vte_charcell *cell;
+ const struct vte_charcell *cell;
guint i;
- for (i = rowdata->cells->len; (glong) i > col; i--) {
- cell = &g_array_index(rowdata->cells,
- struct vte_charcell, i - 1);
+ for (i = _vte_row_data_length (rowdata); (glong) i > col; i--) {
+ cell = _vte_row_data_get (rowdata, i - 1);
if (cell->attr.fragment || cell->c != 0)
break;
}
- g_array_set_size(rowdata->cells, i);
+ _vte_row_data_set_length (rowdata, i);
}
- if ((glong) rowdata->cells->len <= col)
+ if ((glong) _vte_row_data_length (rowdata) <= col)
{
struct vte_charcell cell;
- vte_g_array_fill (rowdata->cells,
- &screen->fill_defaults,
- col);
+ _vte_row_data_fill (rowdata, &screen->fill_defaults, col);
cell.attr = screen->fill_defaults.attr;
cell.attr.invisible = 1; /* FIXME: bug 499944 */
@@ -2140,20 +2091,16 @@ vte_sequence_handler_ta (VteTerminal *terminal, GValueArray *params)
goto fallback_tab;
}
cell.c = '\t';
- g_array_append_vals(rowdata->cells, &cell, 1);
+ _vte_row_data_append (rowdata, &cell);
cell.attr = screen->fill_defaults.attr;
cell.attr.fragment = 1;
- vte_g_array_fill (rowdata->cells,
- &cell,
- newcol);
+ _vte_row_data_fill (rowdata, &cell, newcol);
}
else
{
fallback_tab:
- vte_g_array_fill (rowdata->cells,
- &screen->fill_defaults,
- newcol);
+ _vte_row_data_fill (rowdata, &screen->fill_defaults, newcol);
}
_vte_invalidate_cells (terminal,
@@ -2208,14 +2155,10 @@ vte_sequence_handler_uc (VteTerminal *terminal, GValueArray *params)
screen = terminal->pvt->screen;
column = screen->cursor_current.col;
- cell = vte_terminal_find_charcell(terminal,
- column,
- screen->cursor_current.row);
+ cell = vte_terminal_find_charcell(terminal, column, screen->cursor_current.row);
while ((cell != NULL) && (cell->attr.fragment) && (column > 0)) {
column--;
- cell = vte_terminal_find_charcell(terminal,
- column,
- screen->cursor_current.row);
+ cell = vte_terminal_find_charcell(terminal, column, screen->cursor_current.row);
}
if (cell != NULL) {
/* Set this character to be underlined. */
@@ -2825,9 +2768,7 @@ vte_sequence_handler_insert_lines (VteTerminal *terminal, GValueArray *params)
_vte_ring_remove (terminal->pvt->screen->row_data, end);
rowdata = _vte_ring_insert (terminal->pvt->screen->row_data, row);
/* Add enough cells to it so that it has the default colors. */
- vte_g_array_fill(rowdata->cells,
- &screen->fill_defaults,
- terminal->column_count);
+ _vte_row_data_fill (rowdata, &screen->fill_defaults, terminal->column_count);
}
/* Update the display. */
_vte_terminal_scroll_region(terminal, row, end - row + 1, param);
@@ -2871,9 +2812,7 @@ vte_sequence_handler_delete_lines (VteTerminal *terminal, GValueArray *params)
_vte_ring_remove (terminal->pvt->screen->row_data, row);
rowdata = _vte_ring_insert (terminal->pvt->screen->row_data, end);
/* Add enough cells to it so that it has the default colors. */
- vte_g_array_fill(rowdata->cells,
- &screen->fill_defaults,
- terminal->column_count);
+ _vte_row_data_fill (rowdata, &screen->fill_defaults, terminal->column_count);
}
/* Update the display. */
_vte_terminal_scroll_region(terminal, row, end - row + 1, -param);
@@ -3044,15 +2983,14 @@ vte_sequence_handler_screen_alignment_test (VteTerminal *terminal, GValueArray *
rowdata = _vte_ring_index(screen->row_data, row);
g_assert(rowdata != NULL);
/* Clear this row. */
- if (rowdata->cells->len > 0) {
- g_array_set_size(rowdata->cells, 0);
- }
+ _vte_row_data_set_length (rowdata, 0);
+
_vte_terminal_emit_text_deleted(terminal);
/* Fill this row. */
cell.c = 'E';
cell.attr = screen->basic_defaults.attr;
cell.attr.columns = 1;
- vte_g_array_fill(rowdata->cells, &cell, terminal->column_count);
+ _vte_row_data_fill (rowdata, &cell, terminal->column_count);
_vte_terminal_emit_text_inserted(terminal);
}
_vte_invalidate_all(terminal);
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]