ソースを参照

avoid function call when not needed; use single variable instead of two

The Digital Orchard 7 年 前
コミット
0b76b0b36a

+ 6 - 3
src/Monolog/Processor/MemoryPeakUsageProcessor.php

@@ -21,10 +21,13 @@ class MemoryPeakUsageProcessor extends MemoryProcessor
 {
     public function __invoke(array $record): array
     {
-        $bytes = memory_get_peak_usage($this->realUsage);
-        $formatted = $this->formatBytes($bytes);
+        $usage = memory_get_peak_usage($this->realUsage);
 
-        $record['extra']['memory_peak_usage'] = $formatted;
+        if ($this->useFormatting) {
+            $usage = $this->formatBytes($usage);
+        }
+
+        $record['extra']['memory_peak_usage'] = $usage;
 
         return $record;
     }

+ 6 - 3
src/Monolog/Processor/MemoryUsageProcessor.php

@@ -21,10 +21,13 @@ class MemoryUsageProcessor extends MemoryProcessor
 {
     public function __invoke(array $record): array
     {
-        $bytes = memory_get_usage($this->realUsage);
-        $formatted = $this->formatBytes($bytes);
+        $usage = memory_get_usage($this->realUsage);
 
-        $record['extra']['memory_usage'] = $formatted;
+        if ($this->useFormatting) {
+            $usage = $this->formatBytes($usage);
+        }
+
+        $record['extra']['memory_usage'] = $usage;
 
         return $record;
     }