[evince] ev-link-accessible: Improve efficiency of methods to get start and end indices
- From: Joanmarie Diggs <joanied src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [evince] ev-link-accessible: Improve efficiency of methods to get start and end indices
- Date: Sat, 28 Jun 2014 19:54:51 +0000 (UTC)
commit 1a6c9dfce4fe064d193e0cdd221a0d299a0b54d1
Author: Joanmarie Diggs <jdiggs igalia com>
Date: Fri Jun 27 08:40:09 2014 -0400
ev-link-accessible: Improve efficiency of methods to get start and end indices
* Store the value to eliminate unnecessary iteration through
character rects
* Calculate the end index forward from the start index rather
than backwards from the last character on the page
https://bugzilla.gnome.org/show_bug.cgi?id=732340
libview/ev-link-accessible.c | 27 ++++++++++++++++++++++-----
1 files changed, 22 insertions(+), 5 deletions(-)
---
diff --git a/libview/ev-link-accessible.c b/libview/ev-link-accessible.c
index ebb9485..80cca43 100644
--- a/libview/ev-link-accessible.c
+++ b/libview/ev-link-accessible.c
@@ -34,6 +34,8 @@ struct _EvLinkAccessiblePrivate {
EvHyperlink *hyperlink;
gchar *name;
+ gint start_index;
+ gint end_index;
};
struct _EvHyperlink {
@@ -105,6 +107,8 @@ ev_hyperlink_get_start_index (AtkHyperlink *atk_hyperlink)
return -1;
impl_priv = hyperlink->link_impl->priv;
+ if (impl_priv->start_index != -1)
+ return impl_priv->start_index;
view = ev_page_accessible_get_view (impl_priv->page);
if (!view->page_cache)
@@ -123,8 +127,10 @@ ev_hyperlink_get_start_index (AtkHyperlink *atk_hyperlink)
c_x = rect->x1 + (rect->x2 - rect->x1) / 2.;
c_y = rect->y1 + (rect->y2 - rect->y1) / 2.;
if (c_x >= impl_priv->area.x1 && c_x <= impl_priv->area.x2 &&
- c_y >= impl_priv->area.y1 && c_y <= impl_priv->area.y2)
+ c_y >= impl_priv->area.y1 && c_y <= impl_priv->area.y2) {
+ impl_priv->start_index = i;
return i;
+ }
}
return -1;
@@ -139,11 +145,18 @@ ev_hyperlink_get_end_index (AtkHyperlink *atk_hyperlink)
EvRectangle *areas = NULL;
guint n_areas = 0;
guint i;
+ gint start_index;
if (!hyperlink->link_impl)
return -1;
impl_priv = hyperlink->link_impl->priv;
+ if (impl_priv->end_index != -1)
+ return impl_priv->end_index;
+
+ start_index = ev_hyperlink_get_start_index (atk_hyperlink);
+ if (start_index == -1)
+ return -1;
view = ev_page_accessible_get_view (impl_priv->page);
if (!view->page_cache)
@@ -155,15 +168,17 @@ ev_hyperlink_get_end_index (AtkHyperlink *atk_hyperlink)
if (!areas)
return -1;
- for (i = n_areas - 1; i >= 0; i--) {
+ for (i = start_index + 1; i < n_areas; i++) {
EvRectangle *rect = areas + i;
gdouble c_x, c_y;
c_x = rect->x1 + (rect->x2 - rect->x1) / 2.;
c_y = rect->y1 + (rect->y2 - rect->y1) / 2.;
- if (c_x >= impl_priv->area.x1 && c_x <= impl_priv->area.x2 &&
- c_y >= impl_priv->area.y1 && c_y <= impl_priv->area.y2)
- return i + 1;
+ if (c_x < impl_priv->area.x1 || c_x > impl_priv->area.x2 ||
+ c_y < impl_priv->area.y1 || c_y > impl_priv->area.y2) {
+ impl_priv->end_index = i;
+ return i;
+ }
}
return -1;
@@ -286,6 +301,8 @@ ev_link_accessible_init (EvLinkAccessible *link)
{
atk_object_set_role (ATK_OBJECT (link), ATK_ROLE_LINK);
link->priv = G_TYPE_INSTANCE_GET_PRIVATE (link, EV_TYPE_LINK_ACCESSIBLE, EvLinkAccessiblePrivate);
+ link->priv->start_index = -1;
+ link->priv->end_index = -1;
}
static AtkHyperlink *
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]