Skip to content

Reduce Token class call overhead #27

@staabm

Description

@staabm

when parsing lots of files, working with the Token class has some method call overhead.

Image

to reduce this to a minimum, we could turn this class into a pure value-object, meaning turn all properties readonly (which would require PHP8.1+) or even use a readonly class (which would require PHP8.2+) and turn all properties public:

<?php declare(strict_types = 1);
namespace TheSeer\Tokenizer;

readonly class Token {
    public function __construct(
      public int $line, 
      public string $name, 
      public string $value
     ) {}
}

that way accessing the data would get very fast


alternatively we could switch from token_get_all to PhpToken::tokenize() which internally uses a Token class similar to the above one.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions