From: Roland Häder Date: Thu, 30 Dec 2021 03:03:43 +0000 (+0100) Subject: Continued: X-Git-Url: https://git.mxchange.org/?a=commitdiff_plain;h=de6485401e841e0b9e91e435174bbce3458ebeff;p=core.git Continued: - caching config entry here saves a lot invocations Signed-off-by: Roland Häder --- diff --git a/framework/main/classes/file_directories/binary/class_BaseBinaryFile.php b/framework/main/classes/file_directories/binary/class_BaseBinaryFile.php index 43963e47..6d7cdecf 100644 --- a/framework/main/classes/file_directories/binary/class_BaseBinaryFile.php +++ b/framework/main/classes/file_directories/binary/class_BaseBinaryFile.php @@ -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;