Skip to content

Commit 7bf9c08

Browse files
committed
Avoid calling function in loops
1 parent d32733d commit 7bf9c08

File tree

1 file changed

+4
-3
lines changed

1 file changed

+4
-3
lines changed

src/Util/Tokens.php

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -979,8 +979,9 @@ public static function polyfillTokenizerConstants(): void
979979
// This variable is necessary to avoid collisions with any other
980980
// libraries which also polyfill T_* constants.
981981
// array_flip()/isset() because in_array() is slow.
982-
$existingConstants = array_flip(get_defined_constants(true)['tokenizer']);
983-
foreach ((get_defined_constants(true)['user'] ?? []) as $k => $v) {
982+
$allDefinedConstants = get_defined_constants(true);
983+
$existingConstants = array_flip($allDefinedConstants['tokenizer']);
984+
foreach (($allDefinedConstants['user'] ?? []) as $k => $v) {
984985
if (isset($k[2]) === false || $k[0] !== 'T' || $k[1] !== '_') {
985986
// We only care about T_* constants.
986987
continue;
@@ -996,7 +997,7 @@ public static function polyfillTokenizerConstants(): void
996997
$polyfillMappingTable = [];
997998

998999
foreach ($tokensToPolyfill as $tokenName) {
999-
if (isset(get_defined_constants(true)['tokenizer'][$tokenName]) === true) {
1000+
if (isset($allDefinedConstants['tokenizer'][$tokenName]) === true) {
10001001
// This is a PHP native token, which is already defined by PHP.
10011002
continue;
10021003
}

0 commit comments

Comments
 (0)