Skip to content
Open
Show file tree
Hide file tree
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions src/Lexer/Lexer.php
Original file line number Diff line number Diff line change
Expand Up @@ -151,8 +151,8 @@ private function generateRegexp(): string

self::TOKEN_FLOAT => '(?:-?[0-9]++\\.[0-9]*+(?:e-?[0-9]++)?)|(?:-?[0-9]*+\\.[0-9]++(?:e-?[0-9]++)?)|(?:-?[0-9]++e-?[0-9]++)',
self::TOKEN_INTEGER => '-?(?:(?:0b[0-1]++)|(?:0o[0-7]++)|(?:0x[0-9a-f]++)|(?:[0-9]++))',
self::TOKEN_SINGLE_QUOTED_STRING => '\'(?:\\\\[^\\r\\n]|[^\'\\r\\n\\\\])*+\'',
self::TOKEN_DOUBLE_QUOTED_STRING => '"(?:\\\\[^\\r\\n]|[^"\\r\\n\\\\])*+"',
self::TOKEN_SINGLE_QUOTED_STRING => '\'(?:\\\\[^\\r\\n]|[^\'\\r\\n\\\\]++)*+\'',
self::TOKEN_DOUBLE_QUOTED_STRING => '"(?:\\\\[^\\r\\n]|[^"\\r\\n\\\\]++)*+"',

self::TOKEN_WILDCARD => '\\*',

Expand Down
5 changes: 4 additions & 1 deletion src/Parser/TokenIterator.php
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
namespace PHPStan\PhpDocParser\Parser;

use PHPStan\PhpDocParser\Lexer\Lexer;
use function array_flip;
use function array_pop;
use function assert;
use function count;
Expand Down Expand Up @@ -160,8 +161,10 @@ public function getSkippedHorizontalWhiteSpaceIfAny(): string
/** @phpstan-impure */
public function joinUntil(int ...$tokenType): string
{
$tokenTypeMap = array_flip($tokenType);
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

is this faster then array_fill_keys($tokenType, true)?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It's indistinguishable so changing to array_fill_keys() is fine by me :)


$s = '';
while (!in_array($this->tokens[$this->index][Lexer::TYPE_OFFSET], $tokenType, true)) {
while (!isset($tokenTypeMap[$this->tokens[$this->index][Lexer::TYPE_OFFSET]])) {
$s .= $this->tokens[$this->index++][Lexer::VALUE_OFFSET];
}
return $s;
Expand Down