summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorMaciej Piechotka <uzytkownik2@gmail.com>2013-08-02 17:05:54 +0200
committerMaciej Piechotka <uzytkownik2@gmail.com>2013-08-02 17:05:54 +0200
commit1d84fb023d563223162ae82e222a9f6938879b9c (patch)
tree4a7687b19cef3d40338a9e4a783e1a583641e1f2
parent74947f993819754d510f57cd9a84e4624c9361d5 (diff)
downloadlibgee-1d84fb023d563223162ae82e222a9f6938879b9c.tar.gz
Fix Collection.add_all_array for primitives
-rw-r--r--gee/collection.vala145
1 files changed, 129 insertions, 16 deletions
diff --git a/gee/collection.vala b/gee/collection.vala
index e61790b..7897a09 100644
--- a/gee/collection.vala
+++ b/gee/collection.vala
@@ -199,11 +199,36 @@ public interface Gee.Collection<G> : Iterable<G> {
*/
[CCode (ordering = 13)]
public virtual bool add_all_array (G[] array) {
- bool changed = false;
- foreach (unowned G item in array) {
- changed |= add (item);
+ var t = typeof (G);
+ if (t == typeof (bool)) {
+ return add_all_bool_array ((Collection<bool>) this, (bool [])array);
+ } else if (t == typeof (char)) {
+ return add_all_char_array ((Collection<char>) this, (char [])array);
+ } else if (t == typeof (uchar)) {
+ return add_all_uchar_array ((Collection<uchar>) this, (uchar [])array);
+ } else if (t == typeof (int)) {
+ return add_all_int_array ((Collection<int>) this, (int [])array);
+ } else if (t == typeof (uint)) {
+ return add_all_uint_array ((Collection<uint>) this, (uint [])array);
+ } else if (t == typeof (int64)) {
+ return add_all_int64_array ((Collection<int64?>) this, (int64? [])array);
+ } else if (t == typeof (uint64)) {
+ return add_all_uint64_array ((Collection<uint64?>) this, (uint64? [])array);
+ } else if (t == typeof (long)) {
+ return add_all_long_array ((Collection<long>) this, (long [])array);
+ } else if (t == typeof (ulong)) {
+ return add_all_ulong_array ((Collection<ulong>) this, (ulong [])array);
+ } else if (t == typeof (float)) {
+ return add_all_float_array ((Collection<float>) this, (float? [])array);
+ } else if (t == typeof (double)) {
+ return add_all_double_array ((Collection<double>) this, (double? [])array);
+ } else {
+ bool changed = false;
+ foreach (unowned G item in array) {
+ changed |= add (item);
+ }
+ return changed;
}
- return changed;
}
/**
@@ -270,6 +295,21 @@ public interface Gee.Collection<G> : Iterable<G> {
return changed;
}
+ /**
+ * The read-only view of this collection.
+ */
+ [CCode (ordering = 12)]
+ public abstract Collection<G> read_only_view { owned get; }
+
+ /**
+ * Returns an immutable empty collection.
+ *
+ * @return an immutable empty collection
+ */
+ public static Collection<G> empty<G> () {
+ return new HashSet<G> ().read_only_view;
+ }
+
private static bool[] to_bool_array (Collection<bool> coll) {
bool[] array = new bool[coll.size];
int index = 0;
@@ -369,19 +409,92 @@ public interface Gee.Collection<G> : Iterable<G> {
return array;
}
- /**
- * The read-only view of this collection.
- */
- [CCode (ordering = 12)]
- public abstract Collection<G> read_only_view { owned get; }
+ private static bool add_all_bool_array (Collection<bool> coll, bool[] arr) {
+ bool changed = false;
+ foreach (bool el in arr) {
+ changed |= coll.add (el);
+ }
+ return changed;
+ }
- /**
- * Returns an immutable empty collection.
- *
- * @return an immutable empty collection
- */
- public static Collection<G> empty<G> () {
- return new HashSet<G> ().read_only_view;
+ private static bool add_all_char_array (Collection<char> coll, char[] arr) {
+ bool changed = false;
+ foreach (char el in arr) {
+ changed |= coll.add (el);
+ }
+ return changed;
+ }
+
+ private static bool add_all_uchar_array (Collection<uchar> coll, uchar[] arr) {
+ bool changed = false;
+ foreach (uchar el in arr) {
+ changed |= coll.add (el);
+ }
+ return changed;
+ }
+
+ private static bool add_all_int_array (Collection<int> coll, int[] arr) {
+ bool changed = false;
+ foreach (int el in arr) {
+ changed |= coll.add (el);
+ }
+ return changed;
+ }
+
+ private static bool add_all_uint_array (Collection<uint> coll, uint[] arr) {
+ bool changed = false;
+ foreach (uint el in arr) {
+ changed |= coll.add (el);
+ }
+ return changed;
+ }
+
+ private static bool add_all_int64_array (Collection<int64?> coll, int64?[] arr) {
+ bool changed = false;
+ foreach (unowned int64? el in arr) {
+ changed |= coll.add (el);
+ }
+ return changed;
+ }
+
+ private static bool add_all_uint64_array (Collection<uint64?> coll, uint64?[] arr) {
+ bool changed = false;
+ foreach (unowned uint64? el in arr) {
+ changed |= coll.add (el);
+ }
+ return changed;
+ }
+
+ private static bool add_all_long_array (Collection<long> coll, long[] arr) {
+ bool changed = false;
+ foreach (long el in arr) {
+ changed |= coll.add (el);
+ }
+ return changed;
+ }
+
+ private static bool add_all_ulong_array (Collection<ulong> coll, ulong[] arr) {
+ bool changed = false;
+ foreach (ulong el in arr) {
+ changed |= coll.add (el);
+ }
+ return changed;
+ }
+
+ private static bool add_all_float_array (Collection<float?> coll, float?[] arr) {
+ bool changed = false;
+ foreach (unowned float? el in arr) {
+ changed |= coll.add (el);
+ }
+ return changed;
+ }
+
+ private static bool add_all_double_array (Collection<double?> coll, double?[] arr) {
+ bool changed = false;
+ foreach (unowned double? el in arr) {
+ changed |= coll.add (el);
+ }
+ return changed;
}
}