[vte] [ring] Simplify insert and remove even more
- From: Behdad Esfahbod <behdad src gnome org>
- To: svn-commits-list gnome org
- Cc:
- Subject: [vte] [ring] Simplify insert and remove even more
- Date: Thu, 27 Aug 2009 17:45:00 +0000 (UTC)
commit 545fb3c59298058a682879545ff52230054642a6
Author: Behdad Esfahbod <behdad behdad org>
Date: Wed Aug 26 00:24:09 2009 -0400
[ring] Simplify insert and remove even more
src/ring.c | 41 ++++++++++++++++++++++++++++++-----------
src/vte.c | 24 ++++--------------------
src/vteseq.c | 44 ++++++++++++++------------------------------
3 files changed, 48 insertions(+), 61 deletions(-)
---
diff --git a/src/ring.c b/src/ring.c
index 10a8736..5793e6c 100644
--- a/src/ring.c
+++ b/src/ring.c
@@ -38,7 +38,7 @@ _vte_row_data_init (VteRowData *row)
}
static void
-_vte_row_data_fini(VteRowData *row)
+_vte_row_data_fini (VteRowData *row)
{
if (row->cells)
g_array_free(row->cells, TRUE);
@@ -46,7 +46,7 @@ _vte_row_data_fini(VteRowData *row)
}
static void
-_vte_ring_move(VteRing *ring, unsigned int to, unsigned int from)
+_vte_ring_move (VteRing *ring, unsigned int to, unsigned int from)
{
_vte_row_data_fini (&ring->array[to]);
ring->array[to] = ring->array[from];
@@ -56,7 +56,7 @@ _vte_ring_move(VteRing *ring, unsigned int to, unsigned int from)
#ifdef VTE_DEBUG
static void
-_vte_ring_validate(VteRing * ring)
+_vte_ring_validate (VteRing * ring)
{
long i, max;
g_assert(ring != NULL);
@@ -102,7 +102,7 @@ _vte_ring_new (glong max_elements)
* Frees the ring and each of the items it contains.
*/
void
-_vte_ring_free(VteRing *ring)
+_vte_ring_free (VteRing *ring)
{
glong i;
for (i = 0; i < ring->max; i++)
@@ -119,7 +119,7 @@ _vte_ring_free(VteRing *ring)
* Changes the number of lines the ring can contain.
*/
void
-_vte_ring_resize(VteRing *ring, glong max_elements)
+_vte_ring_resize (VteRing *ring, glong max_elements)
{
glong position, end, old_max;
VteRowData *old_array;
@@ -155,7 +155,7 @@ _vte_ring_resize(VteRing *ring, glong max_elements)
}
/**
- * _vte_ring_insert:
+ * _vte_ring_insert_internal:
* @ring: a #VteRing
* @position: an index
*
@@ -164,8 +164,8 @@ _vte_ring_resize(VteRing *ring, glong max_elements)
*
* Return: the newly added row.
*/
-VteRowData *
-_vte_ring_insert(VteRing * ring, long position)
+static VteRowData *
+_vte_ring_insert_internal (VteRing * ring, long position)
{
long i;
VteRowData *row;
@@ -190,6 +190,25 @@ _vte_ring_insert(VteRing * ring, long position)
}
/**
+ * _vte_ring_insert:
+ * @ring: a #VteRing
+ * @data: the new item
+ *
+ * Inserts a new, empty, row into @ring at the @position'th offset.
+ * The item at that position and any items after that are shifted down.
+ * It pads enough lines if @position is after the end of the ring.
+ *
+ * Return: the newly added row.
+ */
+VteRowData *
+_vte_ring_insert (VteRing *ring, glong position)
+{
+ while (G_UNLIKELY (_vte_ring_next (ring) < position))
+ _vte_ring_append (ring);
+ return _vte_ring_insert_internal (ring, position);
+}
+
+/**
* _vte_ring_append:
* @ring: a #VteRing
* @data: the new item
@@ -199,9 +218,9 @@ _vte_ring_insert(VteRing * ring, long position)
* Return: the newly added row.
*/
VteRowData *
-_vte_ring_append(VteRing * ring)
+_vte_ring_append (VteRing * ring)
{
- return _vte_ring_insert(ring, ring->delta + ring->length);
+ return _vte_ring_insert_internal (ring, ring->delta + ring->length);
}
/**
@@ -212,7 +231,7 @@ _vte_ring_append(VteRing * ring)
* Removes the @position'th item from @ring.
*/
void
-_vte_ring_remove(VteRing * ring, long position)
+_vte_ring_remove (VteRing * ring, long position)
{
long i;
diff --git a/src/vte.c b/src/vte.c
index fca1fb4..6e46ffd 100644
--- a/src/vte.c
+++ b/src/vte.c
@@ -294,22 +294,6 @@ vte_g_array_fill(GArray *array, gconstpointer item, guint final_size)
} while (--final_size);
}
-/* Insert a blank line at an arbitrary position. */
-static VteRowData *
-vte_insert_line_internal(VteTerminal *terminal, glong position)
-{
- while (_vte_ring_next(terminal->pvt->screen->row_data) < position)
- _vte_ring_append(terminal->pvt->screen->row_data);
- return _vte_ring_insert(terminal->pvt->screen->row_data, position);
-}
-
-/* Remove a line at an arbitrary position. */
-static void
-vte_remove_line_internal(VteTerminal *terminal, glong position)
-{
- _vte_ring_remove(terminal->pvt->screen->row_data, position);
-}
-
/* Reset defaults for character insertion. */
void
@@ -2906,8 +2890,8 @@ _vte_terminal_cursor_down (VteTerminal *terminal)
* to insert_delta. */
start++;
end++;
- _vte_ring_insert(terminal->pvt->screen->row_data,
- screen->cursor_current.row);
+ _vte_ring_insert (terminal->pvt->screen->row_data,
+ screen->cursor_current.row);
/* Force the areas below the region to be
* redrawn -- they've moved. */
_vte_terminal_scroll_region(terminal, start,
@@ -2918,8 +2902,8 @@ _vte_terminal_cursor_down (VteTerminal *terminal)
/* If we're at the bottom of the scrolling
* region, add a line at the top to scroll the
* bottom off. */
- vte_remove_line_internal(terminal, start);
- vte_insert_line_internal(terminal, end);
+ _vte_ring_remove (terminal->pvt->screen->row_data, start);
+ _vte_ring_insert (terminal->pvt->screen->row_data, end);
/* Update the display. */
_vte_terminal_scroll_region(terminal, start,
end - start + 1, -1);
diff --git a/src/vteseq.c b/src/vteseq.c
index 377e2b3..1b518a5 100644
--- a/src/vteseq.c
+++ b/src/vteseq.c
@@ -113,22 +113,6 @@ vte_g_array_fill(GArray *array, gpointer item, guint final_size)
} while (--final_size);
}
-/* Insert a blank line at an arbitrary position. */
-static VteRowData *
-vte_insert_line_internal(VteTerminal *terminal, glong position)
-{
- while (_vte_ring_next(terminal->pvt->screen->row_data) < position)
- _vte_ring_append(terminal->pvt->screen->row_data);
- return _vte_ring_insert(terminal->pvt->screen->row_data, position);
-}
-
-/* Remove a line at an arbitrary position. */
-static void
-vte_remove_line_internal(VteTerminal *terminal, glong position)
-{
- _vte_ring_remove(terminal->pvt->screen->row_data, position);
-}
-
/* Check how long a string of unichars is. Slow version. */
static gssize
vte_unichar_strlen(gunichar *c)
@@ -419,13 +403,13 @@ _vte_terminal_scroll_text (VteTerminal *terminal, int scroll_amount)
if (scroll_amount > 0) {
for (i = 0; i < scroll_amount; i++) {
- vte_remove_line_internal(terminal, end);
- vte_insert_line_internal(terminal, start);
+ _vte_ring_remove (terminal->pvt->screen->row_data, end);
+ _vte_ring_insert (terminal->pvt->screen->row_data, start);
}
} else {
for (i = 0; i < -scroll_amount; i++) {
- vte_remove_line_internal(terminal, start);
- vte_insert_line_internal(terminal, end);
+ _vte_ring_remove (terminal->pvt->screen->row_data, start);
+ _vte_ring_insert (terminal->pvt->screen->row_data, end);
}
}
@@ -972,8 +956,8 @@ vte_sequence_handler_al (VteTerminal *terminal, GValueArray *params)
for (i = 0; i < param; i++) {
/* Clear a line off the end of the region and add one to the
* top of the region. */
- vte_remove_line_internal(terminal, end);
- rowdata = vte_insert_line_internal(terminal, start);
+ _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);
@@ -1472,8 +1456,8 @@ vte_sequence_handler_dl (VteTerminal *terminal, GValueArray *params)
for (i = 0; i < param; i++) {
/* Clear a line off the end of the region and add one to the
* top of the region. */
- vte_remove_line_internal(terminal, start);
- vte_insert_line_internal(terminal, end);
+ _vte_ring_remove (terminal->pvt->screen->row_data, start);
+ _vte_ring_insert (terminal->pvt->screen->row_data, end);
/* Adjust the scrollbars if necessary. */
_vte_terminal_adjust_adjustments(terminal);
}
@@ -2045,8 +2029,8 @@ vte_sequence_handler_sr (VteTerminal *terminal, GValueArray *params)
if (screen->cursor_current.row == start) {
/* If we're at the top of the scrolling region, add a
* line at the top to scroll the bottom off. */
- vte_remove_line_internal(terminal, end);
- vte_insert_line_internal(terminal, start);
+ _vte_ring_remove (terminal->pvt->screen->row_data, end);
+ _vte_ring_insert (terminal->pvt->screen->row_data, start);
/* Update the display. */
_vte_terminal_scroll_region(terminal, start, end - start + 1, 1);
_vte_invalidate_cells(terminal,
@@ -2838,8 +2822,8 @@ vte_sequence_handler_insert_lines (VteTerminal *terminal, GValueArray *params)
for (i = 0; i < param; i++) {
/* Clear a line off the end of the region and add one to the
* top of the region. */
- vte_remove_line_internal(terminal, end);
- rowdata = vte_insert_line_internal(terminal, row);
+ _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,
@@ -2884,8 +2868,8 @@ vte_sequence_handler_delete_lines (VteTerminal *terminal, GValueArray *params)
for (i = 0; i < param; i++) {
/* Insert a line at the end of the region and remove one from
* the top of the region. */
- vte_remove_line_internal(terminal, row);
- rowdata = vte_insert_line_internal(terminal, end);
+ _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,
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]