From 9b1f72472f528846c5e09c5fb4d87e415457dce4 Mon Sep 17 00:00:00 2001 From: Eugen Wissner Date: Sat, 31 Mar 2018 08:21:15 +0200 Subject: [PATCH] Deprecate SList.length and DList.length As they have O(n) complexity. The lists length is unknown without iterating. --- source/tanya/container/list.d | 36 ++--------------------------------- 1 file changed, 2 insertions(+), 34 deletions(-) diff --git a/source/tanya/container/list.d b/source/tanya/container/list.d index 4c99906..fe62b5f 100644 --- a/source/tanya/container/list.d +++ b/source/tanya/container/list.d @@ -560,28 +560,12 @@ struct SList(T) assert(l1 == l2); } - /** - * Returns: How many elements are in the list. - */ + deprecated @property size_t length() const { return count(this[]); } - /// - @nogc nothrow pure @safe unittest - { - SList!int l; - - l.insertFront(8); - l.insertFront(9); - assert(l.length == 2); - l.removeFront(); - assert(l.length == 1); - l.removeFront(); - assert(l.length == 0); - } - /** * Comparison for equality. * @@ -1815,28 +1799,12 @@ struct DList(T) return insertAfter!(T[])(r, el[]); } - /** - * Returns: How many elements are in the list. - */ + deprecated @property size_t length() const { return count(this[]); } - /// - @nogc nothrow pure @safe unittest - { - DList!int l; - - l.insertFront(8); - l.insertFront(9); - assert(l.length == 2); - l.removeFront(); - assert(l.length == 1); - l.removeFront(); - assert(l.length == 0); - } - /** * Comparison for equality. *