-
Notifications
You must be signed in to change notification settings - Fork 5.3k
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
Improve performance of URI#hostname(=) [RM#17219] #3635
Conversation
lib/uri/generic.rb
Outdated
@@ -659,7 +659,7 @@ def hostname | |||
# it is wrapped with brackets. | |||
# | |||
def hostname=(v) | |||
v = "[#{v}]" if /\A\[.*\]\z/ !~ v && /:/ =~ v | |||
v = "[#{v}]" if v.index(':') && v[0] != '[' && v[-1] != ']' |
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.
For the record, I have measured that '[' + v + ']'
is actually a bit slower than interpolation. So keeping this as-is.
Have you tried |
I guess this patch should be submitted to the URI repo? https://github.com/ruby/uri |
124260a
to
de19de5
Compare
I haven't, I have considered it for a moment and thought that I also corrected a test failure (nil pointer exception missed).
Okay, apologies this is my first contribution. I tried to research contributing guides, looks like RedMine is preferred. I will update and close this PR, file new one as you recommend and also update the RM ticket with a patch. Thanks. |
There is still a failure, looking into this. I was only running rspec tests locally, this is another suite. |
de19de5
to
2a30841
Compare
No need to apologize. This repo is being synced with gem repos. Probably this patch should be submitted to the URI repo and then it will be synced here. |
2a30841
to
51b6be5
Compare
Okay, thanks. Moved to: ruby/uri#12 |
Hello,
URI#hostname extends URI#host with IPv6 support. In URI, IPv6 address must have square brackets (e.g.
http://[2001:db8::1]
), URI#hostname strips these characters out while URI#hostname= adds them if missing. There are three regular expressions to perform these tasks which can dramatically slow down performance. I am attaching a two-line patch and here is a benchmark: https://gist.github.com/lzap/24cbecb47daf29111350e41a24250922https://bugs.ruby-lang.org/issues/17219