[vte] Add _vte_ring_resize()
- From: Behdad Esfahbod <behdad src gnome org>
- To: svn-commits-list gnome org
- Cc:
- Subject: [vte] Add _vte_ring_resize()
- Date: Fri, 21 Aug 2009 18:12:29 +0000 (UTC)
commit 031a653d791248c51df12af1b59d169179330b55
Author: Behdad Esfahbod <behdad behdad org>
Date: Fri Aug 21 14:09:44 2009 -0400
Add _vte_ring_resize()
Avoids creating a new ring when changing scrollback lines.
src/ring.c | 43 +++++++++++++++++++++++++++++++++----------
src/ring.h | 16 ++++++++--------
src/vte.c | 36 ++++--------------------------------
3 files changed, 45 insertions(+), 50 deletions(-)
---
diff --git a/src/ring.c b/src/ring.c
index a3c4859..454a82f 100644
--- a/src/ring.c
+++ b/src/ring.c
@@ -66,19 +66,42 @@ _vte_ring_new(glong max_elements)
{
VteRing *ret = g_slice_new0(VteRing);
ret->max = MAX(max_elements, 2);
- ret->array = g_malloc0(sizeof(gpointer) * ret->max);
+ ret->array = g_malloc0(sizeof(VteRowData *) * ret->max);
return ret;
}
-VteRing *
-_vte_ring_new_with_delta(glong max_elements, glong delta)
+void
+_vte_ring_resize(VteRing *ring, glong max_elements)
{
- VteRing *ret;
- ret = _vte_ring_new(max_elements);
- ret->delta = delta;
- return ret;
+ glong position, end, old_max;
+ VteRowData **old_array;
+
+ max_elements = MAX(max_elements, 2);
+
+ if (ring->max == max_elements)
+ return;
+
+ old_max = ring->max;
+ old_array = ring->array;
+
+ ring->max = max_elements;
+ ring->array = g_malloc0(sizeof(VteRowData *) * ring->max);
+
+ end = ring->delta + ring->length;
+ for (position = ring->delta; position < end; position++) {
+ _vte_free_row_data (ring->array[position % ring->max]);
+ ring->array[position % ring->max] = old_array[position % old_max];
+ }
+
+ if (ring->length > ring->max) {
+ ring->length = ring->max;
+ ring->delta = end - ring->max;
+ }
+
+ g_free (old_array);
}
+
/**
* _vte_ring_insert:
* @ring: a #VteRing
@@ -91,7 +114,7 @@ _vte_ring_new_with_delta(glong max_elements, glong delta)
*
*/
void
-_vte_ring_insert(VteRing * ring, long position, gpointer data)
+_vte_ring_insert(VteRing * ring, long position, VteRowData * data)
{
long point, i;
@@ -174,7 +197,7 @@ _vte_ring_insert(VteRing * ring, long position, gpointer data)
*
*/
void
-_vte_ring_insert_preserve(VteRing * ring, long position, gpointer data)
+_vte_ring_insert_preserve(VteRing * ring, long position, VteRowData * data)
{
long point, i;
VteRowData **tmp;
@@ -272,7 +295,7 @@ _vte_ring_remove(VteRing * ring, long position, gboolean free_element)
*
*/
void
-_vte_ring_append(VteRing * ring, gpointer data)
+_vte_ring_append(VteRing * ring, VteRowData * data)
{
g_assert(data != NULL);
_vte_ring_insert(ring, ring->delta + ring->length, data);
diff --git a/src/ring.h b/src/ring.h
index 55d7c18..23456d0 100644
--- a/src/ring.h
+++ b/src/ring.h
@@ -41,10 +41,10 @@ struct _VteRing {
#define _vte_ring_contains(__ring, __position) \
(((__position) >= (__ring)->delta) && \
((__position) < (__ring)->delta + (__ring)->length))
-#define _vte_ring_delta(__ring) ((__ring)->delta)
-#define _vte_ring_length(__ring) ((__ring)->length)
+#define _vte_ring_delta(__ring) ((__ring)->delta + 0)
+#define _vte_ring_length(__ring) ((__ring)->length /* + 0 XXX */)
#define _vte_ring_next(__ring) ((__ring)->delta + (__ring)->length)
-#define _vte_ring_max(__ring) ((__ring)->max)
+#define _vte_ring_max(__ring) ((__ring)->max + 0)
#ifdef VTE_DEBUG
#define _vte_ring_index(__ring, __position) \
((__ring)->array[(__position) % (__ring)->max] ? \
@@ -54,18 +54,18 @@ struct _VteRing {
(__position), (__position) % (__ring)->max, \
(__ring)->delta, (__ring)->length, (__ring)->max, \
(__ring)->delta + (__ring)->length, \
- __LINE__), (gpointer) NULL))
+ __LINE__), (VteRowData *) NULL))
#else
#define _vte_ring_index(__ring, __position) \
((__ring)->array[(__position) % (__ring)->max])
#endif
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_resize(VteRing *ring, glong max_elements);
+void _vte_ring_insert(VteRing *ring, glong position, VteRowData * data);
+void _vte_ring_insert_preserve(VteRing *ring, glong position, VteRowData * data);
void _vte_ring_remove(VteRing *ring, glong position, gboolean free_element);
-void _vte_ring_append(VteRing *ring, gpointer data);
+void _vte_ring_append(VteRing *ring, VteRowData * data);
void _vte_ring_free(VteRing *ring, gboolean free_elements);
G_END_DECLS
diff --git a/src/vte.c b/src/vte.c
index a55c748..7bd002a 100644
--- a/src/vte.c
+++ b/src/vte.c
@@ -7914,31 +7914,6 @@ vte_terminal_set_termcap(VteTerminal *terminal, const char *path,
}
static void
-vte_terminal_reset_rowdata(VteTerminal *terminal, VteRing **ring, glong lines)
-{
- VteRing *new_ring;
- VteRowData *row;
- long i, next;
-
- _vte_debug_print(VTE_DEBUG_MISC,
- "Sizing scrollback buffer to %ld lines.\n",
- lines);
- if (*ring && (_vte_ring_max(*ring) == lines)) {
- return;
- }
- 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, i);
- _vte_ring_append(new_ring, row);
- }
- _vte_ring_free(*ring, FALSE);
- }
- *ring = new_ring;
-}
-
-static void
_vte_terminal_codeset_changed_cb(struct _vte_iso2022_state *state, gpointer p)
{
vte_terminal_set_encoding(p, _vte_iso2022_state_get_codeset(state));
@@ -8012,15 +7987,13 @@ vte_terminal_init(VteTerminal *terminal)
pvt->child_exit_status = 0;
/* Initialize the screens and histories. */
- vte_terminal_reset_rowdata(terminal, &pvt->alternate_screen.row_data,
- VTE_SCROLLBACK_INIT);
+ pvt->alternate_screen.row_data = _vte_ring_new (VTE_SCROLLBACK_INIT);
pvt->alternate_screen.sendrecv_mode = TRUE;
pvt->alternate_screen.status_line_contents = g_string_new(NULL);
pvt->screen = &terminal->pvt->alternate_screen;
_vte_terminal_set_default_attributes(terminal);
- vte_terminal_reset_rowdata(terminal, &pvt->normal_screen.row_data,
- VTE_SCROLLBACK_INIT);
+ pvt->normal_screen.row_data = _vte_ring_new (VTE_SCROLLBACK_INIT);
pvt->normal_screen.sendrecv_mode = TRUE;
pvt->normal_screen.status_line_contents = g_string_new(NULL);
pvt->screen = &terminal->pvt->normal_screen;
@@ -13129,7 +13102,7 @@ vte_terminal_set_scrollback_lines(VteTerminal *terminal, glong lines)
lines = MAX (lines, terminal->row_count);
next = MAX (screen->cursor_current.row + 1,
_vte_ring_next (screen->row_data));
- vte_terminal_reset_rowdata (terminal, &screen->row_data, lines);
+ _vte_ring_resize (screen->row_data, lines);
low = _vte_ring_delta (screen->row_data);
high = low + lines - terminal->row_count + 1;
screen->insert_delta = CLAMP (screen->insert_delta, low, high);
@@ -13139,8 +13112,7 @@ vte_terminal_set_scrollback_lines(VteTerminal *terminal, glong lines)
_vte_ring_length (screen->row_data) = next - low;
}
} else {
- vte_terminal_reset_rowdata (terminal, &screen->row_data,
- terminal->row_count);
+ _vte_ring_resize (screen->row_data, terminal->row_count);
scroll_delta = _vte_ring_delta (screen->row_data);
screen->insert_delta = _vte_ring_delta (screen->row_data);
if (_vte_ring_next (screen->row_data) > screen->insert_delta + terminal->row_count){
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]