[vte] Revert b307bc5c and implement it in a clean way



commit f5ce4c445055b7f19db38fea0a79253d68ac6562
Author: Behdad Esfahbod <behdad behdad org>
Date:   Thu Aug 20 17:26:14 2009 -0400

    Revert b307bc5c and implement it in a clean way

 src/ring.c        |   68 ++++++++++++++--------------
 src/ring.h        |    8 ++--
 src/vte-private.h |    4 +-
 src/vte.c         |  132 +++++++++++++++++++++++++---------------------------
 src/vteseq.c      |   77 +++++++------------------------
 5 files changed, 120 insertions(+), 169 deletions(-)
---
diff --git a/src/ring.c b/src/ring.c
index f8b227d..c396462 100644
--- a/src/ring.c
+++ b/src/ring.c
@@ -85,16 +85,15 @@ _vte_ring_new_with_delta(glong max_elements, glong delta,
  * being replaced by the new @data.
  *
  */
-gpointer
+void
 _vte_ring_insert(VteRing * ring, long position, gpointer data)
 {
-	gpointer old_data = NULL;
 	long point, i;
 
-	g_return_val_if_fail(ring != NULL, NULL);
-	g_return_val_if_fail(position >= ring->delta, NULL);
-	g_return_val_if_fail(position <= ring->delta + ring->length, NULL);
-	g_return_val_if_fail(data != NULL, NULL);
+	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);
 
 	_vte_debug_print(VTE_DEBUG_RING,
 			"Inserting at position %ld.\n"
@@ -104,13 +103,20 @@ _vte_ring_insert(VteRing * ring, long position, gpointer data)
 
 	/* Initial insertion, or append. */
 	if (position == ring->length + ring->delta) {
-		i = position % ring->max;
-		old_data = ring->array[i];
+		/* 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);
+		}
 		/* 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[i] = data;
+		ring->array[position % ring->max] = data;
 		if (ring->length == ring->max) {
 			ring->delta++;
 			if (ring->delta > ring->cached_item) {
@@ -125,7 +131,7 @@ _vte_ring_insert(VteRing * ring, long position, gpointer data)
 				"Max = %ld.\n",
 				ring->delta, ring->length, ring->max);
 		_vte_ring_validate(ring);
-		return old_data;
+		return;
 	}
 
 	if (position <= ring->cached_item) {
@@ -143,7 +149,13 @@ _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*). */
-		old_data = ring->array[point % ring->max];
+		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);
+		}
 	} else {
 		/* We don't want to discard the last item. */
 		point++;
@@ -163,8 +175,6 @@ _vte_ring_insert(VteRing * ring, long position, gpointer data)
 			" Delta = %ld, Length = %ld, Max = %ld.\n",
 			ring->delta, ring->length, ring->max);
 	_vte_ring_validate(ring);
-
-	return old_data;
 }
 
 /**
@@ -179,14 +189,14 @@ _vte_ring_insert(VteRing * ring, long position, gpointer data)
  * from the *top*.
  *
  */
-gpointer
+void
 _vte_ring_insert_preserve(VteRing * ring, long position, gpointer data)
 {
 	long point, i;
-	gpointer **tmp, old_data = NULL;
+	gpointer **tmp;
 	gpointer *stack_tmp[128];
 
-	g_return_val_if_fail(position <= _vte_ring_next(ring), NULL);
+	g_return_if_fail(position <= _vte_ring_next(ring));
 
 	_vte_debug_print(VTE_DEBUG_RING,
 			"Inserting+ at position %ld.\n"
@@ -216,21 +226,16 @@ _vte_ring_insert_preserve(VteRing * ring, long position, gpointer data)
 	}
 
 	/* Append the new item. */
-	old_data = _vte_ring_append(ring, data);
+	_vte_ring_append(ring, data);
 
 	/* Append the old items. */
 	for (i = position; i < point; i++) {
-		if (old_data && ring->free) {
-			ring->free (old_data, ring->user_data);
-		}
-		old_data = _vte_ring_append(ring, tmp[i - position]);
+		_vte_ring_append(ring, tmp[i - position]);
 	}
 
 	/* Clean up. */
 	if (tmp != stack_tmp)
 		g_free(tmp);
-
-	return old_data;
 }
 
 /**
@@ -243,11 +248,10 @@ _vte_ring_insert_preserve(VteRing * ring, long position, gpointer data)
  * %TRUE.
  *
  */
