8000 Importing global functions - micro-optimisation, but relevant for thi… · reedy/reactphp-event-loop@75bead6 · GitHub
[go: up one dir, main page]

Skip to content

Commit 75bead6

Browse files
committed
Importing global functions - micro-optimisation, but relevant for this high-throughput component
1 parent 427853c commit 75bead6

9 files changed

+63
-63
lines changed

src/ExtEvLoop.php

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -92,7 +92,7 @@ public function addReadStream($stream, $listener)
9292
private function getStreamListenerClosure($stream, $listener)
9393
{
9494
return function () use ($stream, $listener) {
8000 95-
call_user_func($listener, $stream);
95+
\call_user_func($listener, $stream);
9696
};
9797
}
9898

@@ -140,7 +140,7 @@ public function addTimer($interval, $callback)
140140
$that = $this;
141141
$timers = $this->timers;
142142
$callback = function () use ($timer, $timers, $that) {
143-
call_user_func($timer->getCallback(), $timer);
143+
\call_user_func($timer->getCallback(), $timer);
144144

145145
if ($timers->contains($timer)) {
146146
$that->cancelTimer($timer);
@@ -158,7 +158,7 @@ public function addPeriodicTimer($interval, $callback)
158158
$timer = new Timer($interval, $callback, true);
159159

160160
$callback = function () use ($timer) {
161-
call_user_func($timer->getCallback(), $timer);
161+
\call_user_func($timer->getCallback(), $timer);
162162
};
163163

164164
$event = $this->loop->timer($interval, $interval, $callback);

src/ExtEventLoop.php

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -39,7 +39,7 @@ final class ExtEventLoop implements LoopInterface
3939

4040
public function __construct()
4141
{
42-
if (!class_exists('EventBase', false)) {
42+
if (!\class_exists('EventBase', false)) {
4343
throw new BadMethodCallException('Cannot create ExtEventLoop, ext-event extension missing');
4444
}
4545

@@ -225,7 +225,7 @@ private function createTimerCallback()
225225
{
226226
$timers = $this->timerEvents;
227227
$this->timerCallback = function ($_, $__, $timer) use ($timers) {
228-
call_user_func($timer->getCallback(), $timer);
228+
\call_user_func($timer->getCallback(), $timer);
229229

230230
if (!$timer->isPeriodic() && $timers->contains($timer)) {
231231
$this->cancelTimer($timer);
@@ -248,11 +248,11 @@ private function createStreamCallback()
248248
$key = (int) $stream;
249249

250250
if (Event::READ === (Event::READ & $flags) && isset($read[$key])) {
251-
call_user_func($read[$key], $stream);
251+
\call_user_func($read[$key], $stream);
252252
}
253253

254254
if (Event::WRITE === (Event::WRITE & $flags) && isset($write[$key])) {
255-
call_user_func($write[$key], $stream);
255+
\call_user_func($write[$key], $stream);
256256
}
257257
};
258258
}

src/ExtLibevLoop.php

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,7 @@ final class ExtLibevLoop implements LoopInterface
3737

3838
public function __construct()
3939
{
40-
if (!class_exists('libev\EventLoop', false)) {
40+
if (!\class_exists('libev\EventLoop', false)) {
4141
throw new BadMethodCallException('Cannot create ExtLibevLoop, ext-libev extension missing');
4242
}
4343

@@ -54,7 +54,7 @@ public function addReadStream($stream, $listener)
5454
}
5555

5656
$callback = function () use ($stream, $listener) {
57-
call_user_func($listener, $stream);
57+
\call_user_func($listener, $stream);
5858
};
5959

6060
$event = new IOEvent($callback, $stream, IOEvent::READ);
@@ -70,7 +70,7 @@ public function addWriteStream($stream, $listener)
7070
}
7171

7272
$callback = function () use ($stream, $listener) {
73-
call_user_func($listener, $stream);
73+
\call_user_func($listener, $stream);
7474
};
7575

7676
$event = new IOEvent($callback, $stream, IOEvent::WRITE);
@@ -108,7 +108,7 @@ public function addTimer($interval, $callback)
108108
$that = $this;
109109
$timers = $this->timerEvents;
110110
$callback = function () use ($timer, $timers, $that) {
111-
call_user_func($timer->getCallback(), $timer);
111+
\call_user_func($timer->getCallback(), $timer);
112112

113113
if ($timers->contains($timer)) {
114114
$that->cancelTimer($timer);
@@ -127,7 +127,7 @@ public function addPeriodicTimer($interval, $callback)
127127
$timer = new Timer($interval, $callback, true);
128128

129129
$callback = function () use ($timer) {
130-
call_user_func($timer->getCallback(), $timer);
130+
\call_user_func($timer->getCallback(), $timer);
131131
};
132132

133133
$event = new TimerEvent($callback, $interval, $interval);

src/ExtLibeventLoop.php

Lines changed: 31 additions & 31 deletions
Original file line numberDiff line numberDiff line change
@@ -53,11 +53,11 @@ final class ExtLibeventLoop implements LoopInterface
5353

5454
public function __construct()
5555
{
56-
if (!function_exists('event_base_new')) {
56+
if (!\function_exists('event_base_new')) {
5757
throw new BadMethodCallException('Cannot create ExtLibeventLoop, ext-libevent extension missing');
5858
}
5959

60-
$this->eventBase = event_base_new();
60+
$this->eventBase = \event_base_new();
6161
$this->futureTickQueue = new FutureTickQueue();
6262
$this->timerEvents = new SplObjectStorage();
6363
$this->signals = new SignalsHandler();
@@ -73,10 +73,10 @@ public function addReadStream($stream, $listener)
7373
return;
7474
}
7575

76-
$event = event_new();
77-
event_set($event, $stream, EV_PERSIST | EV_READ, $this->streamCallback);
78-
event_base_set($event, $this->eventBase);
79-
event_add($event);
76+
$event = \event_new();
77+
\event_set($event, $stream, EV_PERSIST | EV_READ, $this->streamCallback);
78+
\event_base_set($event, $this->eventBase);
79+
\event_add($event);
8080

8181
$this->readEvents[$key] = $event;
8282
$this->readListeners[$key] = $listener;
@@ -89,10 +89,10 @@ public function addWriteStream($stream, $listener)
8989
return;
9090
}
9191

92-
$event = event_new();
93-
event_set($event, $stream, EV_PERSIST | EV_WRITE, $this->streamCallback);
94-
event_base_set($event, $this->eventBase);
95-
event_add($event);
92+
$event = \event_new();
93+
\event_set($event, $stream, EV_PERSIST | EV_WRITE, $this->streamCallback);
94+
\event_base_set($event, $this->eventBase);
95+
EED3 \event_add($event);
9696

9797
$this->writeEvents[$key] = $event;
9898
$this->writeListeners[$key] = $listener;
@@ -104,8 +104,8 @@ public function removeReadStream($stream)
104104

105105
if (isset($this->readListeners[$key])) {
106106
$event = $this->readEvents[$key];
107-
event_del($event);
108-
event_free($event);
107+
\event_del($event);
108+
\event_free($event);
109109

110110
unset(
111111
$this->readEvents[$key],
@@ -120,8 +120,8 @@ public function removeWriteStream($stream)
120120

121121
if (isset($this->writeListeners[$key])) {
122122
$event = $this->writeEvents[$key];
123-
event_del($event);
124-
event_free($event);
123+
\event_del($event);
124+
\event_free($event);
125125

126126
unset(
127127
$this->writeEvents[$key],
@@ -152,8 +152,8 @@ public function cancelTimer(TimerInterface $timer)
152152
{
153153
if ($this->timerEvents->contains($timer)) {
154154
$event = $this->timerEvents[$timer];
155-
event_del($event);
156-
event_free($event);
155+
\event_del($event);
156+
\event_free($event);
157157

158158
$this->timerEvents->detach($timer);
159159
}
@@ -169,10 +169,10 @@ public function addSignal($signal, $listener)
169169
$this->signals->add($signal, $listener);
170170

171171
if (!isset($this->signalEvents[$signal])) {
172-
$this->signalEvents[$signal] = event_new();
173-
event_set($this->signalEvents[$signal], $signal, EV_PERSIST | EV_SIGNAL, array($this->signals, 'call'));
174-
event_base_set($this->signalEvents[$signal], $this->eventBase);
175-
event_add($this->signalEvents[$signal]);
172+
$this->signalEvents[$signal] = \event_new();
173+
\event_set($this->signalEvents[$signal], $signal, EV_PERSIST | EV_SIGNAL, array($this->signals, 'call'));
174+
\event_base_set($this->signalEvents[$signal], $this->eventBase);
175+
\event_add($this->signalEvents[$signal]);
176176
}
177177
}
178178

@@ -181,8 +181,8 @@ public function removeSignal($signal, $listener)
181181
$this->signals->remove($signal, $listener);
182182

183183
if (isset($this->signalEvents[$signal]) && $this->signals->count($signal) === 0) {
184-
event_del($this->signalEvents[$signal]);
185-
event_free($this->signalEvents[$signal]);
184+
\event_del($this->signalEvents[$signal]);
185+
\event_free($this->signalEvents[$signal]);
186186
unset($this->signalEvents[$signal]);
187187
}
188188
}
@@ -201,7 +201,7 @@ public function run()
201201
break;
202202
}
203203

204-
event_base_loop($this->eventBase, $flags);
204+
\event_base_loop($this->eventBase, $flags);
205205
}
206206
}
207207

@@ -217,11 +217,11 @@ public function stop()
217217
*/
218218
private function scheduleTimer(TimerInterface $timer)
219219
{
220-
$this->timerEvents[$timer] = $event = event_timer_new();
220+
$this->timerEvents[$timer] = $event = \event_timer_new();
221221

222-
event_timer_set($event, $this->timerCallback, $timer);
223-
event_base_set($event, $this->eventBase);
224-
event_add($event, $timer->getInterval() * self::MICROSECONDS_PER_SECOND);
222+
\event_timer_set($event, $this->timerCallback, $timer);
223+
\event_base_set($event, $this->eventBase);
224+
\event_add($event, $timer->getInterval() * self::MICROSECONDS_PER_SECOND);
225225
}
226226

227227
/**
@@ -236,7 +236,7 @@ private function createTimerCallback()
236236
$that = $this;
237237
$timers = $this->timerEvents;
238238
$this->timerCallback = function ($_, $__, $timer) use ($timers, $that) {
239-
call_user_func($timer->getCallback(), $timer);
239+
\call_user_func($timer->getCallback(), $timer);
240240

241241
// Timer already cancelled ...
242242
if (!$timers->contains($timer)) {
@@ -245,7 +245,7 @@ private function createTimerCallback()
245245

246246
// Reschedule periodic timers ...
247247
if ($timer->isPeriodic()) {
248-
event_add(
248+
\event_add(
249249
$timers[$timer],
250250
$timer->getInterval() * ExtLibeventLoop::MICROSECONDS_PER_SECOND
251251
);
@@ -272,11 +272,11 @@ private function createStreamCallback()
272272
$key = (int) $stream;
273273

274274
if (EV_READ === (EV_READ & $flags) && isset($read[$key])) {
275-
call_user_func($read[$key], $stream);
275+
\call_user_func($read[$key], $stream);
276276
}
277277

278278
if (EV_WRITE === (EV_WRITE & $flags) && isset($write[$key])) {
279-
call_user_func($write[$key], $stream);
279+
\call_user_func($write[$key], $stream);
280280
}
281281
};
282282
}

src/Factory.php

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -24,13 +24,13 @@ final class Factory
2424
public static function create()
2525
{
2626
// @codeCoverageIgnoreStart
27-
if (class_exists('libev\EventLoop', false)) {
27+
if (\class_exists('libev\EventLoop', false)) {
2828
return new ExtLibevLoop();
29-
} elseif (class_exists('EvLoop', false)) {
29+
} elseif (\class_exists('EvLoop', false)) {
3030
return new ExtEvLoop();
31-
} elseif (class_exists('EventBase', false)) {
31+
} elseif (\class_exists('EventBase', false)) {
3232
return new ExtEventLoop();
33-
} elseif (function_exists('event_base_new') && PHP_VERSION_ID < 70000) {
33+
} elseif (\function_exists('event_base_new') && PHP_VERSION_ID < 70000) {
3434
// only use ext-libevent on PHP < 7 for now
3535
return new ExtLibeventLoop();
3636
}

src/SignalsHandler.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@ public function add($signal, $listener)
1515
$this->signals[$signal] = array();
1616
}
1717

18-
if (in_array($listener, $this->signals[$signal])) {
18+
if (\in_array($listener, $this->signals[$signal])) {
1919
return;
2020
}
2121

src/StreamSelectLoop.php

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -68,7 +68,7 @@ public function __construct()
6868
{
6969
$this->futureTickQueue = new FutureTickQueue();
7070
$this->timers = new Timers();
71-
$this->pcntl = extension_loaded('pcntl');
71+
$this->pcntl = \extension_loaded('pcntl');
7272
$this->signals = new SignalsHandler();
7373
}
7474

@@ -235,15 +235,15 @@ private function waitForStreamActivity($timeout)
235235
$key = (int) $stream;
236236

237237
if (isset($this->readListeners[$key])) {
238-
call_user_func($this->readListeners[$key], $stream);
238+
\call_user_func($this->readListeners[$key], $stream);
239239
}
240240
}
241241

242242
foreach ($write as $stream) {
243243
$key = (int) $stream;
244244

245245
if (isset($this->writeListeners[$key])) {
246-
call_user_func($this->writeListeners[$key], $stream);
246+
\call_user_func($this->writeListeners[$key], $stream);
247247
}
248248
}
249249
}
@@ -265,10 +265,10 @@ private function streamSelect(array &$read, array &$write, $timeout)
265265
$except = null;
266266

267267
// suppress warnings that occur, when stream_select is interrupted by a signal
268-
return @stream_select($read, $write, $except, $timeout === null ? null : 0, $timeout);
268+
return @\stream_select($read, $write, $except, $timeout === null ? null : 0, $timeout);
269269
}
270270

271-
$timeout && usleep($timeout);
271+
$timeout && \usleep($timeout);
272272

273273
return 0;
274274
}

src/Tick/FutureTickQueue.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -42,7 +42,7 @@ public function tick()
4242
$count = $this->queue->count();
4343

4444
while ($count--) {
45-
call_user_func(
45+
\call_user_func(
4646
$this->queue->dequeue()
4747
);
4848
}

0 commit comments

Comments
 (0)
0