summaryrefslogtreecommitdiff
path: root/testsuite/a11y
diff options
context:
space:
mode:
authorEmmanuele Bassi <ebassi@gnome.org>2015-07-16 16:12:35 +0100
committerEmmanuele Bassi <ebassi@gnome.org>2015-07-16 16:19:55 +0100
commite259b2f30d86fdde7dab27a25e8088d36421acc7 (patch)
tree7c3499bb6a4f9ecf237fe64cdc9f53efacc67c78 /testsuite/a11y
parent3b41daca780e9e83d04dcad43e2fbd5a2ab8c120 (diff)
downloadgtk+-e259b2f30d86fdde7dab27a25e8088d36421acc7.tar.gz
Avoid O(n²) walking of string arrays
"Yo, we heard you like traversing NULL-terminated arrays to operate on them, so we called g_strv_length() as the for condition, so you can iterate the array while iterating the array." Instead of making famed rapper and television producer Xzibit proud, we should avoid calling g_strv_length() on an array while looping on the array, to avoid quadratic complexity. We do this in various places that deal with arrays of strings that we cannot really guess are short enough not to matter — e.g. the list of CSS selectors in the inspector, or the required authentication information for printing.
Diffstat (limited to 'testsuite/a11y')
-rw-r--r--testsuite/a11y/state/state-record.c7
1 files changed, 4 insertions, 3 deletions
diff --git a/testsuite/a11y/state/state-record.c b/testsuite/a11y/state/state-record.c
index cf9313b1b0..dd37c6233c 100644
--- a/testsuite/a11y/state/state-record.c
+++ b/testsuite/a11y/state/state-record.c
@@ -142,7 +142,7 @@ record_events (const gchar *ui_file,
GError *error;
gchar *contents;
gchar **actions;
- gint i;
+ gint i, len;
builder = gtk_builder_new ();
error = NULL;
@@ -152,8 +152,9 @@ record_events (const gchar *ui_file,
g_file_get_contents (in_file, &contents, NULL, &error);
g_assert_no_error (error);
actions = g_strsplit (contents, "\n", 0);
-
- for (i = 0; i < g_strv_length (actions); i++)
+
+ len = g_strv_length (actions);
+ for (i = 0; i < len; i++)
do_action (builder, actions[i], string);
g_object_unref (builder);