-gpointer
+void
 _vte_ring_remove(VteRing * ring, long position, gboolean free_element)
 {
 	long i;
-	gpointer old_data;
 	_vte_debug_print(VTE_DEBUG_RING,
 			"Removing item at position %ld.\n"
 			" Delta = %ld, Length = %ld, Max = %ld.\n",
@@ -260,14 +264,12 @@ _vte_ring_remove(VteRing * ring, long position, gboolean free_element)
 
 	i = position % ring->max;
 	/* Remove the data at this position. */
-	old_data = ring->array[i];
-	if (free_element && old_data && ring->free) {
+	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(old_data, ring->user_data);
-		old_data = NULL;
+		ring->free(ring->array[position % ring->max], ring->user_data);
 	}
-	ring->array[i] = NULL;
+	ring->array[position % ring->max] = NULL;
 
 	/* Bubble the rest of the buffer up one notch.  This is also less
 	 * of a problem than it might appear, again due to usage patterns. */
@@ -285,8 +287,6 @@ _vte_ring_remove(VteRing * ring, long position, gboolean free_element)
 			" Delta = %ld, Length = %ld, Max = %ld.\n",
 			ring->delta, ring->length, ring->max);
 	_vte_ring_validate(ring);
-
-	return old_data;
 }
 
 /**
@@ -298,11 +298,11 @@ _vte_ring_remove(VteRing * ring, long position, gboolean free_element)
  * the new item, it is freed.
  *
  */
-gpointer
+void
 _vte_ring_append(VteRing * ring, gpointer data)
 {
 	g_assert(data != NULL);
-	return _vte_ring_insert(ring, ring->delta + ring->length, data);
+	_vte_ring_insert(ring, ring->delta + ring->length, data);
 }
 
 /**
diff --git a/src/ring.h b/src/ring.h
index 548c7c9..48a6e96 100644
--- a/src/ring.h
+++ b/src/ring.h
@@ -71,10 +71,10 @@ VteRing *_vte_ring_new(glong max_elements,
 		      gpointer data);
 VteRing *_vte_ring_new_with_delta(glong max_elements, glong delta,
 				  VteRingFreeFunc free_func, gpointer data);
-gpointer _vte_ring_insert(VteRing *ring, glong position, gpointer data);
-gpointer _vte_ring_insert_preserve(VteRing *ring, glong position, gpointer data);
-gpointer _vte_ring_remove(VteRing *ring, glong position, gboolean free_element);
-gpointer _vte_ring_append(VteRing *ring, gpointer data);
+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);
+void _vte_ring_append(VteRing *ring, gpointer data);
 void _vte_ring_free(VteRing *ring, gboolean free_elements);
 
 G_END_DECLS
diff --git a/src/vte-private.h b/src/vte-private.h
index 22f0434..65fe8ca 100644
--- a/src/vte-private.h
+++ b/src/vte-private.h
@@ -286,7 +286,7 @@ struct _VteTerminalPrivate {
 		GString *status_line_contents;
 		gboolean status_line_changed;
 	} normal_screen, alternate_screen, *screen;
-	VteRowData *free_row;
+	VteRowData *free_row;	/* cached VteRowData */
 
 	/* Selection information. */
 	GArray *word_chars;
@@ -442,8 +442,6 @@ void _vte_invalidate_cell(VteTerminal *terminal, glong col, glong row);
 void _vte_invalidate_cursor_once(VteTerminal *terminal, gboolean periodic);
 VteRowData * _vte_new_row_data(VteTerminal *terminal);
 VteRowData * _vte_new_row_data_sized(VteTerminal *terminal, gboolean fill);
