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



commit df980a15c381f9b090aa9cdddc7f7b9efadfc8f1
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 3a305b6..0014673 100644
--- a/pango/src/layout.hg
+++ b/pango/src/layout.hg
@@ -159,6 +159,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]