[pangomm/pangomm-2-46] Layout: Speed up get_log_attrs()



commit bd8db5cf3b04406504af592cc6f0d83480fd2166
Author: Kjell Ahlstedt <kjellahlstedt gmail com>
Date:   Sun Jan 17 15:50:45 2021 +0100

    Layout: Speed up get_log_attrs()
    
    Call pango_layout_get_log_attrs_readonly() instead of
    pango_layout_get_log_attrs(). The PangoLogAttr structs
    will then be copied once instead of twice.

 pango/src/layout.ccg | 6 ++----
 pango/src/layout.hg  | 6 ++++++
 2 files changed, 8 insertions(+), 4 deletions(-)
---
diff --git a/pango/src/layout.ccg b/pango/src/layout.ccg
index 9f4cd27..752547e 100644
--- a/pango/src/layout.ccg
+++ b/pango/src/layout.ccg
@@ -57,12 +57,10 @@ void Layout::set_markup(const Glib::ustring& markup, gunichar accel_marker, guni
 
 Glib::ArrayHandle<PangoLogAttr> Layout::get_log_attrs() const
 {
-  //Get array:
-  PangoLogAttr* pAttrs = 0;
   int n_attrs = 0;
-  pango_layout_get_log_attrs(const_cast<PangoLayout*>(gobj()), &pAttrs, &n_attrs);
+  const PangoLogAttr* const pAttrs = pango_layout_get_log_attrs_readonly(const_cast<PangoLayout*>(gobj()), 
&n_attrs);
 
-  return Glib::ArrayHandle<PangoLogAttr>(pAttrs, n_attrs, Glib::OWNERSHIP_SHALLOW);
+  return Glib::ArrayHandle<PangoLogAttr>(pAttrs, n_attrs, Glib::OWNERSHIP_NONE);
 }
 
 Rectangle Layout::index_to_pos(int index) const
diff --git a/pango/src/layout.hg b/pango/src/layout.hg
index c9d8192..7822fef 100644
--- a/pango/src/layout.hg
+++ b/pango/src/layout.hg
@@ -163,6 +163,12 @@ public:
   _WRAP_METHOD(guint get_serial() const, pango_layout_get_serial)
 
   /** Retrieve an array of logical attributes for each character in the layout.
+   *
+   * The number of attributes returned will be one more
+   * than the total number of characters in the layout, since there
+   * need to be attributes corresponding to both the position before
+   * the first character and the position after the last character.
+   *
    * @return An array of logical attributes.
    */
   Glib::ArrayHandle<LogAttr> get_log_attrs() const;


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