[vte] Move _vte_new_row_data() business into the ring



commit 440737678453a83e812ee60545369ec0e54a4759
Author: Behdad Esfahbod <behdad behdad org>
Date:   Fri Aug 21 21:01:17 2009 -0400

    Move _vte_new_row_data() business into the ring

 src/ring.c        |  239 +++++++++++++++++++++++++++-------------------------
 src/ring.h        |   61 +++++++++----
 src/vte-private.h |   34 --------
 src/vte.c         |   48 +++--------
 src/vteseq.c      |   38 +++------
 5 files changed, 192 insertions(+), 228 deletions(-)
---
diff --git a/src/ring.c b/src/ring.c
index 454a82f..9febd93 100644
--- a/src/ring.c
+++ b/src/ring.c
@@ -1,5 +1,5 @@
 /*
- * Copyright (C) 2002 Red Hat, Inc.
+ * Copyright (C) 2002,2009 Red Hat, Inc.
  *
  * This is free software; you can redistribute it and/or modify it under
  * the terms of the GNU Library General Public License as published by
@@ -14,17 +14,29 @@
  * You should have received a copy of the GNU Library General Public
  * License along with this program; if not, write to the Free Software
  * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
+ *
+ * Red Hat Author(s): Nalin Dahyabhai, Behdad Esfahbod
  */
 
 #include <config.h>
 #include <stdio.h>
-#include <string.h>
 #include <glib.h>
 #include "debug.h"
 #include "ring.h"
 
+
+static VteRowData *
+_vte_row_data_new (void)
+{
+	VteRowData *row = NULL;
+	row = g_slice_new(VteRowData);
+	row->cells = g_array_new(FALSE, TRUE, sizeof(struct vte_charcell));
+	row->soft_wrapped = 0;
+	return row;
+}
+
 static void
-_vte_free_row_data(VteRowData *row)
+_vte_row_data_free(VteRowData *row)
 {
 	if (!row)
 		return;
@@ -32,6 +44,7 @@ _vte_free_row_data(VteRowData *row)
 	g_slice_free(VteRowData, row);
 }
 
+
 #ifdef VTE_DEBUG
 static void
 _vte_ring_validate(VteRing * ring)
@@ -52,24 +65,50 @@ _vte_ring_validate(VteRing * ring)
 /**
  * _vte_ring_new:
  * @max_elements: the maximum size the new ring will be allowed to reach
- * @free_func: a #VteRingFreeFunc
- * @data: user data for @free
  *
- * Allocates a new ring capable of holding up to @max_elements elements at a
- * time, using @free to free them when they are removed from the ring.  The
- * @data pointer is passed to the @free callback whenever it is called.
+ * Allocates a new ring capable of holding up to @max_elements rows at a time.
  *
- * Returns: a new ring
+ * Returns: the new ring
  */
 VteRing *
-_vte_ring_new(glong max_elements)
+_vte_ring_new (glong max_elements)
 {
-	VteRing *ret = g_slice_new0(VteRing);
-	ret->max = MAX(max_elements, 2);
-	ret->array = g_malloc0(sizeof(VteRowData *) * ret->max);
-	return ret;
+	VteRing *ring = g_slice_new0(VteRing);
+	ring->max = MAX(max_elements, 2);
+	ring->array = g_malloc0(sizeof(VteRowData *) * ring->max);
+
+	_vte_debug_print(VTE_DEBUG_RING,
+			"New ring %p.\n"
+			" Delta = %ld, Length = %ld, Max = %ld.\n",
+			ring, ring->delta, ring->length, ring->max);
+	_vte_ring_validate(ring);
+
+	return ring;
 }
 
