From febcc20001e54d4dcbc9a6b94afd5f7d061de7f1 Mon Sep 17 00:00:00 2001 From: Dennis Eichhorn Date: Wed, 4 Oct 2023 23:57:10 +0000 Subject: [PATCH] improve grammar performance --- DataStorage/Database/GrammarAbstract.php | 25 ++++++++++++------------ 1 file changed, 13 insertions(+), 12 deletions(-) diff --git a/DataStorage/Database/GrammarAbstract.php b/DataStorage/Database/GrammarAbstract.php index ab34a8603..7b27e7863 100755 --- a/DataStorage/Database/GrammarAbstract.php +++ b/DataStorage/Database/GrammarAbstract.php @@ -226,16 +226,16 @@ abstract class GrammarAbstract $identifierStart = $this->systemIdentifierStart; $identifierEnd = $this->systemIdentifierEnd; - if (\stripos($system, '(') !== false) { - $identifierStart = ''; - $identifierEnd = ''; - } + // @todo: maybe the if/elseif has to get swapped in order. There could be a count(table.name) for example + if ((\stripos($system, '.')) !== false) { + // The following code could have been handled with \explode more elegantly but \explode needs more memory and more time + // Normally this wouldn't be a problem but in this case there are so many function calls to this routine, + // that it makes sense to make this "minor" improvement. - // The following code could have been handled with \explode more elegantly but \explode needs more memory and more time - // Normally this wouldn't be a problem but in this case there are so many function calls to this routine, - // that it makes sense to make this "minor" improvement. - if (($pos = \stripos($system, '.')) !== false) { - $split = [\substr($system, 0, $pos), \substr($system, $pos + 1)]; + // This is actually slower than \explode(), despite knowing the first index + //$split = [\substr($system, 0, $pos), \substr($system, $pos + 1)]; + + $split = \explode('.', $system); $identifierTwoStart = $identifierStart; $identifierTwoEnd = $identifierEnd; @@ -248,9 +248,10 @@ abstract class GrammarAbstract return $identifierStart . $split[0] . $identifierEnd . '.' . $identifierTwoStart . $split[1] . $identifierTwoEnd; - } - - if ($system === '*') { + } elseif ($system === '*' + || \stripos($system, '(') !== false + || \is_numeric($system) + ) { $identifierStart = ''; $identifierEnd = ''; }