Skip to content

Commit d9462d5

Browse files
authored
Merge pull request Seldaek#936 from zerkms/MICRO_OPT_FOREACH_INSTEAD_OF_CURRENT/NEXT
Replaced current/next-style loop with foreach
2 parents 772a470 + 59d3df2 commit d9462d5

File tree

1 file changed

+8
-5
lines changed

1 file changed

+8
-5
lines changed

src/Monolog/Logger.php

Lines changed: 8 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -281,14 +281,11 @@ public function addRecord(int $level, string $message, array $context = []): boo
281281
{
282282
// check if any handler will handle this message so we can return early and save cycles
283283
$handlerKey = null;
284-
reset($this->handlers);
285-
while ($handler = current($this->handlers)) {
284+
foreach ($this->handlers as $key => $handler) {
286285
if ($handler->isHandling(['level' => $level])) {
287-
$handlerKey = key($this->handlers);
286+
$handlerKey = $key;
288287
break;
289288
}
290-
291-
next($this->handlers);
292289
}
293290

294291
if (null === $handlerKey) {
@@ -311,6 +308,12 @@ public function addRecord(int $level, string $message, array $context = []): boo
311308
$record = call_user_func($processor, $record);
312309
}
313310

311+
// advance the array pointer to the first handler that will handle this record
312+
reset($this->handlers);
313+
while ($handlerKey !== key($this->handlers)) {
314+
next($this->handlers);
315+
}
316+
314317
while ($handler = current($this->handlers)) {
315318
if (true === $handler->handle($record)) {
316319
break;

0 commit comments

Comments
 (0)