-
-
Notifications
You must be signed in to change notification settings - Fork 23k
Optimize find
in Array
and CowData
#84595
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
The array's find implementation looped through all elements, even after finding a corresponding element. On one hand this results in finding the last element (which is already available by rfind), but is also ineffient and can cause issues, when a partial element is followed by a complete element (finding the partial one can cause runtime errors) To clarify, I was using a comment indenting algorithm, that indented each comment based on their parent comment's level of indentation. It was known, that the parent comment will be positioned in the array, before any element without the indentation field (that's what I referred to as partial data) but this implementation caused an error
This is false, you are missing the This change can be an improvement, but the current code isn't wrong However I don't think this will result in any improvement, as any decent optimizing compiler will optimize out this aspect on its own |
find
in Array
and CowData
Yes, my bad, I did miss the break keyword when checking this out. The reason I dig into the source code, is that when I rewrote this same code in my own function inside my script, the error went away. Will do more investigation. |
The optimization might still be relevant, and to match the style of |
I don't see any harm, but it does look more like code style territory rather than performance. |
No harm indeed, just a matter of style as optimization will 99.9% optimize this out and generate the equivalent code, just needs to be updates to clarify there's no bug here just an optimization/style upgrade |
Hello, thank you again for opening this pull request! Edit: I'm just now noticing that there are changes to |
The array's find implementation looped through all elements, even after finding a corresponding element. On one hand this results in finding the last element (which is already available by rfind), but is also ineffient and can cause issues, when a partial element is followed by a complete element (finding the partial one can cause runtime errors)
To clarify, I was using a comment indenting algorithm, that indented each comment based on their parent comment's level of indentation. It was known, that the parent comment will be positioned in the array, before any element without the indentation field (that's what I referred to as partial data) but this implementation caused an error