-
Notifications
You must be signed in to change notification settings - Fork 144
[CLEANUP] Don't store array length as a property #954
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
Merged
Merged
Conversation
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
264d15c
to
521415c
Compare
oliverklee
requested changes
Feb 19, 2025
#958 is merged now. |
This PR now is in need of rebasing. |
d26ead4
to
1ff05e9
Compare
Done. Was tricky, and at times I wondered if restarting from scratch would be easier. |
oliverklee
approved these changes
Feb 20, 2025
Since PHP 5, if not earlier, the length of an array is internally stored by PHP and can be accessed in O(1) time. Maintaining both the array and its length in class properties is error-prone (particularly regarding possible future code changes). When used in a loop, `\count($array)` is more repetitively expensive than `$arrayLength`, but the latter can be set up as a local variable as and when needed. Reference: https://stackoverflow.com/questions/5835241/is-phps-count-function-o1-or-on-for-arrays This change also ensures that the characters are always a (dazzling) array. Resolves #953.
oliverklee
requested changes
Feb 20, 2025
1ff05e9
to
1c14dd5
Compare
Co-authored-by: Oliver Klee <[email protected]>
oliverklee
approved these changes
Feb 20, 2025
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Since PHP 5, if not earlier, the length of an array is internally stored by PHP and can be accessed in O(1) time.
Maintaining both the array and its length in class properties is error-prone (particularly regarding possible future code changes). When used in a loop,
\count($array)
is more repetitively expensive than$arrayLength
,but the latter can be set up as a local variable as and when needed.
Reference:
https://stackoverflow.com/questions/5835241/is-phps-count-function-o1-or-on-for-arrays
This change also ensures that the characters are always a (dazzling) array.
Resolves #953.