+/**
+ * _vte_ring_free:
+ * @ring: a #VteRing
+ *
+ * Frees the ring and each of the items it contains.
+ */
+void
+_vte_ring_free(VteRing *ring)
+{
+	glong i;
+	for (i = 0; i < ring->max; i++)
+		_vte_row_data_free (ring->array[i]);
+	g_free(ring->array);
+	g_slice_free(VteRing, ring);
+}
+
+/**
+ * _vte_ring_free:
+ * @ring: a #VteRing
+ * @max_elements: new maximum numbers of rows in the ring
+ *
+ * Changes the number of lines the ring can contain.
+ */
 void
 _vte_ring_resize(VteRing *ring, glong max_elements)
 {
@@ -81,6 +120,12 @@ _vte_ring_resize(VteRing *ring, glong max_elements)
 	if (ring->max == max_elements)
 		return;
 
+	_vte_debug_print(VTE_DEBUG_RING,
+			"Before resizing ring.\n"
+			" Delta = %ld, Length = %ld, Max = %ld.\n",
+			ring->delta, ring->length, ring->max);
+	_vte_ring_validate(ring);
+
 	old_max = ring->max;
 	old_array = ring->array;
 
@@ -89,7 +134,7 @@ _vte_ring_resize(VteRing *ring, glong max_elements)
 
 	end = ring->delta + ring->length;
 	for (position = ring->delta; position < end; position++) {
-		_vte_free_row_data (ring->array[position % ring->max]);
+		_vte_row_data_free (ring->array[position % ring->max]);
 		ring->array[position % ring->max] = old_array[position % old_max];
 	}
 
@@ -99,29 +144,32 @@ _vte_ring_resize(VteRing *ring, glong max_elements)
 	}
 
 	g_free (old_array);
-}
 
+	_vte_debug_print(VTE_DEBUG_RING,
+			"After resizing ring.\n"
+			" Delta = %ld, Length = %ld, Max = %ld.\n",
+			ring->delta, ring->length, ring->max);
+	_vte_ring_validate(ring);
+}
 
 /**
  * _vte_ring_insert:
  * @ring: a #VteRing
  * @position: an index
- * @data: the new item
  *
- * Inserts a new item (@data) into @ring at the @position'th offset.  If @ring
- * already has an item stored at the desired location, it will be freed before
- * being replaced by the new @data.
+ * Inserts a new, empty, row into @ring at the @position'th offset.
+ * XXX document how exactly this thing is supposed to work.
  *
+ * Return: the newly added row.
  */
