summaryrefslogtreecommitdiff
path: root/folks
diff options
context:
space:
mode:
authorSimon McVittie <simon.mcvittie@collabora.co.uk>2013-03-28 14:46:55 +0000
committerSimon McVittie <simon.mcvittie@collabora.co.uk>2013-04-04 13:46:44 +0100
commit06f06a10a754b28b8ede2ec840cbadbc8afb7733 (patch)
tree80e93639ed8715b67aee8462a013d37f9d5b8fc0 /folks
parentab22ced5b97ef63ad206bdd6e3a9270969fb6157 (diff)
Add fast-path iteration for SmallSet
Bug: https://bugzilla.gnome.org/show_bug.cgi?id=687161 Signed-off-by: Simon McVittie <simon.mcvittie@collabora.co.uk> Reviewed-by: Philip Withnall <philip@tecnocode.co.uk>
Diffstat (limited to 'folks')
-rw-r--r--folks/folks-generics.vapi5
-rw-r--r--folks/small-set-internal.h13
2 files changed, 18 insertions, 0 deletions
diff --git a/folks/folks-generics.vapi b/folks/folks-generics.vapi
index cab90a02..867257f0 100644
--- a/folks/folks-generics.vapi
+++ b/folks/folks-generics.vapi
@@ -39,6 +39,11 @@ namespace Folks
internal static SmallSet<G> copy (Gee.Iterable<G> iterable,
owned Gee.HashDataFunc<G>? item_hash = null,
owned Gee.EqualDataFunc<G>? item_equals = null);
+
+#if FOLKS_COMPILATION
+ [CCode (cheader_filename = "folks/small-set-internal.h")]
+ public unowned G @get (int i);
+#endif
}
}
diff --git a/folks/small-set-internal.h b/folks/small-set-internal.h
index aeda3164..d18bd8f6 100644
--- a/folks/small-set-internal.h
+++ b/folks/small-set-internal.h
@@ -74,6 +74,19 @@ struct _FolksSmallSet {
FolksSmallSet *rw_version;
};
+/* Syntactic sugar for iteration. The type must match the type
+ * of the size property, which is signed, because Vala. */
+static inline gconstpointer
+folks_small_set_get (FolksSmallSet *self,
+ gint i)
+{
+ g_return_val_if_fail (self != NULL, NULL);
+ g_return_val_if_fail (i >= 0, NULL);
+ g_return_val_if_fail ((guint) i < self->items->len, NULL);
+
+ return g_ptr_array_index (self->items, i);
+}
+
FolksSmallSet *
_folks_small_set_new_take_array (GPtrArray *arr,
GType item_type,