mirror of
https://github.com/nikic/PHP-Parser.git
synced 2025-01-16 22:58:15 +01:00
Improve performance of find() and findFirst() when passed $nodes is empty array
This commit is contained in:
parent
4e27a17cd8
commit
481fec47f4
@ -15,6 +15,10 @@ class NodeFinder {
|
||||
* @return Node[] Found nodes satisfying the filter callback
|
||||
*/
|
||||
public function find($nodes, callable $filter): array {
|
||||
if ($nodes === []) {
|
||||
return [];
|
||||
}
|
||||
|
||||
if (!is_array($nodes)) {
|
||||
$nodes = [$nodes];
|
||||
}
|
||||
@ -52,6 +56,10 @@ class NodeFinder {
|
||||
* @return null|Node Found node (or null if none found)
|
||||
*/
|
||||
public function findFirst($nodes, callable $filter): ?Node {
|
||||
if ($nodes === []) {
|
||||
return null;
|
||||
}
|
||||
|
||||
if (!is_array($nodes)) {
|
||||
$nodes = [$nodes];
|
||||
}
|
||||
|
Loading…
x
Reference in New Issue
Block a user