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
fix: avoid some allocations of strings #387
Conversation
🍏 @dentarg |
@normalized_host.force_encoding(Encoding::UTF_8) if @normalized_host | ||
unless @normalized_host.empty? | ||
@normalized_host.force_encoding(Encoding::UTF_8) | ||
end |
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.
Is it guaranteed that @normalized_host
will always respond to #empty?
. The previous code guarded against nil
(Maybe it wasn't necessary or the test coverage we have isn't sufficient, I don't know)
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.
Ah...ok, but @normalized_host
can be empty string, so it is proper way?
if @normalized_host && !@normalized_host.empty?
@normalized_host.force_encoding(Encoding::UTF_8)
end
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.
Yeah
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.
What if @normalized_host
is an empty string but not UTF-8
encoded..?
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.
I think that it will not be have matter because url without host is wrong url
🤔
it is may be have sense to add condition on emptiness at this line:
addressable/lib/addressable/uri.rb
Line 1246 in 0f468ea
authority << self.normalized_host |
🆙 |
🤔 |
Merged #383 before this one as requested. |
@dentarg Any updates on this? |
pinging @dentarg @sporkmonger |
Hello!
In this commit I suggest some optimizations for avoid unnecessary strings allocations
Before (our loop of mail delivery):
After:
no any conversions from nil to empty string