From 52e6959c9c95c0a9246f45e0835d1224827be386 Mon Sep 17 00:00:00 2001 From: Piotr Sarnacki Date: Wed, 28 Nov 2012 01:00:44 +0100 Subject: [PATCH] Do not refresh entire LimitedArray if there is not such need --- assets/scripts/lib/travis/limited_array.coffee | 13 ++++++++++--- 1 file changed, 10 insertions(+), 3 deletions(-) diff --git a/assets/scripts/lib/travis/limited_array.coffee b/assets/scripts/lib/travis/limited_array.coffee index 2d9b6a52..b4f88a4a 100644 --- a/assets/scripts/lib/travis/limited_array.coffee +++ b/assets/scripts/lib/travis/limited_array.coffee @@ -43,7 +43,7 @@ Travis.LimitedArray = Em.ArrayProxy.extend arrangedContent = @get('arrangedContent') length = arrangedContent.get 'length' - if addedCount > 0 && length < limit + if addedCount > 0 addedObjects = array.slice(index, index + addedCount) for object in addedObjects arrangedContent.unshiftObject(object) @@ -52,7 +52,14 @@ Travis.LimitedArray = Em.ArrayProxy.extend removedObjects = array.slice(index, index + removedCount); arrangedContent.removeObjects(removedObjects) + length = arrangedContent.get 'length' + content = @get('content') + if length > limit arrangedContent.replace(limit, length - limit) - else if length < limit - @set('arrangedContent', @get('content').slice(0, @get('limit'))) + else if length < limit && content.get('length') > length + count = limit - length + while count > 0 + if next = content.find( (object) -> !arrangedContent.contains(object) ) + arrangedContent.unshiftObject(next) + count -= 1