[pangomm] Layout: Speed up get_log_attrs()
- From: Kjell Ahlstedt <kjellahl src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [pangomm] Layout: Speed up get_log_attrs()
- Date: Sun, 17 Jan 2021 14:49:23 +0000 (UTC)
commit 0da7f36962b9a326a3f83dd8b70ef3b12b5dee14
Author: Kjell Ahlstedt <kjellahlstedt gmail com>
Date: Sun Jan 17 15:47:11 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 | 10 ++++++++--
2 files changed, 10 insertions(+), 6 deletions(-)
---
diff --git a/pango/src/layout.ccg b/pango/src/layout.ccg
index 3aa20eb..2e5b3d5 100644
--- a/pango/src/layout.ccg
+++ b/pango/src/layout.ccg
@@ -72,12 +72,10 @@ void Layout::set_markup(const Glib::ustring& markup, gunichar accel_marker, guni
std::vector<PangoLogAttr> Layout::get_log_attrs() const
{
- //Get array:
- PangoLogAttr* pAttrs = nullptr;
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::ArrayHandler<PangoLogAttr>::array_to_vector(pAttrs, n_attrs, Glib::OWNERSHIP_SHALLOW);
+ return Glib::ArrayHandler<PangoLogAttr>::array_to_vector(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 d73ff15..749f339 100644
--- a/pango/src/layout.hg
+++ b/pango/src/layout.hg
@@ -161,8 +161,14 @@ public:
_WRAP_METHOD(guint get_serial() const, pango_layout_get_serial)
- /** Retrieve an array of logical attributes for each character in the layout.
- * @return An array of logical attributes.
+ /** Retrieve a vector 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 A vector of logical attributes.
*/
std::vector<LogAttr> get_log_attrs() const;
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]