[libgee] Improve the access to first and last elements in LinkedList
- From: Didier 'Ptitjes' Villevalois <dvillevalois src gnome org>
- To: svn-commits-list gnome org
- Cc:
- Subject: [libgee] Improve the access to first and last elements in LinkedList
- Date: Fri, 11 Sep 2009 19:13:41 +0000 (UTC)
commit fe54f3db46f671542a0cf2eeb9ccda48895ec995
Author: Julien Peeters <contact julienpeeters fr>
Date: Fri Sep 11 13:41:16 2009 +0200
Improve the access to first and last elements in LinkedList
Fixes part of bug 594868.
The signature of first and last properties in List did not take in account the
fact that lists permit null elements. Their type has been changed from G? to G
to reflect this.
Also we optimized the access to first and last elements in LinkedList, which can
be made through head and tail pointers directly.
gee/linkedlist.vala | 16 ++++++++++++++++
gee/list.vala | 8 ++++----
2 files changed, 20 insertions(+), 4 deletions(-)
---
diff --git a/gee/linkedlist.vala b/gee/linkedlist.vala
index 18ad724..d83869f 100644
--- a/gee/linkedlist.vala
+++ b/gee/linkedlist.vala
@@ -230,6 +230,22 @@ public class Gee.LinkedList<G> : AbstractList<G>, Queue<G>, Deque<G> {
/**
* @inheritDoc
*/
+ public override G first () {
+ assert (_size > 0);
+ return _head.data;
+ }
+
+ /**
+ * @inheritDoc
+ */
+ public override G last () {
+ assert (_size > 0);
+ return _tail.data;
+ }
+
+ /**
+ * @inheritDoc
+ */
public int? capacity {
get { return null; }
}
diff --git a/gee/list.vala b/gee/list.vala
index 29f1734..a692941 100644
--- a/gee/list.vala
+++ b/gee/list.vala
@@ -77,18 +77,18 @@ public interface Gee.List<G> : Collection<G> {
public abstract List<G>? slice (int start, int stop);
/**
- * Returns the first item of the list or null if list is empty.
+ * Returns the first item of the list. Fails if the list is empty.
*
* @return first item in the list
*/
- public abstract G? first ();
+ public abstract G first ();
/**
- * Returns the last item of the list or null if list is empty.
+ * Returns the last item of the list. Fails if the list is empty.
*
* @return last item in the list
*/
- public abstract G? last ();
+ public abstract G last ();
/**
* Inserts items into this list for the input collection at the
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]