-void
-_vte_ring_insert(VteRing * ring, long position, VteRowData * data)
+VteRowData *
+_vte_ring_insert(VteRing * ring, long position)
 {
 	long point, i;
+	VteRowData *row;
 
-	g_return_if_fail(ring != NULL);
-	g_return_if_fail(position >= ring->delta);
-	g_return_if_fail(position <= ring->delta + ring->length);
-	g_return_if_fail(data != NULL);
+	g_return_val_if_fail(position >= ring->delta, NULL);
+	g_return_val_if_fail(position <= ring->delta + ring->length, NULL);
 
 	_vte_debug_print(VTE_DEBUG_RING,
 			"Inserting at position %ld.\n"
@@ -132,37 +180,37 @@ _vte_ring_insert(VteRing * ring, long position, VteRowData * data)
 	/* Initial insertion, or append. */
 	if (position == ring->length + ring->delta) {
 		/* If there was something there before, free it. */
-		_vte_free_row_data (ring->array[position % ring->max]);
+		_vte_row_data_free (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
 		 * scrolls off the *top*. */
-		ring->array[position % ring->max] = data;
-		if (ring->length == ring->max) {
+		ring->array[position % ring->max] = row = _vte_row_data_new ();
+		if (ring->length == ring->max)
 			ring->delta++;
-		} else {
+		else
 			ring->length++;
-		}
+
 		_vte_debug_print(VTE_DEBUG_RING,
 				" Delta = %ld, Length = %ld, "
 				"Max = %ld.\n",
 				ring->delta, ring->length, ring->max);
 		_vte_ring_validate(ring);
-		return;
+
+		return row;
 	}
 
 	/* All other cases.  Calculate the location where the last "item" in the
 	 * buffer is going to end up in the array. */
 	point = ring->delta + ring->length - 1;
-	while (point < 0) {
+	while (point < 0)
 		point += ring->max;
-	}
 
 	if (ring->length == ring->max) {
 		/* 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*). */
-		_vte_free_row_data (ring->array[point % ring->max]);
+		_vte_row_data_free (ring->array[point % ring->max]);
 	} else {
 		/* We don't want to discard the last item. */
 		point++;
@@ -170,40 +218,40 @@ _vte_ring_insert(VteRing * ring, long position, VteRowData * data)
 
 	/* We need to bubble the remaining valid elements down.  This isn't as
 	 * slow as you probably think it is due to the pattern of usage. */
-	for (i = point; i > position; i--) {
+	for (i = point; i > position; i--)
 		ring->array[i % ring->max] = ring->array[(i - 1) % ring->max];
-	}
 
 	/* Store the new item and bump up the length, unless we've hit the
 	 * maximum length already. */
-	ring->array[position % ring->max] = data;
+	ring->array[position % ring->max] = row = _vte_row_data_new ();
 	ring->length = CLAMP(ring->length + 1, 0, ring->max);
 	_vte_debug_print(VTE_DEBUG_RING,
 			" Delta = %ld, Length = %ld, Max = %ld.\n",
 			ring->delta, ring->length, ring->max);
 	_vte_ring_validate(ring);
+
+	return row;
 }
 
 /**
  * _vte_ring_insert_preserve:
  * @ring: a #VteRing
  * @position: an index
- * @data: the new item
  *
- * Inserts a new item (@data) into @ring at the @position'th offset.  If @ring
+ * Inserts a new, empty, row into @ring at the @position'th offset.  If @ring
  * already has an item stored at the desired location, it (and any successive
  * items) will be moved down, items that need to be removed will be removed
  * from the *top*.
  *
+ * Return: the newly added row.
  */
-void
-_vte_ring_insert_preserve(VteRing * ring, long position, VteRowData * data)
+VteRowData *
+_vte_ring_insert_preserve(VteRing * ring, long position)
 {
-	long point, i;
-	VteRowData **tmp;
-	VteRowData *stack_tmp[128];
+	long i;
+	VteRowData *row;
 
-	g_return_if_fail(position <= _vte_ring_next(ring));
+	g_return_val_if_fail(position <= _vte_ring_next(ring), NULL);
 
 	_vte_debug_print(VTE_DEBUG_RING,
 			"Inserting+ at position %ld.\n"
@@ -211,48 +259,48 @@ _vte_ring_insert_preserve(VteRing * ring, long position, VteRowData * data)
 			position, ring->delta, ring->length, ring->max);
 	_vte_ring_validate(ring);
 
-	/* Allocate space to save existing elements. */
-	point = _vte_ring_next(ring);
-	i = MAX(1, point - position);
+	if (ring->length < ring->max)
+		return _vte_ring_insert (ring, position);
 
-	/* Save existing elements. */
-	tmp = stack_tmp;
-	if ((guint) i > G_N_ELEMENTS (stack_tmp))
-		tmp = g_new0(VteRowData *, i);
-	for (i = position; i < point; i++) {
-		tmp[i - position] = _vte_ring_index(ring, i);
-	}
+	/* Otherwise, we need to shift items back */
+	_vte_row_data_free (ring->array[ring->delta % ring->max]);
+	for (i = ring->delta; i < position; i++)
+		_vte_ring_index(ring, i) = _vte_ring_index(ring, i + 1);
+	_vte_ring_index(ring, position) = row = _vte_row_data_new ();
 
-	/* Remove the existing elements. */
-	for (i = point; i > position; i--) {
-		_vte_ring_remove(ring, i - 1, FALSE);
-	}
-
-	/* Append the new item. */
-	_vte_ring_append(ring, data);
+	_vte_debug_print(VTE_DEBUG_RING,
+			" Delta = %ld, Length = %ld, Max = %ld.\n",
+			ring->delta, ring->length, ring->max);
+	_vte_ring_validate(ring);
 
-	/* Append the old items. */
-	for (i = position; i < point; i++) {
-		_vte_ring_append(ring, tmp[i - position]);
-	}
+	return row;
+}
 
-	/* Clean up. */
-	if (tmp != stack_tmp)
-		g_free(tmp);
+/**
+ * _vte_ring_append:
+ * @ring: a #VteRing
+ * @data: the new item
+ *
+ * Appends a new item to the ring.  If an item must be removed to make room for
+ * the new item, it is freed.
+ *
+ * Return: the newly added row.
+ */
+VteRowData *
+_vte_ring_append(VteRing * ring)
+{
+	return _vte_ring_insert(ring, ring->delta + ring->length);
 }
 
 /**
  * _vte_ring_remove:
  * @ring: a #VteRing
  * @position: an index
- * @free_element: %TRUE if the item should be freed
- *
- * Removes the @position'th item from @ring, freeing it only if @free_element is
- * %TRUE.
  *
+ * Removes the @position'th item from @ring.
  */
 void
-_vte_ring_remove(VteRing * ring, long position, gboolean free_element)
+_vte_ring_remove(VteRing * ring, long position)
 {
 	long i;
 	_vte_debug_print(VTE_DEBUG_RING,
@@ -263,8 +311,7 @@ _vte_ring_remove(VteRing * ring, long position, gboolean free_element)
 
 	i = position % ring->max;
 	/* Remove the data at this position. */
-	if (free_element)
-		_vte_free_row_data (ring->array[position % ring->max]);
+	_vte_row_data_free (ring->array[position % ring->max]);
 	ring->array[position % ring->max] = NULL;
 
 	/* Bubble the rest of the buffer up one notch.  This is also less
@@ -284,41 +331,3 @@ _vte_ring_remove(VteRing * ring, long position, gboolean free_element)
 			ring->delta, ring->length, ring->max);
 	_vte_ring_validate(ring);
 }
-
-/**
- * _vte_ring_append:
- * @ring: a #VteRing
- * @data: the new item
- *
- * Appends a new item to the ring.  If an item must be removed to make room for
- * the new item, it is freed.
- *
- */
-void
-_vte_ring_append(VteRing * ring, VteRowData * data)
-{
-	g_assert(data != NULL);
-	_vte_ring_insert(ring, ring->delta + ring->length, data);
-}
-
-/**
- * _vte_ring_free:
- * @ring: a #VteRing
- * @free_elements: %TRUE if items in the ring should be freed
- *
- * Frees the ring and, optionally, each of the items it contains.
- *
- */
-void
-_vte_ring_free(VteRing *ring, gboolean free_elements)
-{
-	long i;
-	if (free_elements) {
-		for (i = 0; i < ring->max; i++) {
-			/* Remove this item. */
-			_vte_free_row_data (ring->array[i]);
-		}
-	}
-	g_free(ring->array);
-	g_slice_free(VteRing, ring);
-}
diff --git a/src/ring.h b/src/ring.h
index 23456d0..bdbc467 100644
--- a/src/ring.h
+++ b/src/ring.h
@@ -24,8 +24,44 @@
 
 #include <glib.h>
 
+#include "debug.h"
+#include "vteunistr.h"
+
 G_BEGIN_DECLS
 
+/* The structure we use to hold characters we're supposed to display -- this
+ * includes any supported visible attributes. */
+struct vte_charcell {
+	vteunistr c;		/* The Unicode string for the cell. */
+
+	struct vte_charcell_attr {
+		guint32 columns: 4;	/* Number of visible columns
+					   (as determined by g_unicode_iswide(c)).
+					   Also abused for tabs; bug 353610
+					   Keep at least 4 for tabs to work
+					   */
+		guint32 fore: 9;	/* Index into color palette */
+		guint32 back: 9;	/* Index into color palette. */
+
+		guint32 fragment: 1;	/* A continuation cell. */
+		guint32 standout: 1;	/* Single-bit attributes. */
+		guint32 underline: 1;
+		guint32 strikethrough: 1;
+
+		guint32 reverse: 1;
+		guint32 blink: 1;
+		guint32 half: 1;
+		guint32 bold: 1;
+
+		guint32 invisible: 1;
+		/* unused; bug 499893
+		guint32 protect: 1;
+		 */
+
+		/* 31 bits */
+	} attr;
+};
+
 typedef struct _VteRowData {
 	GArray *cells;
 	guchar soft_wrapped: 1;
@@ -45,28 +81,15 @@ struct _VteRing {
 #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 + 0)
-#ifdef VTE_DEBUG
-#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" \
-		  " at %d\n", \
-		  (__position), (__position) % (__ring)->max, \
-		  (__ring)->delta, (__ring)->length, (__ring)->max, \
-		  (__ring)->delta + (__ring)->length, \
-		  __LINE__), (VteRowData *) NULL))
-#else
-#define _vte_ring_index(__ring, __position) \
-	((__ring)->array[(__position) % (__ring)->max])
-#endif
+#define _vte_ring_index(__ring, __position) ((__ring)->array[(__position) % (__ring)->max])
 
 VteRing *_vte_ring_new(glong max_elements);
 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, VteRowData * data);
-void _vte_ring_free(VteRing *ring, gboolean free_elements);
+VteRowData *_vte_ring_insert(VteRing *ring, glong position);
+VteRowData *_vte_ring_insert_preserve(VteRing *ring, glong position);
+VteRowData *_vte_ring_append(VteRing *ring);
+void _vte_ring_remove(VteRing *ring, glong position);
+void _vte_ring_free(VteRing *ring);
 
 G_END_DECLS
 
diff --git a/src/vte-private.h b/src/vte-private.h
index a154cde..1227cb5 100644
--- a/src/vte-private.h
+++ b/src/vte-private.h
@@ -41,7 +41,6 @@
 #include <unistd.h>
 #include <glib/gi18n-lib.h>
 
-#include "vteunistr.h"
 #include "vte.h"
 #include "buffer.h"
 #include "debug.h"
@@ -96,39 +95,6 @@ G_BEGIN_DECLS
 #define I_(string) (g_intern_static_string(string))
 
 
-/* The structure we use to hold characters we're supposed to display -- this
- * includes any supported visible attributes. */
-struct vte_charcell {
-	vteunistr c;		/* The Unicode string for the cell. */
-
-	struct vte_charcell_attr {
-		guint32 columns: 4;	/* Number of visible columns
-					   (as determined by g_unicode_iswide(c)).
-					   Also abused for tabs; bug 353610
-					   Keep at least 4 for tabs to work
-					   */
-		guint32 fore: 9;	/* Index into color palette */
-		guint32 back: 9;	/* Index into color palette. */
-
-		guint32 fragment: 1;	/* A continuation cell. */
-		guint32 standout: 1;	/* Single-bit attributes. */
-		guint32 underline: 1;
-		guint32 strikethrough: 1;
-
-		guint32 reverse: 1;
-		guint32 blink: 1;
-		guint32 half: 1;
-		guint32 bold: 1;
-
-		guint32 invisible: 1;
-		/* unused; bug 499893
-		guint32 protect: 1;
-		 */
-
-		/* 31 bits */
-	} attr;
-};
-
 typedef enum {
         VTE_REGEX_GREGEX,
         VTE_REGEX_VTE,
diff --git a/src/vte.c b/src/vte.c
index 7bd002a..3264ca6 100644
--- a/src/vte.c
+++ b/src/vte.c
@@ -294,35 +294,18 @@ vte_g_array_fill(GArray *array, gconstpointer item, guint final_size)
 	} while (--final_size);
 }
 
-/* Allocate a new line. */
-VteRowData *
-_vte_new_row_data(VteTerminal *terminal)
-{
-	VteRowData *row = NULL;
-	row = g_slice_new(VteRowData);
-	row->cells = g_array_sized_new(FALSE, TRUE,
-				       sizeof(struct vte_charcell),
-				       terminal->column_count);
-	row->soft_wrapped = 0;
-	return row;
-}
-
 /* Insert a blank line at an arbitrary position. */
 static void
 vte_insert_line_internal(VteTerminal *terminal, glong position)
 {
-	VteRowData *row;
 	/* Pad out the line data to the insertion point. */
-	while (_vte_ring_next(terminal->pvt->screen->row_data) < position) {
-		row = _vte_new_row_data(terminal);
-		_vte_ring_append(terminal->pvt->screen->row_data, row);
-	}
+	while (_vte_ring_next(terminal->pvt->screen->row_data) < position)
+		_vte_ring_append(terminal->pvt->screen->row_data);
 	/* If we haven't inserted a line yet, insert a new one. */
-	row = _vte_new_row_data(terminal);
 	if (_vte_ring_next(terminal->pvt->screen->row_data) >= position) {
-		_vte_ring_insert(terminal->pvt->screen->row_data, position, row);
+		_vte_ring_insert(terminal->pvt->screen->row_data, position);
 	} else {
-		_vte_ring_append(terminal->pvt->screen->row_data, row);
+		_vte_ring_append(terminal->pvt->screen->row_data);
 	}
 }
 
@@ -330,9 +313,8 @@ vte_insert_line_internal(VteTerminal *terminal, glong position)
 static void
 vte_remove_line_internal(VteTerminal *terminal, glong position)
 {
-	if (_vte_ring_next(terminal->pvt->screen->row_data) > position) {
-		_vte_ring_remove(terminal->pvt->screen->row_data, position, TRUE);
-	}
+	if (_vte_ring_next(terminal->pvt->screen->row_data) > position)
+		_vte_ring_remove(terminal->pvt->screen->row_data, position);
 }
 
 
@@ -2305,11 +2287,10 @@ vte_terminal_get_encoding(VteTerminal *terminal)
 static inline VteRowData*
 vte_terminal_insert_rows (VteTerminal *terminal, guint cnt)
 {
-	const VteScreen *screen = terminal->pvt->screen;
 	VteRowData *row;
+	const VteScreen *screen = terminal->pvt->screen;
 	do {
-		row = _vte_new_row_data (terminal);
-		_vte_ring_append(screen->row_data, row);
+		row = _vte_ring_append(screen->row_data);
 	} while(--cnt);
 	return row;
 }
@@ -2898,7 +2879,6 @@ _vte_terminal_cleanup_tab_fragments_at_cursor (VteTerminal *terminal)
 void
 _vte_terminal_cursor_down (VteTerminal *terminal)
 {
-	VteRowData *row;
 	long start, end;
 	VteScreen *screen;
 
@@ -2933,10 +2913,8 @@ _vte_terminal_cursor_down (VteTerminal *terminal)
 				 * to insert_delta. */
 				start++;
 				end++;
-				row = _vte_new_row_data(terminal);
 				_vte_ring_insert_preserve(terminal->pvt->screen->row_data,
-							  screen->cursor_current.row,
-							  row);
+							  screen->cursor_current.row);
 				/* Force the areas below the region to be
 				 * redrawn -- they've moved. */
 				_vte_terminal_scroll_region(terminal, start,
@@ -8444,8 +8422,8 @@ 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);
+	_vte_ring_free(terminal->pvt->normal_screen.row_data);
+	_vte_ring_free(terminal->pvt->alternate_screen.row_data);
 
 	/* Clear the status lines. */
 	g_string_free(terminal->pvt->normal_screen.status_line_contents,
@@ -13393,9 +13371,9 @@ vte_terminal_reset(VteTerminal *terminal, gboolean full, gboolean clear_history)
 	terminal->pvt->alternate_screen.alternate_charset = FALSE;
 	/* Clear the scrollback buffers and reset the cursors. */
 	if (clear_history) {
-		_vte_ring_free(terminal->pvt->normal_screen.row_data, TRUE);
+		_vte_ring_free(terminal->pvt->normal_screen.row_data);
 		terminal->pvt->normal_screen.row_data = _vte_ring_new(terminal->pvt->scrollback_lines);
-		_vte_ring_free(terminal->pvt->alternate_screen.row_data, TRUE);
+		_vte_ring_free(terminal->pvt->alternate_screen.row_data);
 		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;
diff --git a/src/vteseq.c b/src/vteseq.c
index 50e951a..a13150b 100644
--- a/src/vteseq.c
+++ b/src/vteseq.c
@@ -117,18 +117,15 @@ vte_g_array_fill(GArray *array, gpointer item, guint final_size)
 static void
 vte_insert_line_internal(VteTerminal *terminal, glong position)
 {
-	VteRowData *row;
 	/* Pad out the line data to the insertion point. */
 	while (_vte_ring_next(terminal->pvt->screen->row_data) < position) {
-		row = _vte_new_row_data(terminal);
-		_vte_ring_append(terminal->pvt->screen->row_data, row);
+		_vte_ring_append(terminal->pvt->screen->row_data);
 	}
 	/* If we haven't inserted a line yet, insert a new one. */
-	row = _vte_new_row_data(terminal);
 	if (_vte_ring_next(terminal->pvt->screen->row_data) >= position) {
-		_vte_ring_insert(terminal->pvt->screen->row_data, position, row);
+		_vte_ring_insert(terminal->pvt->screen->row_data, position);
 	} else {
-		_vte_ring_append(terminal->pvt->screen->row_data, row);
+		_vte_ring_append(terminal->pvt->screen->row_data);
 	}
 }
 
@@ -136,9 +133,8 @@ vte_insert_line_internal(VteTerminal *terminal, glong position)
 static void
 vte_remove_line_internal(VteTerminal *terminal, glong position)
 {
-	if (_vte_ring_next(terminal->pvt->screen->row_data) > position) {
-		_vte_ring_remove(terminal->pvt->screen->row_data, position, TRUE);
-	}
+	if (_vte_ring_next(terminal->pvt->screen->row_data) > position)
+		_vte_ring_remove(terminal->pvt->screen->row_data, position);
 }
 
 /* Check how long a string of unichars is.  Slow version. */
@@ -319,7 +315,6 @@ _vte_terminal_home_cursor (VteTerminal *terminal)
 static void
 _vte_terminal_clear_screen (VteTerminal *terminal)
 {
-	VteRowData *rowdata;
 	long i, initial, row;
 	VteScreen *screen;
 	screen = terminal->pvt->screen;
@@ -327,10 +322,8 @@ _vte_terminal_clear_screen (VteTerminal *terminal)
 	row = screen->cursor_current.row - screen->insert_delta;
 	initial = _vte_ring_next(screen->row_data);
 	/* Add a new screen's worth of rows. */
-	for (i = 0; i < terminal->row_count; i++) {
-		rowdata = _vte_new_row_data(terminal);
-		_vte_ring_append(screen->row_data, rowdata);
-	}
+	for (i = 0; i < terminal->row_count; i++)
+		_vte_ring_append(screen->row_data);
 	/* Move the cursor and insertion delta to the first line in the
 	 * newly-cleared area and scroll if need be. */
 	screen->insert_delta = initial;
@@ -416,7 +409,6 @@ _vte_terminal_clear_above_current (VteTerminal *terminal)
 static void
 _vte_terminal_scroll_text (VteTerminal *terminal, int scroll_amount)
 {
-	VteRowData *row;
 	long start, end, i;
 	VteScreen *screen;
 
@@ -430,10 +422,9 @@ _vte_terminal_scroll_text (VteTerminal *terminal, int scroll_amount)
 		end = start + terminal->row_count - 1;
 	}
 
-	while (_vte_ring_next(screen->row_data) <= end) {
-		row = _vte_new_row_data(terminal);
-		_vte_ring_append(terminal->pvt->screen->row_data, row);
-	}
+	while (_vte_ring_next(screen->row_data) <= end)
+		_vte_ring_append(terminal->pvt->screen->row_data);
+
 	if (scroll_amount > 0) {
 		for (i = 0; i < scroll_amount; i++) {
 			vte_remove_line_internal(terminal, end);
@@ -1140,8 +1131,7 @@ vte_sequence_handler_cd (VteTerminal *terminal, GValueArray *params)
 			rowdata = _vte_ring_index(screen->row_data, i);
 			g_assert(rowdata != NULL);
 		} else {
-			rowdata = _vte_new_row_data(terminal);
-			_vte_ring_append(screen->row_data, rowdata);
+			rowdata = _vte_ring_append(screen->row_data);
 		}
 		/* Pad out the row. */
 		vte_g_array_fill(rowdata->cells,
@@ -3081,10 +3071,8 @@ vte_sequence_handler_screen_alignment_test (VteTerminal *terminal, GValueArray *
 	     row < terminal->pvt->screen->insert_delta + terminal->row_count;
 	     row++) {
 		/* Find this row. */
-		while (_vte_ring_next(screen->row_data) <= row) {
-			rowdata = _vte_new_row_data(terminal);
-			_vte_ring_append(screen->row_data, rowdata);
-		}
+		while (_vte_ring_next(screen->row_data) <= row)
+			_vte_ring_append(screen->row_data);
 		_vte_terminal_adjust_adjustments(terminal);
 		rowdata = _vte_ring_index(screen->row_data, row);
 		g_assert(rowdata != NULL);



[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]