]> git.mxchange.org Git - core.git/commitdiff
Continued:
authorRoland Häder <roland@mxchange.org>
Thu, 30 Dec 2021 03:03:43 +0000 (04:03 +0100)
committerRoland Häder <roland@mxchange.org>
Thu, 30 Dec 2021 03:03:43 +0000 (04:03 +0100)
- caching config entry here saves a lot invocations

Signed-off-by: Roland Häder <roland@mxchange.org>
framework/main/classes/file_directories/binary/class_BaseBinaryFile.php

index 43963e47b0b9e3661e933d0a9c59294f20480e71..6d7cdecff1ec78b0c8fcb0d29938e8b8b8b68d63 100644 (file)
@@ -46,6 +46,11 @@ abstract class BaseBinaryFile extends BaseAbstractFile implements BinaryFile {
        use StackableTrait;
        use IndexableTrait;
 
+       /**
+        * Configuration cache
+        */
+       private static $configCache = [];
+
        /**
         * Current seek position
         */
@@ -245,9 +250,15 @@ abstract class BaseBinaryFile extends BaseAbstractFile implements BinaryFile {
         * @return      void
         */
        private function markFileGapsOnly (string $type, int $minimumBlockLength) {
-               // Very simple to do ...
+               // Is config cache there?
                //* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__, __LINE__)->debugOutput(sprintf('BASE-BINARY-FILE: type=%s,minimumBlockLength=%d - CALLED!', $type, $minimumBlockLength));
-               for ($idx = 0; $idx < FrameworkBootstrap::getConfigurationInstance()->getConfigEntry($type . '_pre_allocate_count'); $idx++) {
+               if (!isset(self::$configCache[$type . '_pre_allocate_count'])) {
+                       // Then set it
+                       self::$configCache[$type . '_pre_allocate_count'] = FrameworkBootstrap::getConfigurationInstance()->getConfigEntry($type . '_pre_allocate_count');
+               }
+
+               // Very simple to do ...
+               for ($idx = 0; $idx < self::$configCache[$type . '_pre_allocate_count']; $idx++) {
                        // Calculate start/end positions
                        $startPosition = $idx * $minimumBlockLength;
                        $endPosition = $idx * $minimumBlockLength + $minimumBlockLength;