-VteRowData * _vte_reset_row_data (VteTerminal *terminal, VteRowData *row, gboolean fill);
-void _vte_free_row_data(VteRowData *row);
 void _vte_terminal_adjust_adjustments(VteTerminal *terminal);
 void _vte_terminal_queue_contents_changed(VteTerminal *terminal);
 void _vte_terminal_emit_text_deleted(VteTerminal *terminal);
diff --git a/src/vte.c b/src/vte.c
index 36b0286..35d4ca8 100644
--- a/src/vte.c
+++ b/src/vte.c
@@ -279,14 +279,30 @@ 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};
 
-/* Free a no-longer-used row data array. */
-void
+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
@@ -302,11 +318,29 @@ vte_g_array_fill(GArray *array, gconstpointer item, guint final_size)
 	} while (--final_size);
 }
 
+static VteRowData *
+_vte_reset_row_data (VteTerminal *terminal, VteRowData *row, gboolean fill)
+{
+       g_array_set_size (row->cells, 0);
+       row->soft_wrapped = 0;
+       if (fill) {
+               vte_g_array_fill(row->cells,
+                               &terminal->pvt->screen->fill_defaults,
+                               terminal->column_count);
+       }
+       return row;
+}
+
 /* Allocate a new line. */
 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;
@@ -318,6 +352,11 @@ 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),
@@ -331,47 +370,23 @@ _vte_new_row_data_sized(VteTerminal *terminal, gboolean fill)
 	return row;
 }
 
-VteRowData *
-_vte_reset_row_data (VteTerminal *terminal, VteRowData *row, gboolean fill)
-{
-	g_array_set_size (row->cells, 0);
-	row->soft_wrapped = 0;
-	if (fill) {
-		vte_g_array_fill(row->cells,
-				&terminal->pvt->screen->fill_defaults,
-				terminal->column_count);
-	}
-	return row;
-}
-
 /* Insert a blank line at an arbitrary position. */
 static void
 vte_insert_line_internal(VteTerminal *terminal, glong position)
 {
-	VteRowData *row, *old_row;
-	old_row = terminal->pvt->free_row;
+	VteRowData *row;
 	/* Pad out the line data to the insertion point. */
 	while (_vte_ring_next(terminal->pvt->screen->row_data) < position) {
-		if (old_row) {
-			row = _vte_reset_row_data (terminal, old_row, TRUE);
-		} else {
-			row = _vte_new_row_data_sized(terminal, TRUE);
-		}
-		old_row = _vte_ring_append(terminal->pvt->screen->row_data, row);
-	}
-	/* If we haven't inserted a line yet, insert a new one. */
-	if (old_row) {
-		row = _vte_reset_row_data (terminal, old_row, TRUE);
-	} else {
 		row = _vte_new_row_data_sized(terminal, TRUE);
+		_vte_ring_append(terminal->pvt->screen->row_data, row);
 	}
+	/* If we haven't inserted a line yet, insert a new one. */
+	row = _vte_new_row_data_sized(terminal, TRUE);
 	if (_vte_ring_next(terminal->pvt->screen->row_data) >= position) {
-		old_row = _vte_ring_insert(terminal->pvt->screen->row_data,
-				 position, row);
+		_vte_ring_insert(terminal->pvt->screen->row_data, position, row);
 	} else {
-		old_row =_vte_ring_append(terminal->pvt->screen->row_data, row);
+		_vte_ring_append(terminal->pvt->screen->row_data, row);
 	}
-	terminal->pvt->free_row = old_row;
 }
 
 /* Remove a line at an arbitrary position. */
