-
Notifications
You must be signed in to change notification settings - Fork 82
Speed up token value to name lookup #187
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Conversation
|
@TysonAndre, |
src/Token.php
Outdated
| return $mapToKind; | ||
| } | ||
|
|
||
| /** @return int (Or string, if $kindName wasn't found) */ |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
returns string, right?
src/Token.php
Outdated
| /** @return int (Or string, if $kindName wasn't found) */ | ||
| public static function getTokenKindNameFromValue($kindName) { | ||
| $mapToKind = self::getTokenKindNameFromValueMap(); | ||
| return $mapToKind[$kindName] ?? $kindName; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The variable names are confusing here (and they were like that before). $kindName the parameter is really the value? And I think it should return "" or null if it isn't found.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Was in a rush in the morning, noticed that $kindName was wrong but didn't fix it (Threw the rest of the documentation it was based off of off).
This appears to be used in generating debug data from the dumped values in tests, and I don't plan on changing the function behavior in this PR. (Having an unknown int is more useful than null if there actually was a bug)
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Sure. Thanks!
Grammar test suite sped up from 1.2 seconds to 1.1 seconds. This went from O(n) (loop over 183 constants) to O(1) (hash lookup)
5b09ade to
b98ede7
Compare
Grammar test suite sped up from 1.2 seconds to 1.1 seconds.
This went from O(n) (loop over (around half of) 183 constants) to O(1) (hash lookup)