[vala/0.10-parallel: 2/32] gee: Replace interfaces by abstract classes to improve performance



commit 28cee66a6207dd2c0956265f2a49fdd34979ccee
Author: Jürg Billeter <j bitron ch>
Date:   Wed Aug 11 22:23:09 2010 +0200

    gee: Replace interfaces by abstract classes to improve performance

 gee/Makefile.am           |    1 -
 gee/arraylist.vala        |   32 +++++++++++-----------
 gee/collection.vala       |    2 +-
 gee/collectionobject.vala |   30 ---------------------
 gee/hashmap.vala          |   62 ++++++++++++++++++++++----------------------
 gee/hashset.vala          |   22 ++++++++--------
 gee/iterable.vala         |    2 +-
 gee/iterator.vala         |    2 +-
 gee/list.vala             |    2 +-
 gee/map.vala              |    2 +-
 gee/set.vala              |    2 +-
 11 files changed, 64 insertions(+), 95 deletions(-)
---
diff --git a/gee/Makefile.am b/gee/Makefile.am
index 15f3e9b..ab31565 100644
--- a/gee/Makefile.am
+++ b/gee/Makefile.am
@@ -14,7 +14,6 @@ noinst_LTLIBRARIES = \
 libgee_la_VALASOURCES = \
 	arraylist.vala \
 	collection.vala \
-	collectionobject.vala \
 	hashmap.vala \
 	hashset.vala \
 	iterable.vala \
diff --git a/gee/arraylist.vala b/gee/arraylist.vala
index b8dd485..5d2b392 100644
--- a/gee/arraylist.vala
+++ b/gee/arraylist.vala
@@ -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) {
diff --git a/gee/collection.vala b/gee/collection.vala
index 11ea97a..6a652fc 100644
--- a/gee/collection.vala
+++ b/gee/collection.vala
@@ -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/hashmap.vala b/gee/hashmap.vala
index 79bcf1c..5159fe3 100644
--- a/gee/hashmap.vala
+++ b/gee/hashmap.vala
@@ -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;
diff --git a/gee/hashset.vala b/gee/hashset.vala
index 7f188e1..01452c6 100644
--- a/gee/hashset.vala
+++ b/gee/hashset.vala
@@ -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;
diff --git a/gee/iterable.vala b/gee/iterable.vala
index a95bd73..b0097ac 100644
--- a/gee/iterable.vala
+++ b/gee/iterable.vala
@@ -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 ();
 
 	/**
diff --git a/gee/iterator.vala b/gee/iterator.vala
index 9677e88..5190fb6 100644
--- a/gee/iterator.vala
+++ b/gee/iterator.vala
@@ -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.
 	 *
diff --git a/gee/list.vala b/gee/list.vala
index 3f13576..e11399c 100644
--- a/gee/list.vala
+++ b/gee/list.vala
@@ -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.
 	 *
diff --git a/gee/map.vala b/gee/map.vala
index c98eeb4..e78f794 100644
--- a/gee/map.vala
+++ b/gee/map.vala
@@ -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.
 	 */
diff --git a/gee/set.vala b/gee/set.vala
index 03c28da..6449023 100644
--- a/gee/set.vala
+++ b/gee/set.vala
@@ -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> {
 }
 



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