From de6485401e841e0b9e91e435174bbce3458ebeff Mon Sep 17 00:00:00 2001 From: =?utf8?q?Roland=20H=C3=A4der?= Date: Thu, 30 Dec 2021 04:03:43 +0100 Subject: [PATCH] Continued: - caching config entry here saves a lot invocations MIME-Version: 1.0 Content-Type: text/plain; charset=utf8 Content-Transfer-Encoding: 8bit Signed-off-by: Roland Häder --- .../binary/class_BaseBinaryFile.php | 15 +++++++++++++-- 1 file changed, 13 insertions(+), 2 deletions(-) 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; -- 2.39.2