[vte] a11y: Remove extraneous copying of a long-ish string



commit 857961e340df503522ee2d1082520dbf715f76fd
Author: Christian Persch <chpe gnome org>
Date:   Mon Nov 30 17:23:34 2015 +0100

    a11y: Remove extraneous copying of a long-ish string
    
    Add a variant of ::get_text that returns the GString it uses internally
    anyway, instead of returning the text, and creating a new GString for
    the a11y layer.

 src/vte.cc         |   51 +++++++++++++++++++++++++++++++++++++++++----------
 src/vteaccess.cc   |   18 +++++-------------
 src/vteinternal.hh |   31 +++++++++++++++++++++++--------
 3 files changed, 69 insertions(+), 31 deletions(-)
---
diff --git a/src/vte.cc b/src/vte.cc
index 0aa2709..cea7a3b 100644
--- a/src/vte.cc
+++ b/src/vte.cc
@@ -5974,6 +5974,27 @@ VteTerminalPrivate::get_text(vte::grid::row_t start_row,
                              GArray *attributes,
                              gsize *ret_len)
 {
+        GString *text = get_text(start_row, start_col,
+                                 end_row, end_col,
+                                 wrap, include_trailing_spaces,
+                                 is_selected, data,
+                                 attributes);
+        if (ret_len)
+                *ret_len = text->len;
+        return static_cast<char*>(g_string_free(text, FALSE));
+}
+
+GString*
+VteTerminalPrivate::get_text(vte::grid::row_t start_row,
+                             vte::grid::column_t start_col,
+                             vte::grid::row_t end_row,
+                             vte::grid::column_t end_col,
+                             bool wrap,
+                             bool include_trailing_spaces,
+                             VteSelectionFunc is_selected,
+                             gpointer data,
+                             GArray *attributes)
+{
         vte::grid::row_t row;
         vte::grid::column_t col, last_emptycol, last_nonemptycol;
         gsize last_empty, last_nonempty;
@@ -6099,9 +6120,7 @@ VteTerminalPrivate::get_text(vte::grid::row_t start_row,
        }
        /* Sanity check. */
        g_assert(attributes == NULL || string->len == attributes->len);
-        if (ret_len)
-                *ret_len = string->len;
-       return g_string_free(string, FALSE);
+        return string;
 }
 
 char *
@@ -6112,31 +6131,43 @@ VteTerminalPrivate::get_text_displayed(bool wrap,
                                        GArray *attributes,
                                        gsize *ret_len)
 {
+        GString *text = get_text_displayed(wrap, include_trailing_spaces,
+                                           is_selected, data,
+                                           attributes);
+        if (ret_len)
+                *ret_len = text->len;
+        return static_cast<char*>(g_string_free(text, FALSE));
+}
+
+GString*
+VteTerminalPrivate::get_text_displayed(bool wrap,
+                                       bool include_trailing_spaces,
+                                       VteSelectionFunc is_selected,
+                                       gpointer data,
+                                       GArray *attributes)
+{
         return get_text(_vte_terminal_first_displayed_row(m_terminal), 0,
                         _vte_terminal_last_displayed_row(m_terminal), m_column_count - 1,
                         wrap, include_trailing_spaces,
                         is_selected, data,
-                        attributes,
-                        ret_len);
+                        attributes);
 }
 
 /* This is distinct from just using first/last_displayed_row since a11y
  * doesn't know about sub-row displays.
  */
