Browse Source

Merge pull request #936 from zerkms/MICRO_OPT_FOREACH_INSTEAD_OF_CURRENT/NEXT

Replaced current/next-style loop with foreach
Jordi Boggiano 8 năm trước cách đây
mục cha
commit
d9462d50b0
1 tập tin đã thay đổi với 8 bổ sung5 xóa
  1. 8 5
      src/Monolog/Logger.php

+ 8 - 5
src/Monolog/Logger.php

@@ -281,14 +281,11 @@ class Logger implements LoggerInterface
     {
         // check if any handler will handle this message so we can return early and save cycles
         $handlerKey = null;
-        reset($this->handlers);
-        while ($handler = current($this->handlers)) {
+        foreach ($this->handlers as $key => $handler) {
             if ($handler->isHandling(['level' => $level])) {
-                $handlerKey = key($this->handlers);
+                $handlerKey = $key;
                 break;
             }
-
-            next($this->handlers);
         }
 
         if (null === $handlerKey) {
@@ -311,6 +308,12 @@ class Logger implements LoggerInterface
             $record = call_user_func($processor, $record);
         }
 
+        // advance the array pointer to the first handler that will handle this record
+        reset($this->handlers);
+        while ($handlerKey !== key($this->handlers)) {
+            next($this->handlers);
+        }
+
         while ($handler = current($this->handlers)) {
             if (true === $handler->handle($record)) {
                 break;