From fe54f3db46f671542a0cf2eeb9ccda48895ec995 Mon Sep 17 00:00:00 2001 From: Julien Peeters Date: Fri, 11 Sep 2009 13:41:16 +0200 Subject: [PATCH] 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 : AbstractList, Queue, Deque { /** * @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 : Collection { public abstract List? 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 -- 2.7.4