-char *
+GString*
 VteTerminalPrivate::get_text_displayed_a11y(bool wrap,
                                             bool include_trailing_spaces,
                                             VteSelectionFunc is_selected,
                                             gpointer data,
-                                            GArray *attributes,
-                                            gsize *ret_len)
+                                            GArray *attributes)
 {
         return get_text(m_screen->scroll_delta, 0,
                         m_screen->scroll_delta + m_row_count - 1, m_column_count - 1,
                         wrap, include_trailing_spaces,
                         is_selected, data,
-                        attributes,
-                        ret_len);
+                        attributes);
 }
 
 /*
diff --git a/src/vteaccess.cc b/src/vteaccess.cc
index 9384b0f..46efbae 100644
--- a/src/vteaccess.cc
+++ b/src/vteaccess.cc
@@ -198,7 +198,7 @@ vte_terminal_accessible_update_private_data_if_needed(VteTerminalAccessible *acc
        VteTerminalAccessiblePrivate *priv = (VteTerminalAccessiblePrivate 
*)_vte_terminal_accessible_get_instance_private(accessible);
         VteTerminal *terminal;
        struct _VteCharAttributes attrs;
-       char *next, *tmp;
+       char *next;
        long row, offset, caret;
        long ccol, crow;
        guint i;
@@ -277,18 +277,10 @@ vte_terminal_accessible_update_private_data_if_needed(VteTerminalAccessible *acc
                priv->snapshot_linebreaks = g_array_new(FALSE, FALSE, sizeof(int));
 
                /* Get a new view of the uber-label. */
-                gsize tmp_len;
-               tmp = terminal->pvt->get_text_displayed_a11y(true /* wrap */,
-                                                             true /* include trailing whitespace */,
-                                                             nullptr, nullptr,
-                                                             priv->snapshot_attributes,
-                                                             &tmp_len);
-               if (tmp == NULL) {
-                       /* Aaargh!  We're screwed. */
-                       return;
-               }
-               priv->snapshot_text = g_string_new_len(tmp, tmp_len);
-               g_free(tmp);
+               priv->snapshot_text = terminal->pvt->get_text_displayed_a11y(true /* wrap */,
+                                                                             true /* include trailing 
whitespace */,
+                                                                             nullptr, nullptr,
+                                                                             priv->snapshot_attributes);
 
                /* Get the offsets to the beginnings of each character. */
                i = 0;
diff --git a/src/vteinternal.hh b/src/vteinternal.hh
index 740c2dc..acb9e86 100644
--- a/src/vteinternal.hh
+++ b/src/vteinternal.hh
@@ -546,7 +546,17 @@ public:
 
         inline bool line_is_wrappable(vte::grid::row_t row) const;
 
-        char *get_text(vte::grid::row_t start_row,
+        GString* get_text(vte::grid::row_t start_row,
+                          vte::grid::column_t start_col,
+                          vte::grid::row_t end_row,
+                          vte::grid::column_t end_col,
+                          bool wrap,
+                          bool include_trailing_spaces,
+                          VteSelectionFunc is_selected,
+                          gpointer data,
+                          GArray *attributes);
+
+        char* get_text(vte::grid::row_t start_row,
                        vte::grid::column_t start_col,
                        vte::grid::row_t end_row,
                        vte::grid::column_t end_col,
@@ -557,19 +567,24 @@ public:
                        GArray *attributes,
                        gsize *ret_len);
 
-        char *get_text_displayed(bool wrap,
+        GString* get_text_displayed(bool wrap,
+                                    bool include_trailing_spaces,
+                                    VteSelectionFunc is_selected,
+                                    gpointer data,
+                                    GArray *attributes);
+
+        char* get_text_displayed(bool wrap,
                                  bool include_trailing_spaces,
                                  VteSelectionFunc is_selected,
                                  gpointer data,
                                  GArray *attributes,
                                  gsize *ret_len);
 
-        char *get_text_displayed_a11y(bool wrap,
-                                      bool include_trailing_spaces,
-                                      VteSelectionFunc is_selected,
-                                      gpointer data,
-                                      GArray *attributes,
-                                      gsize *ret_len);
+        GString* get_text_displayed_a11y(bool wrap,
+                                         bool include_trailing_spaces,
+                                         VteSelectionFunc is_selected,
+                                         gpointer data,
+                                         GArray *attributes);
 
         void start_selection(long x,
                              long y,


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