merged branch drak/eventdispatcher_opimization (PR #2597)

Commits
-------

0fe8ac6 [EventDispatcher] Removed unused argument.

Discussion
----------

[EventDispatcher] Removed unused parameter in doDispatch().

Bug fix: no
Feature addition: no
Backwards compatibility break: no
Symfony2 tests pass: yes
Fixes the following tickets: -

Removed unused parameter.

---------------------------------------------------------------------------

by Seldaek at 2011/11/10 02:30:01 -0800

A simple $foo($arg) is faster than call_user_func, fine, but with all the if/else logic here are you sure it is still faster?

---------------------------------------------------------------------------

by drak at 2011/11/10 06:44:41 -0800

call_user_func is inordinately slow, I'll make some benchmarks. The if logic here is pretty, two conditionals for array callables or one conditional for closures/functions.

---------------------------------------------------------------------------

by drak at 2011/11/10 12:45:27 -0800

After doing some benchmarks, there are savings to be made in all cases except when the listener is an instantiated object when it's marginally slower, so I've reverted these changes and made this PR just to remove the unused argument in `doDispatch()`. You can see the benchmark code here: https://gist.github.com/1356129.

---------------------------------------------------------------------------

by drak at 2011/11/10 12:46:55 -0800

This PR is ready for consideration.
This commit is contained in:
Fabien Potencier 2011-11-11 08:31:28 +01:00
commit db6fea9fd0

View File

@ -47,7 +47,7 @@ class EventDispatcher implements EventDispatcherInterface
$event = new Event();
}
$this->doDispatch($this->getListeners($eventName), $eventName, $event);
$this->doDispatch($this->getListeners($eventName), $event);
}
/**
@ -150,10 +150,9 @@ class EventDispatcher implements EventDispatcherInterface
* for each listener.
*
* @param array[callback] $listeners The event listeners.
* @param string $eventName The name of the event to dispatch.
* @param Event $event The event object to pass to the event handlers/listeners.
*/
protected function doDispatch($listeners, $eventName, Event $event)
protected function doDispatch($listeners, Event $event)
{
foreach ($listeners as $listener) {
call_user_func($listener, $event);