@@ -379,13 +394,7 @@ static void
 vte_remove_line_internal(VteTerminal *terminal, glong position)
 {
 	if (_vte_ring_next(terminal->pvt->screen->row_data) > position) {
-		if (terminal->pvt->free_row)
-			_vte_free_row_data (terminal->pvt->free_row);
-
-		terminal->pvt->free_row = _vte_ring_remove(
-				terminal->pvt->screen->row_data,
-				position,
-				FALSE);
+		_vte_ring_remove(terminal->pvt->screen->row_data, position, TRUE);
 	}
 }
 
@@ -2360,17 +2369,11 @@ static inline VteRowData*
 vte_terminal_insert_rows (VteTerminal *terminal, guint cnt)
 {
 	const VteScreen *screen = terminal->pvt->screen;
-	VteRowData *old_row, *row;
-	old_row = terminal->pvt->free_row;
+	VteRowData *row;
 	do {
-		if (old_row) {
-			row = _vte_reset_row_data (terminal, old_row, FALSE);
-		} else {
-			row = _vte_new_row_data_sized (terminal, FALSE);
-		}
-		old_row = _vte_ring_append(screen->row_data, row);
+		row = _vte_new_row_data_sized (terminal, FALSE);
+		_vte_ring_append(screen->row_data, row);
 	} while(--cnt);
-	terminal->pvt->free_row = old_row;
 	return row;
 }
 
@@ -2999,14 +3002,8 @@ _vte_terminal_cursor_down (VteTerminal *terminal)
 				 * to insert_delta. */
 				start++;
 				end++;
