From efc98a00ee9fb59a995543b827ee635240308976 Mon Sep 17 00:00:00 2001 From: =?utf8?q?Roland=20H=C3=A4der?= Date: Sun, 6 Dec 2020 10:49:38 +0100 Subject: [PATCH] Continued: - minimum block length is the same for all file indexes and file-based stacks - merged 2 lines together in BaseFrameworkSystem class MIME-Version: 1.0 Content-Type: text/plain; charset=utf8 Content-Transfer-Encoding: 8bit Signed-off-by: Roland Häder --- .../classes/class_BaseFrameworkSystem.php | 7 ++--- .../main/classes/index/class_BaseIndex.php | 21 +++++++++++--- .../stacker/file/class_BaseFileStack.php | 28 ++++++++++++------- 3 files changed, 37 insertions(+), 19 deletions(-) diff --git a/framework/main/classes/class_BaseFrameworkSystem.php b/framework/main/classes/class_BaseFrameworkSystem.php index 526346ca..1ccedc9f 100644 --- a/framework/main/classes/class_BaseFrameworkSystem.php +++ b/framework/main/classes/class_BaseFrameworkSystem.php @@ -1003,11 +1003,8 @@ Loaded includes: * @return $executionTime Current execution time in nice braces */ protected function getPrintableExecutionTime () { - // Caculate the execution time - $executionTime = microtime(true) - $this->getStartupTime(); - - // Pack it in nice braces - $executionTime = sprintf('[ %01.5f ] ', $executionTime); + // Calculate execution time and pack it in nice braces + $executionTime = sprintf('[ %01.5f ] ', (microtime(true) - $this->getStartupTime())); // And return it return $executionTime; diff --git a/framework/main/classes/index/class_BaseIndex.php b/framework/main/classes/index/class_BaseIndex.php index 0392f36b..6ec08504 100644 --- a/framework/main/classes/index/class_BaseIndex.php +++ b/framework/main/classes/index/class_BaseIndex.php @@ -61,6 +61,11 @@ abstract class BaseIndex extends BaseFrameworkSystem { */ const SEPARATOR_GAP_LENGTH = 0x03; + /** + * Minimum block length + */ + private static $minimumBlockLength = 0; + /** * Protected constructor * @@ -224,13 +229,21 @@ abstract class BaseIndex extends BaseFrameworkSystem { * @return $length Minimum length for one entry/block */ public function calculateMinimumBlockLength () { - // Calulcate it + // Is it "cached"? /* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__, __LINE__)->debugOutput('BASE-INDEX: CALLED!'); - $length = BaseBinaryFile::LENGTH_TYPE + strlen(chr(BaseBinaryFile::SEPARATOR_TYPE_POSITION)) + BaseBinaryFile::LENGTH_POSITION + strlen(chr(BaseBinaryFile::SEPARATOR_ENTRIES)); + if (self::$minimumBlockLength == 0) { + // Calulcate it + self::$minimumBlockLength = ( + // Type + BaseBinaryFile::LENGTH_TYPE + strlen(chr(BaseBinaryFile::SEPARATOR_TYPE_POSITION)) + + // Position + BaseBinaryFile::LENGTH_POSITION + strlen(chr(BaseBinaryFile::SEPARATOR_ENTRIES)) + ); + } // Return it - /* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__, __LINE__)->debugOutput(sprintf('BASE-INDEX: length=%d - EXIT!', $length)); - return $length; + /* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__, __LINE__)->debugOutput(sprintf('BASE-INDEX: self::minimumBlockLength=%d - EXIT!', self::$minimumBlockLength)); + return self::$minimumBlockLength; } /** diff --git a/framework/main/classes/stacker/file/class_BaseFileStack.php b/framework/main/classes/stacker/file/class_BaseFileStack.php index a5fba08d..c11f58af 100644 --- a/framework/main/classes/stacker/file/class_BaseFileStack.php +++ b/framework/main/classes/stacker/file/class_BaseFileStack.php @@ -50,6 +50,11 @@ abstract class BaseFileStack extends BaseStacker implements StackableFile { // Exception codes const EXCEPTION_BAD_MAGIC = 0xe100; + /** + * Minimum block length + */ + private $minimumBlockLength = 0; + /** * Protected constructor * @@ -510,19 +515,22 @@ abstract class BaseFileStack extends BaseStacker implements StackableFile { * @return $length Minimum length for one entry/block */ public function calculateMinimumBlockLength () { - // Calulcate it + // Is the value "cached"? /* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__, __LINE__)->debugOutput('BASE-FILE-STACK: CALLED!'); - $length = - // Length of entry group - BaseBinaryFile::LENGTH_GROUP + strlen(chr(BaseBinaryFile::SEPARATOR_GROUP_HASH)) + - // Hash + value - self::getHashLength() + strlen(chr(BaseBinaryFile::SEPARATOR_HASH_VALUE)) + 1 + - // Final separator - strlen(chr(BaseBinaryFile::SEPARATOR_ENTRIES)); + if (self::$minimumBlockLength == 0) { + // Calulcate it + self::$minimumBlockLength = + // Length of entry group + BaseBinaryFile::LENGTH_GROUP + strlen(chr(BaseBinaryFile::SEPARATOR_GROUP_HASH)) + + // Hash + value + self::getHashLength() + strlen(chr(BaseBinaryFile::SEPARATOR_HASH_VALUE)) + 1 + + // Final separator + strlen(chr(BaseBinaryFile::SEPARATOR_ENTRIES)); + } // Return it - /* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__, __LINE__)->debugOutput(sprintf('BASE-FILE-STACK: length=%d - EXIT!', $length)); - return $length; + /* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__, __LINE__)->debugOutput(sprintf('BASE-FILE-STACK: self::minimumBlockLength=%d - EXIT!', self::$minimumBlockLength)); + return self::$minimumBlockLength; } /** -- 2.39.2