From cb8193f663ea44cf766af6f759f1a58481c92f23 Mon Sep 17 00:00:00 2001 From: Vadim Lopatin Date: Thu, 7 Sep 2017 10:53:18 +0300 Subject: [PATCH] support asArray for sorting items - for buggins/dlangide#250 --- src/dlangui/core/collections.d | 13 ++++++++++--- 1 file changed, 10 insertions(+), 3 deletions(-) diff --git a/src/dlangui/core/collections.d b/src/dlangui/core/collections.d index 6e7899d5..ac3b36d0 100644 --- a/src/dlangui/core/collections.d +++ b/src/dlangui/core/collections.d @@ -324,10 +324,10 @@ struct ObjectList(T) { } } /** remove and destroy all items */ - void clear(bool destroyObj = true) { + void clear(bool destroyObj = true) { for (int i = 0; i < _count; i++) { - if(destroyObj) { - destroy(_list[i]); + if(destroyObj) { + destroy(_list[i]); } _list[i] = null; } @@ -343,6 +343,13 @@ struct ObjectList(T) { } return res; } + /// Get items array slice. Don't try to resize it! + T[] asArray() { + if (!_count) + return null; + return _list[0.._count]; + } + /// destructor destroys all items ~this() { clear(); }