-
Notifications
You must be signed in to change notification settings - Fork 62
Performance increasement by integer priority #17
Changes from all commits
3834843
263a6eb
9d10eec
29d9577
8a0320c
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -66,13 +66,16 @@ private function getListenersForEvent($event, EventManager $events, $withPriorit | |
{ | ||
$r = new ReflectionProperty($events, 'events'); | ||
$r->setAccessible(true); | ||
$listeners = $r->getValue($events); | ||
$internal = $r->getValue($events); | ||
|
||
if (! isset($listeners[$event])) { | ||
return $this->traverseListeners([]); | ||
$listeners = []; | ||
foreach (isset($internal[$event]) ? $internal[$event] : [] as $p => $listOfListeners) { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Better naming needed |
||
foreach ($listOfListeners as $l) { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. better naming needed (do not abbreviate) |
||
$listeners[$p] = isset($listeners[$p]) ? array_merge($listeners[$p], $l) : $l; | ||
} | ||
} | ||
|
||
return $this->traverseListeners($listeners[$event], $withPriority); | ||
return $this->traverseListeners($listeners, $withPriority); | ||
} | ||
|
||
/** | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -27,7 +27,7 @@ public function setUp() | |
|
||
public function getListeners(SharedEventManager $manager, array $identifiers, $event, $priority = 1) | ||
{ | ||
$priority = (int) $priority . '.0'; | ||
$priority = (int) $priority; | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Note to self: this will affect every single component we've upgraded that implements a "getListeners" method of some sort for introspecting attached listeners. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Which may be a rationale for re-instating the getListeners() method. That said, it could be marked private, and libraries could use reflection in order to query it. This is me brainstorming via github comments. Sue me. |
||
$listeners = $manager->getListeners($identifiers, $event); | ||
if (! isset($listeners[$priority])) { | ||
return []; | ||
|
@@ -247,7 +247,7 @@ public function testClearListenersDoesNothingIfNoEventsRegisteredForIdentifier() | |
$this->manager->clearListeners('IDENTIFIER', 'EVENT'); | ||
|
||
// getListeners() always pulls in wildcard listeners | ||
$this->assertEquals(['1.0' => [ | ||
$this->assertEquals([1 => [ | ||
$this->callback, | ||
]], $this->manager->getListeners([ 'IDENTIFIER' ], 'EVENT')); | ||
} | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
We can now use argument unpacking! \o/
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Oh, wait... package still supports PHP 5.5... @weierophinney are you fine with dropping 5.5 for 3.1.0?