From 00bf94cd406f9c3ad6f6a4a4670b72c40f7e5328 Mon Sep 17 00:00:00 2001 From: turrsis Date: Thu, 8 May 2014 21:01:15 +0300 Subject: [PATCH 1/2] fix performance --- src/PriorityList.php | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/src/PriorityList.php b/src/PriorityList.php index 48becbd00..907e30629 100644 --- a/src/PriorityList.php +++ b/src/PriorityList.php @@ -192,7 +192,7 @@ public function rewind() */ public function current() { - $this->sort(); + $this->sorted || $this->sort(); $node = current($this->items); return ($node !== false ? $node['data'] : false); } @@ -205,6 +205,7 @@ public function current() */ public function key() { + $this->sorted || $this->sort(); return key($this->items); } From 771836880be44408657ae6268e4c357c7bdb4cb6 Mon Sep 17 00:00:00 2001 From: turrsis Date: Thu, 8 May 2014 21:04:52 +0300 Subject: [PATCH 2/2] add test --- test/PriorityListTest.php | 2 ++ 1 file changed, 2 insertions(+) diff --git a/test/PriorityListTest.php b/test/PriorityListTest.php index 0cc7669d1..c102a70b9 100644 --- a/test/PriorityListTest.php +++ b/test/PriorityListTest.php @@ -176,6 +176,8 @@ public function testCurrent() $this->list->insert('foo', 'foo_value', null); $this->list->insert('bar', 'bar_value', 1); $this->list->insert('baz', 'baz_value', -1); + + $this->assertEquals('bar', $this->list->key()); $this->assertEquals('bar_value', $this->list->current()); }