[vte] Specialize VteRing to know about VteRowData
- From: Behdad Esfahbod <behdad src gnome org>
- To: svn-commits-list gnome org
- Cc:
- Subject: [vte] Specialize VteRing to know about VteRowData
- Date: Fri, 21 Aug 2009 16:20:25 +0000 (UTC)
commit ba1f44d6119cc39602d8a660f4e5a9f56a6f19da
Author: Behdad Esfahbod <behdad behdad org>
Date: Thu Aug 20 23:03:50 2009 -0400
Specialize VteRing to know about VteRowData
src/ring.c | 139 ++++++++--------------------------------------------
src/ring.h | 24 ++++-----
src/vte-private.h | 6 --
src/vte.c | 68 ++++----------------------
src/vteseq.c | 28 ++++-------
5 files changed, 53 insertions(+), 212 deletions(-)
---
diff --git a/src/ring.c b/src/ring.c
index c396462..22263cd 100644
--- a/src/ring.c
+++ b/src/ring.c
@@ -23,6 +23,15 @@
#include "debug.h"
#include "ring.h"
+static void
+_vte_free_row_data(VteRowData *row)
+{
+ if (!row)
+ return;
+ g_array_free(row->cells, TRUE);
+ g_slice_free(VteRowData, row);
+}
+
#ifdef VTE_DEBUG
static void
_vte_ring_validate(VteRing * ring)
@@ -53,23 +62,20 @@ _vte_ring_validate(VteRing * ring)
* Returns: a new ring
*/
VteRing *
-_vte_ring_new(glong max_elements, VteRingFreeFunc free_func, gpointer data)
+_vte_ring_new(glong max_elements)
{
VteRing *ret = g_slice_new0(VteRing);
- ret->user_data = data;
ret->cached_item = -1;
ret->max = MAX(max_elements, 2);
ret->array = g_malloc0(sizeof(gpointer) * ret->max);
- ret->free = free_func;
return ret;
}
VteRing *
-_vte_ring_new_with_delta(glong max_elements, glong delta,
- VteRingFreeFunc free_func, gpointer data)
+_vte_ring_new_with_delta(glong max_elements, glong delta)
{
VteRing *ret;
- ret = _vte_ring_new(max_elements, free_func, data);
+ ret = _vte_ring_new(max_elements);
ret->delta = delta;
return ret;
}
@@ -104,14 +110,7 @@ _vte_ring_insert(VteRing * ring, long position, gpointer data)
/* Initial insertion, or append. */
if (position == ring->length + ring->delta) {
/* If there was something there before, free it. */
- if ((ring->free != NULL) &&
- (ring->array[position % ring->max] != NULL)) {
- _vte_debug_print(VTE_DEBUG_RING,
- "Freeing item at position "
- "%ld.\n", position);
- ring->free(ring->array[position % ring->max],
- ring->user_data);
- }
+ _vte_free_row_data (ring->array[position % ring->max]);
/* Set the new item, and if the buffer wasn't "full", increase
* our idea of how big it is, otherwise increase the delta so
* that this becomes the "last" item and the previous item
@@ -149,13 +148,7 @@ _vte_ring_insert(VteRing * ring, long position, gpointer data)
/* If the buffer's full, then the last item will have to be
* "lost" to make room for the new item so that the buffer
* doesn't grow (here we scroll off the *bottom*). */
- if (ring->free && ring->array[point % ring->max]) {
- _vte_debug_print(VTE_DEBUG_RING,
- "Freeing item at position "
- "%ld.\n", point);
- ring->free(ring->array[point % ring->max],
- ring->user_data);
- }
+ _vte_free_row_data (ring->array[point % ring->max]);
} else {
/* We don't want to discard the last item. */
point++;
@@ -193,8 +186,8 @@ void
_vte_ring_insert_preserve(VteRing * ring, long position, gpointer data)
{
long point, i;
- gpointer **tmp;
- gpointer *stack_tmp[128];
+ VteRowData **tmp;
+ VteRowData *stack_tmp[128];
g_return_if_fail(position <= _vte_ring_next(ring));
@@ -215,9 +208,9 @@ _vte_ring_insert_preserve(VteRing * ring, long position, gpointer data)
/* Save existing elements. */
tmp = stack_tmp;
if ((guint) i > G_N_ELEMENTS (stack_tmp))
- tmp = g_new0(gpointer *, i);
+ tmp = g_new0(VteRowData *, i);
for (i = position; i < point; i++) {
- tmp[i - position] = _vte_ring_index(ring, gpointer, i);
+ tmp[i - position] = _vte_ring_index(ring, i);
}
/* Remove the existing elements. */
@@ -264,11 +257,7 @@ _vte_ring_remove(VteRing * ring, long position, gboolean free_element)
i = position % ring->max;
/* Remove the data at this position. */
- if (free_element && ring->array[position % ring->max] && ring->free) {
- _vte_debug_print(VTE_DEBUG_RING,
- "Freeing item at position %ld.\n", position);
- ring->free(ring->array[position % ring->max], ring->user_data);
- }
+ _vte_free_row_data (ring->array[position % ring->max]);
ring->array[position % ring->max] = NULL;
/* Bubble the rest of the buffer up one notch. This is also less
@@ -314,99 +303,15 @@ _vte_ring_append(VteRing * ring, gpointer data)
*
*/
void
-_vte_ring_free(VteRing * ring, gboolean free_elements)
+_vte_ring_free(VteRing *ring, gboolean free_elements)
{
long i;
- if (free_elements && ring->free) {
+ if (free_elements) {
for (i = 0; i < ring->max; i++) {
/* Remove this item. */
- if (ring->array[i] != NULL) {
- ring->free(ring->array[i], ring->user_data);
- }
+ _vte_free_row_data (ring->array[i]);
}
}
g_free(ring->array);
g_slice_free(VteRing, ring);
}
-
-#ifdef RING_MAIN
-static void
-scrolled_off(gpointer freed, gpointer data)
-{
- long *l = (long *)freed;
- char *fmt = data;
- g_printerr(fmt, *l);
-}
-
-int
-main(int argc, char **argv)
-{
- long i, j, k, bias;
- const int size = 8;
- long values[40];
- long lone = 42;
- long *value;
- VteRing *ring;
-
- for (i = 0; i < G_N_ELEMENTS(values); i++) {
- values[i] = i;
- }
-
- ring = _vte_ring_new(size, scrolled_off, "Lost value %ld.\n");
- bias = 0;
- g_printerr("Initializing.\n");
- for (i = 0; i + bias <= G_N_ELEMENTS(values); i++) {
- k = 0;
- g_printerr("[%ld] ", i);
- for (j = 0; j < G_N_ELEMENTS(values); j++) {
- if (_vte_ring_contains(ring, j)) {
- value = _vte_ring_index(ring, long *, j);
- } else {
- value = NULL;
- }
- if (value) {
- g_printerr("%s%ld->%ld",
- (k > 0) ? ", " : "", j, *value);
- k++;
- }
- }
- g_printerr("\n");
- g_printerr("[%ld] max %ld, delta %ld, length %ld = {",
- i, ring->max, ring->delta, ring->length);
- for (j = 0; j < size; j++) {
- value = ring->array[j];
- if (j > 0) {
- g_printerr(", ");
- }
- if (value) {
- g_printerr("%ld", *value);
- }
- }
- g_printerr("}\n");
- if (i == 3) {
- g_printerr("Removing item at 4.\n");
- _vte_ring_remove(ring, 4, TRUE);
- bias--;
- } else if (i == 10) {
- g_printerr("Inserting item at 7.\n");
- _vte_ring_insert(ring, 7, &lone);
- bias--;
- } else if (i == 20) {
- g_printerr("Inserting item at 13.\n");
- _vte_ring_insert(ring, 13, &lone);
- bias--;
- } else if (i == 30) {
- g_printerr("Inserting item at 23.\n");
- _vte_ring_insert_preserve(ring, 23, &lone);
- bias--;
- } else if (i < G_N_ELEMENTS(values)) {
- g_printerr("Appending item.\n");
- _vte_ring_append(ring, &values[i + bias]);
- }
- }
-
- _vte_ring_free(ring, TRUE);
-
- return 0;
-}
-#endif
diff --git a/src/ring.h b/src/ring.h
index 48a6e96..56368f2 100644
--- a/src/ring.h
+++ b/src/ring.h
@@ -26,17 +26,18 @@
G_BEGIN_DECLS
+typedef struct _VteRowData {
+ GArray *cells;
+ guchar soft_wrapped: 1;
+} VteRowData;
+
typedef struct _VteRing VteRing;
-typedef void (*VteRingFreeFunc)(gpointer freeing, gpointer data);
struct _VteRing {
glong delta, length, max;
glong cached_item;
gpointer cached_data;
- gpointer *array;
-
- VteRingFreeFunc free;
- gpointer user_data;
+ VteRowData **array;
};
#define _vte_ring_contains(__ring, __position) \
@@ -50,7 +51,7 @@ struct _VteRing {
#define _vte_ring_get_cached_data(__ring) ((__ring)->cached_data)
#define _vte_ring_set_cache(__ring, __v, __data) ((__ring)->cached_item = (__v), (__ring)->cached_data = (__data))
#ifdef VTE_DEBUG
-#define _vte_ring_at(__ring, __position) \
+#define _vte_ring_index(__ring, __position) \
((__ring)->array[(__position) % (__ring)->max] ? \
(__ring)->array[(__position) % (__ring)->max] : \
(g_critical("NULL at %ld(->%ld) delta %ld, length %ld, max %ld next %ld" \
@@ -60,17 +61,12 @@ struct _VteRing {
(__ring)->delta + (__ring)->length, \
__LINE__), (gpointer) NULL))
#else
-#define _vte_ring_at(__ring, __position) \
+#define _vte_ring_index(__ring, __position) \
((__ring)->array[(__position) % (__ring)->max])
#endif
-#define _vte_ring_index(__ring, __cast, __position) \
- (__cast) _vte_ring_at(__ring, __position)
-VteRing *_vte_ring_new(glong max_elements,
- VteRingFreeFunc free_func,
- gpointer data);
-VteRing *_vte_ring_new_with_delta(glong max_elements, glong delta,
- VteRingFreeFunc free_func, gpointer data);
+VteRing *_vte_ring_new(glong max_elements);
+VteRing *_vte_ring_new_with_delta(glong max_elements, glong delta);
void _vte_ring_insert(VteRing *ring, glong position, gpointer data);
void _vte_ring_insert_preserve(VteRing *ring, glong position, gpointer data);
void _vte_ring_remove(VteRing *ring, glong position, gboolean free_element);
diff --git a/src/vte-private.h b/src/vte-private.h
index 65fe8ca..bf2e489 100644
--- a/src/vte-private.h
+++ b/src/vte-private.h
@@ -183,11 +183,6 @@ typedef struct _VteWordCharRange {
gunichar start, end;
} VteWordCharRange;
-typedef struct _VteRowData {
- GArray *cells;
- guchar soft_wrapped: 1;
-} VteRowData;
-
/* Terminal private data. */
struct _VteTerminalPrivate {
/* Emulation setup data. */
@@ -286,7 +281,6 @@ struct _VteTerminalPrivate {
GString *status_line_contents;
gboolean status_line_changed;
} normal_screen, alternate_screen, *screen;
- VteRowData *free_row; /* cached VteRowData */
/* Selection information. */
GArray *word_chars;
diff --git a/src/vte.c b/src/vte.c
index 35d4ca8..ac3505d 100644
--- a/src/vte.c
+++ b/src/vte.c
@@ -279,30 +279,6 @@ 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};
-static void
-_vte_free_row_data(VteRowData *row)
-{
- g_array_free(row->cells, TRUE);
- g_slice_free(VteRowData, row);
-}
-
-static void
-_vte_terminal_free_row_data(VteTerminal *terminal,
- VteRowData *row)
-{
- if (terminal->pvt->free_row)
- _vte_free_row_data (terminal->pvt->free_row);
-
- terminal->pvt->free_row = row;
-}
-
-static void
-_vte_terminal_free_row_data_ring_callback (VteRowData *row,
- VteTerminal *terminal)
-{
- _vte_terminal_free_row_data(terminal, row);
-}
-
/* 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
@@ -336,11 +312,6 @@ VteRowData *
_vte_new_row_data(VteTerminal *terminal)
{
VteRowData *row = NULL;
- if (terminal->pvt->free_row) {
- row = terminal->pvt->free_row;
- terminal->pvt->free_row = NULL;
- return _vte_reset_row_data (terminal, row, FALSE);
- }
row = g_slice_new(VteRowData);
row->cells = g_array_new(FALSE, TRUE, sizeof(struct vte_charcell));
row->soft_wrapped = 0;
@@ -352,11 +323,6 @@ VteRowData *
_vte_new_row_data_sized(VteTerminal *terminal, gboolean fill)
{
VteRowData *row = NULL;
- if (terminal->pvt->free_row) {
- row = terminal->pvt->free_row;
- terminal->pvt->free_row = NULL;
- return _vte_reset_row_data (terminal, row, fill);
- }
row = g_slice_new(VteRowData);
row->cells = g_array_sized_new(FALSE, TRUE,
sizeof(struct vte_charcell),
@@ -618,7 +584,7 @@ _vte_terminal_find_row_data(VteTerminal *terminal, glong row)
VteRowData *rowdata = NULL;
VteScreen *screen = terminal->pvt->screen;
if (_vte_ring_contains(screen->row_data, row)) {
- rowdata = _vte_ring_index(screen->row_data, VteRowData *, row);
+ rowdata = _vte_ring_index(screen->row_data, row);
}
return rowdata;
}
@@ -631,7 +597,7 @@ vte_terminal_find_charcell(VteTerminal *terminal, gulong col, glong row)
VteScreen *screen;
screen = terminal->pvt->screen;
if (_vte_ring_contains(screen->row_data, row)) {
- rowdata = _vte_ring_index(screen->row_data, VteRowData *, row);
+ rowdata = _vte_ring_index(screen->row_data, row);
if (rowdata->cells->len > col) {
ret = &g_array_index(rowdata->cells,
struct vte_charcell,
@@ -2402,8 +2368,7 @@ _vte_terminal_ensure_row (VteTerminal *terminal)
_vte_terminal_adjust_adjustments(terminal);
} else {
/* Find the row the cursor is in. */
- row = _vte_ring_index(screen->row_data,
- VteRowData *, v);
+ row = _vte_ring_index(screen->row_data, v);
}
_vte_ring_set_cache (screen->row_data, v, row);
} else {
@@ -6405,8 +6370,7 @@ vte_terminal_extend_selection_expand (VteTerminal *terminal)
j = sc->row;
while (_vte_ring_contains(screen->row_data, j)) {
/* Get the data for the row we're looking at. */
- rowdata = _vte_ring_index(screen->row_data,
- VteRowData *, j);
+ rowdata = _vte_ring_index(screen->row_data, j);
if (rowdata == NULL) {
break;
}
@@ -6452,8 +6416,7 @@ vte_terminal_extend_selection_expand (VteTerminal *terminal)
j = ec->row;
while (_vte_ring_contains(screen->row_data, j)) {
/* Get the data for the row we're looking at. */
- rowdata = _vte_ring_index(screen->row_data,
- VteRowData *, j);
+ rowdata = _vte_ring_index(screen->row_data, j);
if (rowdata == NULL) {
break;
}
@@ -6514,8 +6477,7 @@ vte_terminal_extend_selection_expand (VteTerminal *terminal)
/* Make sure we include all of the last line. */
ec->col = terminal->column_count - 1;
if (_vte_ring_contains(screen->row_data, ec->row)) {
- rowdata = _vte_ring_index(screen->row_data,
- VteRowData *, ec->row);
+ rowdata = _vte_ring_index(screen->row_data, ec->row);
if (rowdata != NULL) {
ec->col = MAX(ec->col, (long) rowdata->cells->len);
}
@@ -7998,14 +7960,11 @@ vte_terminal_reset_rowdata(VteTerminal *terminal, VteRing **ring, glong lines)
if (*ring && (_vte_ring_max(*ring) == lines)) {
return;
}
- new_ring = _vte_ring_new_with_delta(lines,
- *ring ? _vte_ring_delta(*ring) : 0,
- (GFunc) _vte_terminal_free_row_data_ring_callback,
- terminal);
+ new_ring = _vte_ring_new_with_delta(lines, *ring ? _vte_ring_delta(*ring) : 0);
if (*ring) {
next = _vte_ring_next(*ring);
for (i = _vte_ring_delta(*ring); i < next; i++) {
- row = _vte_ring_index(*ring, VteRowData *, i);
+ row = _vte_ring_index(*ring, i);
_vte_ring_append(new_ring, row);
}
_vte_ring_free(*ring, FALSE);
@@ -8548,9 +8507,6 @@ vte_terminal_finalize(GObject *object)
/* Clear the output histories. */
_vte_ring_free(terminal->pvt->normal_screen.row_data, TRUE);
_vte_ring_free(terminal->pvt->alternate_screen.row_data, TRUE);
- if (terminal->pvt->free_row) {
- _vte_free_row_data (terminal->pvt->free_row);
- }
/* Clear the status lines. */
g_string_free(terminal->pvt->normal_screen.status_line_contents,
@@ -13500,13 +13456,9 @@ vte_terminal_reset(VteTerminal *terminal, gboolean full, gboolean clear_history)
/* Clear the scrollback buffers and reset the cursors. */
if (clear_history) {
_vte_ring_free(terminal->pvt->normal_screen.row_data, TRUE);
- terminal->pvt->normal_screen.row_data =
- _vte_ring_new(terminal->pvt->scrollback_lines,
- (GFunc) _vte_terminal_free_row_data_ring_callback, terminal);
+ terminal->pvt->normal_screen.row_data = _vte_ring_new(terminal->pvt->scrollback_lines);
_vte_ring_free(terminal->pvt->alternate_screen.row_data, TRUE);
- terminal->pvt->alternate_screen.row_data =
- _vte_ring_new(terminal->pvt->scrollback_lines,
- (GFunc) _vte_terminal_free_row_data_ring_callback, terminal);
+ terminal->pvt->alternate_screen.row_data = _vte_ring_new(terminal->pvt->scrollback_lines);
terminal->pvt->normal_screen.cursor_saved.row = 0;
terminal->pvt->normal_screen.cursor_saved.col = 0;
terminal->pvt->normal_screen.cursor_current.row = 0;
diff --git a/src/vteseq.c b/src/vteseq.c
index 0bbf102..b22694a 100644
--- a/src/vteseq.c
+++ b/src/vteseq.c
@@ -85,7 +85,7 @@ vte_terminal_find_charcell(VteTerminal *terminal, glong col, glong row)
g_assert(VTE_IS_TERMINAL(terminal));
screen = terminal->pvt->screen;
if (_vte_ring_contains(screen->row_data, row)) {
- rowdata = _vte_ring_index(screen->row_data, VteRowData *, row);
+ rowdata = _vte_ring_index(screen->row_data, row);
if ((glong) rowdata->cells->len > col) {
ret = &g_array_index(rowdata->cells,
struct vte_charcell,
@@ -359,8 +359,7 @@ _vte_terminal_clear_current_line (VteTerminal *terminal)
* which corresponds to the cursor. */
if (_vte_ring_next(screen->row_data) > screen->cursor_current.row) {
/* Get the data for the row which the cursor points to. */
- rowdata = _vte_ring_index(screen->row_data, VteRowData *,
- screen->cursor_current.row);
+ rowdata = _vte_ring_index(screen->row_data, screen->cursor_current.row);
g_assert(rowdata != NULL);
/* Remove it. */
if (rowdata->cells->len > 0) {
@@ -396,8 +395,7 @@ _vte_terminal_clear_above_current (VteTerminal *terminal)
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,
- VteRowData *, i);
+ rowdata = _vte_ring_index(screen->row_data, i);
g_assert(rowdata != NULL);
/* Remove it. */
len = rowdata->cells->len;
@@ -998,8 +996,7 @@ vte_sequence_handler_al (VteTerminal *terminal, GValueArray *params)
vte_remove_line_internal(terminal, end);
vte_insert_line_internal(terminal, start);
/* Get the data for the new row. */
- rowdata = _vte_ring_index(screen->row_data,
- VteRowData *, start);
+ rowdata = _vte_ring_index(screen->row_data, start);
g_assert(rowdata != NULL);
/* Add enough cells to it so that it has the default columns. */
vte_g_array_fill(rowdata->cells, &screen->fill_defaults,
@@ -1119,7 +1116,7 @@ vte_sequence_handler_cd (VteTerminal *terminal, GValueArray *params)
i = screen->cursor_current.row;
if (i < _vte_ring_next(screen->row_data)) {
/* Get the data for the row we're clipping. */
- rowdata = _vte_ring_index(screen->row_data, VteRowData *, i);
+ 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)) {
@@ -1132,7 +1129,7 @@ vte_sequence_handler_cd (VteTerminal *terminal, GValueArray *params)
i < _vte_ring_next(screen->row_data);
i++) {
/* Get the data for the row we're removing. */
- rowdata = _vte_ring_index(screen->row_data, VteRowData *, i);
+ rowdata = _vte_ring_index(screen->row_data, i);
/* Remove it. */
if ((rowdata != NULL) && (rowdata->cells->len > 0)) {
g_array_set_size(rowdata->cells, 0);
@@ -1144,8 +1141,7 @@ vte_sequence_handler_cd (VteTerminal *terminal, GValueArray *params)
i++) {
/* Retrieve the row's data, creating it if necessary. */
if (_vte_ring_contains(screen->row_data, i)) {
- rowdata = _vte_ring_index(screen->row_data,
- VteRowData *, i);
+ rowdata = _vte_ring_index(screen->row_data, i);
g_assert(rowdata != NULL);
} else {
rowdata = _vte_new_row_data(terminal);
@@ -1440,9 +1436,7 @@ vte_sequence_handler_dc (VteTerminal *terminal, GValueArray *params)
if (_vte_ring_next(screen->row_data) > screen->cursor_current.row) {
long len;
/* Get the data for the row which the cursor points to. */
- rowdata = _vte_ring_index(screen->row_data,
- VteRowData *,
- screen->cursor_current.row);
+ rowdata = _vte_ring_index(screen->row_data, screen->cursor_current.row);
g_assert(rowdata != NULL);
col = screen->cursor_current.col;
len = rowdata->cells->len;
@@ -2872,7 +2866,7 @@ vte_sequence_handler_insert_lines (VteTerminal *terminal, GValueArray *params)
vte_remove_line_internal(terminal, end);
vte_insert_line_internal(terminal, row);
/* Get the data for the new row. */
- rowdata = _vte_ring_index(screen->row_data, VteRowData *, row);
+ rowdata = _vte_ring_index(screen->row_data, row);
g_assert(rowdata != NULL);
/* Add enough cells to it so that it has the default colors. */
vte_g_array_fill(rowdata->cells,
@@ -2921,7 +2915,7 @@ vte_sequence_handler_delete_lines (VteTerminal *terminal, GValueArray *params)
vte_remove_line_internal(terminal, row);
vte_insert_line_internal(terminal, end);
/* Get the data for the new row. */
- rowdata = _vte_ring_index(screen->row_data, VteRowData *, end);
+ rowdata = _vte_ring_index(screen->row_data, end);
g_assert(rowdata != NULL);
/* Add enough cells to it so that it has the default colors. */
vte_g_array_fill(rowdata->cells,
@@ -3096,7 +3090,7 @@ vte_sequence_handler_screen_alignment_test (VteTerminal *terminal, GValueArray *
_vte_ring_append(screen->row_data, rowdata);
}
_vte_terminal_adjust_adjustments(terminal);
- rowdata = _vte_ring_index(screen->row_data, VteRowData *, row);
+ rowdata = _vte_ring_index(screen->row_data, row);
g_assert(rowdata != NULL);
/* Clear this row. */
if (rowdata->cells->len > 0) {
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]