Skip to content

Further improves getDefinedFunctionsInFile()#9249

Merged
live627 merged 1 commit into
SimpleMachines:release-3.0from
live627:fns
Jun 3, 2026
Merged

Further improves getDefinedFunctionsInFile()#9249
live627 merged 1 commit into
SimpleMachines:release-3.0from
live627:fns

Conversation

@live627

@live627 live627 commented May 31, 2026

Copy link
Copy Markdown
Contributor

Support functions with union types and classes that extend fully qualified types

Can now parse nearly the entire SMF codebase as seen in my very long result set https://github.com/live627/benchmark-tests/blob/main/smf/fns.txt

My comparison script https://github.com/live627/benchmark-tests/blob/main/smf/fns.php

Support functions with union types and classes that   extend fully qualified types
@live627 live627 merged commit ab820c3 into SimpleMachines:release-3.0 Jun 3, 2026
4 checks passed
@live627 live627 deleted the fns branch June 3, 2026 12:44
Comment on lines +2308 to +2310
// Remove multiline comments so regex does not
// match fake functions/classes inside them.
$source = preg_replace('~//[^\h]+|/\*.*?\*/~s', '', $source);

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Suggested change
// Remove multiline comments so regex does not
// match fake functions/classes inside them.
$source = preg_replace('~//[^\h]+|/\*.*?\*/~s', '', $source);
// Remove multiline comments so regex does not
// match fake functions/classes inside them.
$source = Config::stripPhpComments($source);

This would produce more thorough and reliable results.

Can I get you to submit a follow-up PR making this change, @live627?

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

I hadn't noticed that function before now. I'm testing it now. It's quite a bit slower: the one with the token takes 0.43s, while the custom algorithm takes 0.38s. The one in this branch takes 0.08s.

That custom implementation also missed a function.

(new regex = mine, old regex = your suggested change without the tokenizer)

Files:        1599
Iterations:   1

New regex total: 79.910 ms
Old regex total: 378.003 ms

New regex avg:   79.910 ms
Old regex avg:   378.003 ms

Speedup:         4.73x (new regex faster)

New regex count: 4420
Old regex count: 4419

Differences detected:

../../smf2.1/sources\Subs-Compat.php
  New regex only:
    + package_crypt

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants