]> git.ipfire.org Git - thirdparty/vala.git/commitdiff
gee: Replace interfaces by abstract classes to improve performance
authorJürg Billeter <j@bitron.ch>
Wed, 11 Aug 2010 20:23:09 +0000 (22:23 +0200)
committerJürg Billeter <j@bitron.ch>
Fri, 17 Sep 2010 23:00:13 +0000 (01:00 +0200)
gee/Makefile.am
gee/arraylist.vala
gee/collection.vala
gee/collectionobject.vala [deleted file]
gee/hashmap.vala
gee/hashset.vala
gee/iterable.vala
gee/iterator.vala
gee/list.vala
gee/map.vala
gee/set.vala

index 15f3e9b69dde4d403895fe67640ed42519873e7b..ab315657d6fb4a4ee0b9be603437c91c3dc9d54d 100644 (file)
@@ -14,7 +14,6 @@ noinst_LTLIBRARIES = \
 libgee_la_VALASOURCES = \
        arraylist.vala \
        collection.vala \
-       collectionobject.vala \
        hashmap.vala \
        hashset.vala \
        iterable.vala \
index b8dd485538b4513e4c4f3ce931a74fa2c3e884ef..5d2b392d87c2b454d43cab5927fec8f18d614a00 100644 (file)
@@ -27,8 +27,8 @@ using GLib;
 /**
  * Arrays of arbitrary elements which grow automatically as elements are added.
  */
-public class Vala.ArrayList<G> : CollectionObject, Iterable<G>, Collection<G>, List<G> {
-       public int size {
+public class Vala.ArrayList<G> : List<G> {
+       public override int size {
                get { return _size; }
        }
 
@@ -47,19 +47,19 @@ public class Vala.ArrayList<G> : CollectionObject, Iterable<G>, Collection<G>, L
                this.equal_func = equal_func;
        }
 
-       public Type get_element_type () {
+       public override Type get_element_type () {
                return typeof (G);
        }
 
-       public Vala.Iterator<G> iterator () {
+       public override Vala.Iterator<G> iterator () {
                return new Iterator<G> (this);
        }
 
-       public bool contains (G item) {
+       public override bool contains (G item) {
                return (index_of (item) != -1);
        }
 
-       public int index_of (G item) {
+       public override int index_of (G item) {
                for (int index = 0; index < _size; index++) {
                        if (_equal_func (_items[index], item)) {
                                return index;
@@ -68,19 +68,19 @@ public class Vala.ArrayList<G> : CollectionObject, Iterable<G>, Collection<G>, L
                return -1;
        }
 
-       public G? get (int index) {
+       public override G? get (int index) {
                assert (index >= 0 && index < _size);
 
                return _items[index];
        }
 
-       public void set (int index, G item) {
+       public override void set (int index, G item) {
                assert (index >= 0 && index < _size);
 
                _items[index] = item;
        }
 
-       public bool add (G item) {
+       public override bool add (G item) {
                if (_size == _items.length) {
                        grow_if_needed (1);
                }
@@ -89,7 +89,7 @@ public class Vala.ArrayList<G> : CollectionObject, Iterable<G>, Collection<G>, L
                return true;
        }
 
-       public void insert (int index, G item) {
+       public override void insert (int index, G item) {
                assert (index >= 0 && index <= _size);
 
                if (_size == _items.length) {
@@ -100,7 +100,7 @@ public class Vala.ArrayList<G> : CollectionObject, Iterable<G>, Collection<G>, L
                _stamp++;
        }
 
-       public bool remove (G item) {
+       public override bool remove (G item) {
                for (int index = 0; index < _size; index++) {
                        if (_equal_func (_items[index], item)) {
                                remove_at (index);
@@ -110,7 +110,7 @@ public class Vala.ArrayList<G> : CollectionObject, Iterable<G>, Collection<G>, L
                return false;
        }
 
-       public void remove_at (int index) {
+       public override void remove_at (int index) {
                assert (index >= 0 && index < _size);
 
                _items[index] = null;
@@ -120,7 +120,7 @@ public class Vala.ArrayList<G> : CollectionObject, Iterable<G>, Collection<G>, L
                _stamp++;
        }
 
-       public void clear () {
+       public override void clear () {
                for (int index = 0; index < _size; index++) {
                        _items[index] = null;
                }
@@ -152,7 +152,7 @@ public class Vala.ArrayList<G> : CollectionObject, Iterable<G>, Collection<G>, L
                _items.resize (value);
        }
 
-       private class Iterator<G> : CollectionObject, Vala.Iterator<G> {
+       private class Iterator<G> : Vala.Iterator<G> {
                public ArrayList<G> list {
                        set {
                                _list = value;
@@ -170,7 +170,7 @@ public class Vala.ArrayList<G> : CollectionObject, Iterable<G>, Collection<G>, L
                        this.list = list;
                }
 
-               public bool next () {
+               public override bool next () {
                        assert (_stamp == _list._stamp);
                        if (_index < _list._size) {
                                _index++;
@@ -178,7 +178,7 @@ public class Vala.ArrayList<G> : CollectionObject, Iterable<G>, Collection<G>, L
                        return (_index < _list._size);
                }
 
-               public G? get () {
+               public override G? get () {
                        assert (_stamp == _list._stamp);
 
                        if (_index < 0 || _index >= _list._size) {
index 11ea97aa835f988769d26501dcc1216c015456a1..6a652fcdfd41cddf804264f8158c91aef206c946 100644 (file)
@@ -24,7 +24,7 @@
  * Serves as the base interface for implementing collection classes. Defines
  * size, iteration, and modification methods.
  */
-public interface Vala.Collection<G> : Iterable<G> {
+public abstract class Vala.Collection<G> : Iterable<G> {
        /**
         * The number of items in this collection.
         */
diff --git a/gee/collectionobject.vala b/gee/collectionobject.vala
deleted file mode 100644 (file)
index 5a7a624..0000000
+++ /dev/null
@@ -1,30 +0,0 @@
-/* collectionobject.vala
- *
- * Copyright (C) 2008  Jürg Billeter
- *
- * This library is free software; you can redistribute it and/or
- * modify it under the terms of the GNU Lesser General Public
- * License as published by the Free Software Foundation; either
- * version 2.1 of the License, or (at your option) any later version.
-
- * This library is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
- * Lesser General Public License for more details.
-
- * You should have received a copy of the GNU Lesser General Public
- * License along with this library; if not, write to the Free Software
- * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301  USA
- *
- * Author:
- *     Jürg Billeter <j@bitron.ch>
- */
-
-using GLib;
-
-/**
- * Base class for all collections.
- */
-public class Vala.CollectionObject {
-}
-
index 79bcf1c4de5d9be084c94de44dae9d242bed3142..5159fe3ff6528f71a94d5995b58f0d6075c2b826 100644 (file)
@@ -27,8 +27,8 @@ using GLib;
 /**
  * Hashtable implementation of the Map interface.
  */
-public class Vala.HashMap<K,V> : CollectionObject, Map<K,V> {
-       public int size {
+public class Vala.HashMap<K,V> : Map<K,V> {
+       public override int size {
                get { return _nnodes; }
        }
 
@@ -66,11 +66,11 @@ public class Vala.HashMap<K,V> : CollectionObject, Map<K,V> {
                _nodes = new Node<K,V>[_array_size];
        }
 
-       public Set<K> get_keys () {
+       public override Set<K> get_keys () {
                return new KeySet<K,V> (this);
        }
 
-       public Collection<V> get_values () {
+       public override Collection<V> get_values () {
                return new ValueCollection<K,V> (this);
        }
 
@@ -83,12 +83,12 @@ public class Vala.HashMap<K,V> : CollectionObject, Map<K,V> {
                return node;
        }
 
-       public bool contains (K key) {
+       public override bool contains (K key) {
                Node<K,V>** node = lookup_node (key);
                return (*node != null);
        }
 
-       public V? get (K key) {
+       public override V? get (K key) {
                Node<K,V>* node = (*lookup_node (key));
                if (node != null) {
                        return node->value;
@@ -97,7 +97,7 @@ public class Vala.HashMap<K,V> : CollectionObject, Map<K,V> {
                }
        }
 
-       public void set (K key, V value) {
+       public override void set (K key, V value) {
                Node<K,V>** node = lookup_node (key);
                if (*node != null) {
                        (*node)->value = value;
@@ -110,7 +110,7 @@ public class Vala.HashMap<K,V> : CollectionObject, Map<K,V> {
                _stamp++;
        }
 
-       public bool remove (K key) {
+       public override bool remove (K key) {
                Node<K,V>** node = lookup_node (key);
                if (*node != null) {
                        Node<K,V> next = (owned) (*node)->next;
@@ -129,7 +129,7 @@ public class Vala.HashMap<K,V> : CollectionObject, Map<K,V> {
                return false;
        }
 
-       public void clear () {
+       public override void clear () {
                for (int i = 0; i < _array_size; i++) {
                        Node<K,V> node = (owned) _nodes[i];
                        while (node != null) {
@@ -184,7 +184,7 @@ public class Vala.HashMap<K,V> : CollectionObject, Map<K,V> {
                }
        }
 
-       private class KeySet<K,V> : CollectionObject, Iterable<K>, Collection<K>, Set<K> {
+       private class KeySet<K,V> : Set<K> {
                public HashMap<K,V> map {
                        set { _map = value; }
                }
@@ -195,36 +195,36 @@ public class Vala.HashMap<K,V> : CollectionObject, Map<K,V> {
                        this.map = map;
                }
 
-               public Type get_element_type () {
+               public override Type get_element_type () {
                        return typeof (K);
                }
 
-               public Iterator<K> iterator () {
+               public override Iterator<K> iterator () {
                        return new KeyIterator<K,V> (_map);
                }
 
-               public int size {
+               public override int size {
                        get { return _map.size; }
                }
 
-               public bool add (K key) {
+               public override bool add (K key) {
                        assert_not_reached ();
                }
 
-               public void clear () {
+               public override void clear () {
                        assert_not_reached ();
                }
 
-               public bool remove (K key) {
+               public override bool remove (K key) {
                        assert_not_reached ();
                }
 
-               public bool contains (K key) {
+               public override bool contains (K key) {
                        return _map.contains (key);
                }
        }
 
-       private class KeyIterator<K,V> : CollectionObject, Iterator<K> {
+       private class KeyIterator<K,V> : Iterator<K> {
                public HashMap<K,V> map {
                        set {
                                _map = value;
@@ -243,7 +243,7 @@ public class Vala.HashMap<K,V> : CollectionObject, Map<K,V> {
                        this.map = map;
                }
 
-               public bool next () {
+               public override bool next () {
                        if (_node != null) {
                                _node = _node.next;
                        }
@@ -254,14 +254,14 @@ public class Vala.HashMap<K,V> : CollectionObject, Map<K,V> {
                        return (_node != null);
                }
 
-               public K? get () {
+               public override K? get () {
                        assert (_stamp == _map._stamp);
                        assert (_node != null);
                        return _node.key;
                }
        }
 
-       private class ValueCollection<K,V> : CollectionObject, Iterable<V>, Collection<V> {
+       private class ValueCollection<K,V> : Collection<V> {
                public HashMap<K,V> map {
                        set { _map = value; }
                }
@@ -272,31 +272,31 @@ public class Vala.HashMap<K,V> : CollectionObject, Map<K,V> {
                        this.map = map;
                }
 
-               public Type get_element_type () {
+               public override Type get_element_type () {
                        return typeof (V);
                }
 
-               public Iterator<V> iterator () {
+               public override Iterator<V> iterator () {
                        return new ValueIterator<K,V> (_map);
                }
 
-               public int size {
+               public override int size {
                        get { return _map.size; }
                }
 
-               public bool add (V value) {
+               public override bool add (V value) {
                        assert_not_reached ();
                }
 
-               public void clear () {
+               public override void clear () {
                        assert_not_reached ();
                }
 
-               public bool remove (V value) {
+               public override bool remove (V value) {
                        assert_not_reached ();
                }
 
-               public bool contains (V value) {
+               public override bool contains (V value) {
                        Iterator<V> it = iterator ();
                        while (it.next ()) {
                                if (_map._value_equal_func (it.get (), value)) {
@@ -307,7 +307,7 @@ public class Vala.HashMap<K,V> : CollectionObject, Map<K,V> {
                }
        }
 
-       private class ValueIterator<K,V> : CollectionObject, Iterator<V> {
+       private class ValueIterator<K,V> : Iterator<V> {
                public HashMap<K,V> map {
                        set {
                                _map = value;
@@ -326,7 +326,7 @@ public class Vala.HashMap<K,V> : CollectionObject, Map<K,V> {
                        this.map = map;
                }
 
-               public bool next () {
+               public override bool next () {
                        if (_node != null) {
                                _node = _node.next;
                        }
@@ -337,7 +337,7 @@ public class Vala.HashMap<K,V> : CollectionObject, Map<K,V> {
                        return (_node != null);
                }
 
-               public V? get () {
+               public override V? get () {
                        assert (_stamp == _map._stamp);
                        assert (_node != null);
                        return _node.value;
index 7f188e18ab7b80b26febf4b20eb9432a93d47d73..01452c669341706c76d567b19a0ec6e45e8852e5 100644 (file)
@@ -27,8 +27,8 @@ using GLib;
 /**
  * Hashtable implementation of the Set interface.
  */
-public class Vala.HashSet<G> : CollectionObject, Iterable<G>, Collection<G>, Set<G> {
-       public int size {
+public class Vala.HashSet<G> : Set<G> {
+       public override int size {
                get { return _nnodes; }
        }
 
@@ -69,20 +69,20 @@ public class Vala.HashSet<G> : CollectionObject, Iterable<G>, Collection<G>, Set
                return node;
        }
 
-       public bool contains (G key) {
+       public override bool contains (G key) {
                Node<G>** node = lookup_node (key);
                return (*node != null);
        }
 
-       public Type get_element_type () {
+       public override Type get_element_type () {
                return typeof (G);
        }
 
-       public Vala.Iterator<G> iterator () {
+       public override Vala.Iterator<G> iterator () {
                return new Iterator<G> (this);
        }
 
-       public bool add (G key) {
+       public override bool add (G key) {
                Node<G>** node = lookup_node (key);
                if (*node != null) {
                        return false;
@@ -96,7 +96,7 @@ public class Vala.HashSet<G> : CollectionObject, Iterable<G>, Collection<G>, Set
                }
        }
 
-       public bool remove (G key) {
+       public override bool remove (G key) {
                Node<G>** node = lookup_node (key);
                if (*node != null) {
                        Node<G> next = (owned) (*node)->next;
@@ -114,7 +114,7 @@ public class Vala.HashSet<G> : CollectionObject, Iterable<G>, Collection<G>, Set
                return false;
        }
 
-       public void clear () {
+       public override void clear () {
                for (int i = 0; i < _array_size; i++) {
                        Node<G> node = (owned) _nodes[i];
                        while (node != null) {
@@ -166,7 +166,7 @@ public class Vala.HashSet<G> : CollectionObject, Iterable<G>, Collection<G>, Set
                }
        }
 
-       private class Iterator<G> : CollectionObject, Vala.Iterator<G> {
+       private class Iterator<G> : Vala.Iterator<G> {
                public HashSet<G> set {
                        set {
                                _set = value;
@@ -185,7 +185,7 @@ public class Vala.HashSet<G> : CollectionObject, Iterable<G>, Collection<G>, Set
                        this.set = set;
                }
 
-               public bool next () {
+               public override bool next () {
                        if (_node != null) {
                                _node = _node.next;
                        }
@@ -196,7 +196,7 @@ public class Vala.HashSet<G> : CollectionObject, Iterable<G>, Collection<G>, Set
                        return (_node != null);
                }
 
-               public G? get () {
+               public override G? get () {
                        assert (_stamp == _set._stamp);
                        assert (_node != null);
                        return _node.key;
index a95bd735d3395d9556636b20e70cd3c28d1b4054..b0097ac112ddad7500b4bed279798e18ebdcfc08 100644 (file)
@@ -26,7 +26,7 @@ using GLib;
  * Implemented by classes that support a simple iteration over instances of the
  * collection.
  */
-public interface Vala.Iterable<G> : CollectionObject {
+public abstract class Vala.Iterable<G> {
        public abstract Type get_element_type ();
 
        /**
index 9677e8832ff6f4f41ef8e556d908364054798a56..5190fb652c8febe85ff36e454170c994431939de 100644 (file)
@@ -24,7 +24,7 @@
  * Implemented by classes that support a simple iteration over instances of the
  * collection.
  */
-public interface Vala.Iterator<G> : CollectionObject {
+public abstract class Vala.Iterator<G> {
        /**
         * Advances to the next element in the iteration.
         *
index 3f135762810e12f2c60155aaf79253f5996111e6..e11399cbaabdd3c550acddf10eee6eed4834d214 100644 (file)
@@ -23,7 +23,7 @@
 /**
  * Represents a collection of items in a well-defined order.
  */
-public interface Vala.List<G> : Collection<G> {
+public abstract class Vala.List<G> : Collection<G> {
        /**
         * Returns the item at the specified index in this list.
         *
index c98eeb4d257c7f32e9d77b6187e7f2269d4e9c8a..e78f794d4b69df6f3d5a11eb5722c9cc78cef310 100644 (file)
@@ -23,7 +23,7 @@
 /**
  * A map is a generic collection of key/value pairs.
  */
-public interface Vala.Map<K,V> : CollectionObject {
+public abstract class Vala.Map<K,V> {
        /**
         * The number of items in this map.
         */
index 03c28da2066691cdd037ec057f00a162735ae5a0..6449023cffa5600d7c910b781b54683690328412 100644 (file)
@@ -23,6 +23,6 @@
 /**
  * A set is a collection without duplicates.
  */
-public interface Vala.Set<G> : Collection<G> {
+public abstract class Vala.Set<G> : Collection<G> {
 }