-				if (terminal->pvt->free_row) {
-					row = _vte_reset_row_data (terminal,
-							terminal->pvt->free_row,
-							FALSE);
-				} else {
-					row = _vte_new_row_data_sized(terminal, FALSE);
-				}
-				terminal->pvt->free_row = _vte_ring_insert_preserve(terminal->pvt->screen->row_data,
+				row = _vte_new_row_data_sized(terminal, FALSE);
+				_vte_ring_insert_preserve(terminal->pvt->screen->row_data,
 							  screen->cursor_current.row,
 							  row);
 				/* Force the areas below the region to be
@@ -7989,7 +7986,7 @@ vte_terminal_set_termcap(VteTerminal *terminal, const char *path,
 }
 
 static void
-vte_terminal_reset_rowdata(VteRing **ring, glong lines)
+vte_terminal_reset_rowdata(VteTerminal *terminal, VteRing **ring, glong lines)
 {
 	VteRing *new_ring;
 	VteRowData *row;
@@ -8003,16 +8000,13 @@ vte_terminal_reset_rowdata(VteRing **ring, glong lines)
 	}
 	new_ring = _vte_ring_new_with_delta(lines,
 					    *ring ? _vte_ring_delta(*ring) : 0,
-					    (GFunc) _vte_free_row_data,
-					    NULL);
+					    (GFunc) _vte_terminal_free_row_data_ring_callback,
+					    terminal);
 	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_append(new_ring, row);
-			if (row) {
-				_vte_free_row_data (row);
-			}
+			_vte_ring_append(new_ring, row);
 		}
 		_vte_ring_free(*ring, FALSE);
 	}
@@ -8093,14 +8087,14 @@ vte_terminal_init(VteTerminal *terminal)
         pvt->child_exit_status = 0;
 
 	/* Initialize the screens and histories. */
-	vte_terminal_reset_rowdata(&pvt->alternate_screen.row_data,
+	vte_terminal_reset_rowdata(terminal, &pvt->alternate_screen.row_data,
 				   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(&pvt->normal_screen.row_data,
+	vte_terminal_reset_rowdata(terminal, &pvt->normal_screen.row_data,
 				   VTE_SCROLLBACK_INIT);
 	pvt->normal_screen.sendrecv_mode = TRUE;
 	pvt->normal_screen.status_line_contents = g_string_new(NULL);
@@ -13213,7 +13207,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 (&screen->row_data, lines);
+		vte_terminal_reset_rowdata (terminal, &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);
@@ -13223,7 +13217,7 @@ vte_terminal_set_scrollback_lines(VteTerminal *terminal, glong lines)
 			_vte_ring_length (screen->row_data) = next - low;
 		}
 	} else {
-		vte_terminal_reset_rowdata (&screen->row_data,
+		vte_terminal_reset_rowdata (terminal, &screen->row_data,
 				terminal->row_count);
 		scroll_delta = _vte_ring_delta (screen->row_data);
 		screen->insert_delta = _vte_ring_delta (screen->row_data);
@@ -13508,11 +13502,11 @@ vte_terminal_reset(VteTerminal *terminal, gboolean full, gboolean 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_free_row_data, NULL);
+				      (GFunc) _vte_terminal_free_row_data_ring_callback, terminal);
 		_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_free_row_data, NULL);
+				      (GFunc) _vte_terminal_free_row_data_ring_callback, terminal);
 		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 92c9227..0bbf102 100644
--- a/src/vteseq.c
+++ b/src/vteseq.c
@@ -117,30 +117,20 @@ vte_g_array_fill(GArray *array, gpointer item, guint final_size)
 static void
 vte_insert_line_internal(VteTerminal *terminal, glong position)
 {
-	VteRowData *row, *old_row;
-	old_row = terminal->pvt->free_row;
+	VteRowData *row;
 	/* Pad out the line data to the insertion point. */
 	while (_vte_ring_next(terminal->pvt->screen->row_data) < position) {
-		if (old_row) {
-			row = _vte_reset_row_data (terminal, old_row, TRUE);
-		} else {
-			row = _vte_new_row_data_sized(terminal, TRUE);
-		}
-		old_row = _vte_ring_append(terminal->pvt->screen->row_data, row);
-	}
-	/* If we haven't inserted a line yet, insert a new one. */
-	if (old_row) {
-		row = _vte_reset_row_data (terminal, old_row, TRUE);
-	} else {
 		row = _vte_new_row_data_sized(terminal, TRUE);
+		_vte_ring_append(terminal->pvt->screen->row_data, row);
 	}
+	/* If we haven't inserted a line yet, insert a new one. */
+	row = _vte_new_row_data_sized(terminal, TRUE);
 	if (_vte_ring_next(terminal->pvt->screen->row_data) >= position) {
-		old_row = _vte_ring_insert(terminal->pvt->screen->row_data,
+		_vte_ring_insert(terminal->pvt->screen->row_data,
 				 position, row);
 	} else {
-		old_row =_vte_ring_append(terminal->pvt->screen->row_data, row);
+		_vte_ring_append(terminal->pvt->screen->row_data, row);
 	}
-	terminal->pvt->free_row = old_row;
 }
 
 /* Remove a line at an arbitrary position. */
@@ -148,13 +138,7 @@ static void
 vte_remove_line_internal(VteTerminal *terminal, glong position)
 {
 	if (_vte_ring_next(terminal->pvt->screen->row_data) > position) {
-		if (terminal->pvt->free_row)
-			_vte_free_row_data (terminal->pvt->free_row);
-
-		terminal->pvt->free_row = _vte_ring_remove(
-				terminal->pvt->screen->row_data,
-				position,
-				FALSE);
+		_vte_ring_remove(terminal->pvt->screen->row_data, position, TRUE);
 	}
 }
 
@@ -336,27 +320,21 @@ _vte_terminal_home_cursor (VteTerminal *terminal)
 static void
 _vte_terminal_clear_screen (VteTerminal *terminal)
 {
-	VteRowData *rowdata, *old_row;
+	VteRowData *rowdata;
 	long i, initial, row;
 	VteScreen *screen;
 	screen = terminal->pvt->screen;
 	initial = screen->insert_delta;
 	row = screen->cursor_current.row - screen->insert_delta;
 	/* Add a new screen's worth of rows. */
-	old_row = terminal->pvt->free_row;
 	for (i = 0; i < terminal->row_count; i++) {
 		/* Add a new row */
 		if (i == 0) {
 			initial = _vte_ring_next(screen->row_data);
 		}
-		if (old_row) {
-			rowdata = _vte_reset_row_data (terminal, old_row, TRUE);
-		} else {
-			rowdata = _vte_new_row_data_sized(terminal, TRUE);
-		}
-		old_row = _vte_ring_append(screen->row_data, rowdata);
+		rowdata = _vte_new_row_data_sized(terminal, TRUE);
+		_vte_ring_append(screen->row_data, rowdata);
 	}
-	terminal->pvt->free_row = old_row;
 	/* Move the cursor and insertion delta to the first line in the
 	 * newly-cleared area and scroll if need be. */
 	screen->insert_delta = initial;
@@ -444,7 +422,7 @@ _vte_terminal_clear_above_current (VteTerminal *terminal)
 static void
 _vte_terminal_scroll_text (VteTerminal *terminal, int scroll_amount)
 {
-	VteRowData *row, *old_row;
+	VteRowData *row;
 	long start, end, i;
 	VteScreen *screen;
 
@@ -458,16 +436,10 @@ _vte_terminal_scroll_text (VteTerminal *terminal, int scroll_amount)
 		end = start + terminal->row_count - 1;
 	}
 
-	old_row = terminal->pvt->free_row;
 	while (_vte_ring_next(screen->row_data) <= end) {
-		if (old_row) {
-			row = _vte_reset_row_data (terminal, old_row, FALSE);
-		} else {
-			row = _vte_new_row_data_sized(terminal, FALSE);
-		}
-		old_row = _vte_ring_append(terminal->pvt->screen->row_data, row);
+		row = _vte_new_row_data_sized(terminal, FALSE);
+		_vte_ring_append(terminal->pvt->screen->row_data, row);
 	}
-	terminal->pvt->free_row = old_row;
 	if (scroll_amount > 0) {
 		for (i = 0; i < scroll_amount; i++) {
 			vte_remove_line_internal(terminal, end);
@@ -1176,15 +1148,8 @@ vte_sequence_handler_cd (VteTerminal *terminal, GValueArray *params)
 						  VteRowData *, i);
 			g_assert(rowdata != NULL);
 		} else {
-			if (terminal->pvt->free_row) {
-				rowdata = _vte_reset_row_data (terminal,
-						terminal->pvt->free_row,
-						FALSE);
-			} else {
-				rowdata = _vte_new_row_data(terminal);
-			}
-			terminal->pvt->free_row =
-				_vte_ring_append(screen->row_data, rowdata);
+			rowdata = _vte_new_row_data(terminal);
+			_vte_ring_append(screen->row_data, rowdata);
 		}
 		/* Pad out the row. */
 		vte_g_array_fill(rowdata->cells,
@@ -3116,7 +3081,7 @@ static void
 vte_sequence_handler_screen_alignment_test (VteTerminal *terminal, GValueArray *params)
 {
 	long row;
-	VteRowData *rowdata, *old_row;
+	VteRowData *rowdata;
 	VteScreen *screen;
 	struct vte_charcell cell;
 
@@ -3126,16 +3091,10 @@ vte_sequence_handler_screen_alignment_test (VteTerminal *terminal, GValueArray *
 	     row < terminal->pvt->screen->insert_delta + terminal->row_count;
 	     row++) {
 		/* Find this row. */
-		old_row = terminal->pvt->free_row;
 		while (_vte_ring_next(screen->row_data) <= row) {
-			if (old_row) {
-				rowdata = _vte_reset_row_data (terminal, old_row, FALSE);
-			} else {
-				rowdata = _vte_new_row_data(terminal);
-			}
-			old_row = _vte_ring_append(screen->row_data, rowdata);
+			rowdata = _vte_new_row_data(terminal);
+			_vte_ring_append(screen->row_data, rowdata);
 		}
-		terminal->pvt->free_row = old_row;
 		_vte_terminal_adjust_adjustments(terminal);
 		rowdata = _vte_ring_index(screen->row_data, VteRowData *, row);
 		g_assert(rowdata != NULL);



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