Add has_extension() method to String#109433
Merged
Repiteo merged 1 commit intogodotengine:masterfrom Oct 31, 2025
Merged
Conversation
ff83d70 to
c8058e7
Compare
timothyqiu
reviewed
Aug 10, 2025
Ivorforce
reviewed
Aug 11, 2025
Member
There was a problem hiding this comment.
I'm not sure adding this is worth it without profiling evidence. This is especially true because we're once again adding two implementations (one for String and one for const char *, doubling the LOC added.
While I think semantically wrapping operations like this is nice, it's possible to implement it just with the current unoptimized version (lower() == p_ext). We can always optimize if it bottlenecks us anywhere.
Member
Author
|
Pushed the simpler version. I did a simple benchmark and it's 2.3 times slower, but yeah, it's unlikely to be a bottleneck, so whatever. |
AThousandShips
approved these changes
Aug 12, 2025
Member
AThousandShips
left a comment
There was a problem hiding this comment.
I think this makes sense as a useful shorthand, minor details only
Contributor
|
Thanks! |
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
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.
I noticed we have lots of code like
path.get_extension().to_lower() == "ext". Theto_lower()part isn't used consistently (while extensions should always be case insensitive), and the 2 calls will make 2 temporary strings, which while doesn't not really matter, is rather bad.This PR adds a
has_extension()method (not exposed) that does case-insensitive check of file's extension. I went over all usages ofget_extension()and applied the new method where applicable.