[libgee] Allow creation of ArrayList from array



commit 3e6be50ff460efaa0a7a8a3f9c544063ea252826
Author: Maciej Piechotka <uzytkownik2 gmail com>
Date:   Sat Feb 16 11:23:53 2013 +0000

    Allow creation of ArrayList from array

 gee/arraylist.vala |   22 +++++++++++++++++++++-
 1 files changed, 21 insertions(+), 1 deletions(-)
---
diff --git a/gee/arraylist.vala b/gee/arraylist.vala
index 3312aff..4cc99d1 100644
--- a/gee/arraylist.vala
+++ b/gee/arraylist.vala
@@ -58,7 +58,7 @@ public class Gee.ArrayList<G> : AbstractBidirList<G> {
        [CCode (notify = false)]
        public EqualDataFunc<G> equal_func { private set; get; }
 
-       internal G[] _items = new G[4];
+       internal G[] _items;
        internal int _size;
 
        // concurrent modification protection
@@ -77,6 +77,26 @@ public class Gee.ArrayList<G> : AbstractBidirList<G> {
                        equal_func = Functions.get_equal_func_for (typeof (G));
                }
                this.equal_func = equal_func;
+               _items = new G[4];
+               _size = 0;
+       }
+
+       /**
+        * Constructs a new array list based on provided array.
+        *
+        * If not provided, the function parameter is requested to the
+        * { link Functions} function factory methods.
+        *
+        * @param itmes initial items to be put into array
+        * @param equal_func an optional element equality testing function
+        */
+       public ArrayList.wrap (owned G[] items, owned EqualDataFunc<G>? equal_func = null) {
+               if (equal_func == null) {
+                       equal_func = Functions.get_equal_func_for (typeof (G));
+               }
+               this.equal_func = equal_func;
+               _items = items;
+               _size = items.length;
        }
 
        /**


[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]