From a2e5f57a24be31269200f8b5b650bd235204f85d Mon Sep 17 00:00:00 2001 From: Maciej Piechotka Date: Sat, 3 Aug 2013 11:02:42 +0200 Subject: [PATCH] Fix Collection.remove_all_array for primitives --- gee/collection.vala | 121 ++++++++++++++++++++++++++++++++++++++++++++++++++-- 1 file changed, 117 insertions(+), 4 deletions(-) diff --git a/gee/collection.vala b/gee/collection.vala index 1c1ec9b..6297794 100644 --- a/gee/collection.vala +++ b/gee/collection.vala @@ -276,11 +276,36 @@ public interface Gee.Collection : Iterable { */ public bool remove_all_array (G[] array) { // FIXME: Change to virtual after bug #693455 is fixed - bool changed = false; - foreach (unowned G item in array) { - changed |= remove (item); + var t = typeof (G); + if (t == typeof (bool)) { + return remove_all_bool_array ((Collection) this, (bool [])array); + } else if (t == typeof (char)) { + return remove_all_char_array ((Collection) this, (char [])array); + } else if (t == typeof (uchar)) { + return remove_all_uchar_array ((Collection) this, (uchar [])array); + } else if (t == typeof (int)) { + return remove_all_int_array ((Collection) this, (int [])array); + } else if (t == typeof (uint)) { + return remove_all_uint_array ((Collection) this, (uint [])array); + } else if (t == typeof (int64)) { + return remove_all_int64_array ((Collection) this, (int64? [])array); + } else if (t == typeof (uint64)) { + return remove_all_uint64_array ((Collection) this, (uint64? [])array); + } else if (t == typeof (long)) { + return remove_all_long_array ((Collection) this, (long [])array); + } else if (t == typeof (ulong)) { + return remove_all_ulong_array ((Collection) this, (ulong [])array); + } else if (t == typeof (float)) { + return remove_all_float_array ((Collection) this, (float? [])array); + } else if (t == typeof (double)) { + return remove_all_double_array ((Collection) this, (double? [])array); + } else { + bool changed = false; + foreach (unowned G item in array) { + changed |= remove (item); + } + return changed; } - return changed; } /** @@ -582,5 +607,93 @@ public interface Gee.Collection : Iterable { } return true; } + + private static bool remove_all_bool_array (Collection coll, bool[] arr) { + bool changed = false; + foreach (bool el in arr) { + changed |= coll.remove (el); + } + return changed; + } + + private static bool remove_all_char_array (Collection coll, char[] arr) { + bool changed = false; + foreach (char el in arr) { + changed |= coll.remove (el); + } + return changed; + } + + private static bool remove_all_uchar_array (Collection coll, uchar[] arr) { + bool changed = false; + foreach (uchar el in arr) { + changed |= coll.remove (el); + } + return changed; + } + + private static bool remove_all_int_array (Collection coll, int[] arr) { + bool changed = false; + foreach (int el in arr) { + changed |= coll.remove (el); + } + return changed; + } + + private static bool remove_all_uint_array (Collection coll, uint[] arr) { + bool changed = false; + foreach (uint el in arr) { + changed |= coll.remove (el); + } + return changed; + } + + private static bool remove_all_int64_array (Collection coll, int64?[] arr) { + bool changed = false; + foreach (unowned int64? el in arr) { + changed |= coll.remove (el); + } + return changed; + } + + private static bool remove_all_uint64_array (Collection coll, uint64?[] arr) { + bool changed = false; + foreach (unowned uint64? el in arr) { + changed |= coll.remove (el); + } + return changed; + } + + private static bool remove_all_long_array (Collection coll, long[] arr) { + bool changed = false; + foreach (long el in arr) { + changed |= coll.remove (el); + } + return changed; + } + + private static bool remove_all_ulong_array (Collection coll, ulong[] arr) { + bool changed = false; + foreach (ulong el in arr) { + changed |= coll.remove (el); + } + return changed; + } + + private static bool remove_all_float_array (Collection coll, float?[] arr) { + bool changed = false; + foreach (unowned float? el in arr) { + changed |= coll.remove (el); + } + return changed; + } + + private static bool remove_all_double_array (Collection coll, double?[] arr) { + bool changed = false; + foreach (unowned double? el in arr) { + changed |= coll.remove (el); + } + return changed; + } } -- 2.7.4