X-Git-Url: http://git.cyclocoop.org/%28?a=blobdiff_plain;f=includes%2Futils%2FClassCollector.php;h=cf62f6d008a6661c145d1b242f371faf248c9913;hb=60882bb6b07aa0a9cbf0f8a2224cc94e2575dc11;hp=c987354d37373b86ba9e87a8623657fa750ceec6;hpb=a192a7a7287bb0c5afeb8993ecc922692d554f5f;p=lhc%2Fweb%2Fwiklou.git diff --git a/includes/utils/ClassCollector.php b/includes/utils/ClassCollector.php index c987354d37..cf62f6d008 100644 --- a/includes/utils/ClassCollector.php +++ b/includes/utils/ClassCollector.php @@ -39,7 +39,7 @@ class ClassCollector { protected $startToken; /** - * @var array List of tokens that are members of the current expect sequence + * @var array[]|string[] List of tokens that are members of the current expect sequence */ protected $tokens; @@ -59,6 +59,31 @@ class ClassCollector { $this->alias = null; $this->tokens = []; + // HACK: The PHP tokenizer is slow (T225730). + // Speed it up by reducing the input to the three kinds of statement we care about: + // - namespace X; + // - [final] [abstract] class X … {} + // - class_alias( … ); + $lines = []; + $matches = null; + preg_match_all( + // phpcs:ignore Generic.Files.LineLength.TooLong + '#^\t*(?:namespace |(final )?(abstract )?(class|interface|trait) |class_alias\()[^;{]+[;{]\s*\}?#m', + $code, + $matches + ); + if ( isset( $matches[0][0] ) ) { + foreach ( $matches[0] as $match ) { + $match = trim( $match ); + if ( substr( $match, -1 ) === '{' ) { + // Keep it balanced + $match .= '}'; + } + $lines[] = $match; + } + } + $code = 'startToken === null ) { $this->tryBeginExpect( $token ); @@ -101,7 +126,7 @@ class ClassCollector { /** * Accepts the next token in an expect sequence * - * @param array $token + * @param array|string $token */ protected function tryEndExpect( $token ) { switch ( $this->startToken[0] ) {