[vte/wip/egmont/bidi: 95/107] etap6
- From: Egmont Koblinger <egmontkob src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [vte/wip/egmont/bidi: 95/107] etap6
- Date: Thu, 30 May 2019 13:49:31 +0000 (UTC)
commit 99e1e2a6cb1a3864df0e43097a826046371481a1
Author: Egmont Koblinger <egmont gmail com>
Date: Fri May 24 12:39:11 2019 +0200
etap6
src/ringview.cc | 71 ++++++++++++++++++++++++++++-----------------------------
1 file changed, 35 insertions(+), 36 deletions(-)
---
diff --git a/src/ringview.cc b/src/ringview.cc
index cd1ee311..a62bafb0 100644
--- a/src/ringview.cc
+++ b/src/ringview.cc
@@ -20,16 +20,16 @@
* RingView provides a "view" to a continuous segment of the Ring (or stream),
* typically the user visible area.
*
- * It computes additional data that are necessary to display the contents
- * properly, but are not needed for the terminal emulation logic. In order to
- * save tons of resources, these data are computed when the Ring's contents are
- * about to be displayed, rather than whenever they change.
+ * It computes additional data that are needed to display the contents (or handle
+ * user events such as mouse click), but not needed for the terminal emulation logic.
+ * In order to save tons of resources, these data are computed when the Ring's
+ * contents are about to be displayed, rather than whenever they change.
*
- * In addition to the area covered by the Ringview, context lines are also
- * taken into account up to the next hard newline or a safety limit.
+ * For computing these data, context lines (outside of the specified region of the
+ * Ring) are also taken into account up to the next hard newline or a safety limit.
*
- * Currently RingView is used for BiDi: to figure out which character is mapped
- * to which visual position.
+ * Currently RingView is used for BiDi: to figure out which logical character is
+ * mapped to which visual position.
*
* Future possible uses include "highlight all" for the search match, and
* syntax highlighting. URL autodetection might also be ported to this
@@ -38,19 +38,11 @@
#include <config.h>
-#ifdef WITH_FRIBIDI
-#include <fribidi.h>
-#endif
-
#include "bidi.hh"
#include "debug.h"
#include "vtedefines.hh"
#include "vteinternal.hh"
-#ifdef WITH_FRIBIDI
-static_assert (sizeof (gunichar) == sizeof (FriBidiChar), "Whoooo");
-#endif
-
using namespace vte::base;
RingView::RingView()
@@ -71,49 +63,53 @@ RingView::~RingView()
delete m_bidirunner;
}
-/* Pausing a RingView frees up pretty much all of its memory. This is to be
- * used when the terminal is unlikely to be painted in the near future, e.g.
- * the widget is unmapped. Not to be called too frequently, in order to avoid
- * memory fragmentation. The RingView is unpaused automatically on demand.
+/* Pausing a RingView frees up pretty much all of its memory.
+ *
+ * This is to be used when the terminal is unlikely to be painted or interacted with
+ * in the near future, e.g. the widget is unmapped. Not to be called too frequently,
+ * in order to avoid memory fragmentation.
+ *
+ * The RingView is unpaused automatically on demand.
*/
void RingView::pause()
{
if (m_paused)
return;
- for (int i = 0; i < m_bidirows_alloc_len; i++) {
- delete m_bidirows[i];
- }
- g_free (m_bidirows);
- m_bidirows_alloc_len = 0;
-
for (int i = 0; i < m_rows_alloc_len; i++) {
_vte_row_data_fini(m_rows[i]);
}
g_free (m_rows);
m_rows_alloc_len = 0;
+ for (int i = 0; i < m_bidirows_alloc_len; i++) {
+ delete m_bidirows[i];
+ }
+ g_free (m_bidirows);
+ m_bidirows_alloc_len = 0;
+
m_invalid = true;
m_paused = true;
}
+/* Allocate (again) the required memory. */
void RingView::unpause()
{
g_assert_cmpint (m_len, >=, 1);
- m_bidirows_alloc_len = m_len;
- m_bidirows = (BidiRow **) g_malloc (sizeof (BidiRow *) * m_bidirows_alloc_len);
- for (int i = 0; i < m_bidirows_alloc_len; i++) {
- m_bidirows[i] = new BidiRow();
- }
-
- m_rows_alloc_len = m_len + 10; /* a bit of random heuristics */
+ m_rows_alloc_len = m_len + 16; /* a bit of random heuristics for context lines */
m_rows = (VteRowData **) g_malloc (sizeof (VteRowData *) * m_rows_alloc_len);
for (int i = 0; i < m_rows_alloc_len; i++) {
m_rows[i] = (VteRowData *) malloc (sizeof (VteRowData));
_vte_row_data_init (m_rows[i]);
}
+ m_bidirows_alloc_len = m_len;
+ m_bidirows = (BidiRow **) g_malloc (sizeof (BidiRow *) * m_bidirows_alloc_len);
+ for (int i = 0; i < m_bidirows_alloc_len; i++) {
+ m_bidirows[i] = new BidiRow();
+ }
+
m_invalid = true;
m_paused = false;
}
@@ -143,10 +139,13 @@ void RingView::set_rows(vte::grid::row_t start, vte::grid::row_t len)
if (start == m_start && len == m_len)
return;
+ /* m_rows is expended on demand in update() */
+
+ /* m_bidirows needs exactly these many lines */
if (G_UNLIKELY (!m_paused && len > m_bidirows_alloc_len)) {
int i = m_bidirows_alloc_len;
while (len > m_bidirows_alloc_len) {
- m_bidirows_alloc_len *= 2;
+ m_bidirows_alloc_len *= 1.25 /* whatever */;
}
m_bidirows = (BidiRow **) g_realloc (m_bidirows, sizeof (BidiRow *) * m_bidirows_alloc_len);
for (; i < m_bidirows_alloc_len; i++) {
@@ -199,7 +198,7 @@ void RingView::maybe_update()
m_top = row;
while (row < m_start + m_len) {
if (m_rows_len == m_rows_alloc_len) {
- m_rows_alloc_len *= 2;
+ m_rows_alloc_len *= 1.25 /* whatever */;
m_rows = (VteRowData **) g_realloc (m_rows, sizeof (VteRowData *) *
m_rows_alloc_len);
for (int j = m_rows_len; j < m_rows_alloc_len; j++) {
m_rows[j] = (VteRowData *) malloc (sizeof (VteRowData));
@@ -212,7 +211,7 @@ void RingView::maybe_update()
_vte_row_data_copy (row_data, m_rows[m_rows_len]);
} else {
// FIXME
- _vte_row_data_shrink (m_rows[m_rows_len], 0);
+ _vte_row_data_clear (m_rows[m_rows_len]);
}
m_rows_len++;
row++;
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]