Skip to content
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

Use object composition rather than inheritance for HTTP::URI #325

Merged
merged 3 commits into from
Apr 3, 2016

Conversation

tarcieri
Copy link
Member

@tarcieri tarcieri commented Apr 3, 2016

The Addressable gem has been the source of a number of bugs and performance problems (e.g. #206, #297, #323)

Perhaps in the future it might be worth avoiding using it where ::URI would suffice, or getting rid of it entirely, but as things stand Addressable::URI is the parent class for HTTP::URI, which prevents us from doing that without making a breaking release of the library.

This replaces inheritance with object composition: Forwardable is used to delegate an explicit set of methods to Addressable::URI. This should make it easier to work around Addressable bugs or
potentially even use ::URI as the internal representation when URIs are simple enough.

tarcieri added 2 commits April 2, 2016 19:18
The Addressable gem has been the source of a number of bugs and
performance problems. Perhaps in the future it might be worth
avoiding using it where ::URI would suffice, or getting rid of
it entirely, but as things stand it's the parent class for
HTTP::URI, which prevents us from doing that without making a
breaking release of the library.

This replaces inheritence with object composition: Forwardable
is used to delegate an explicit set of methods to Addressable::URI.
This should make it easier to work around Addressable bugs or
potentially even use ::URI as the internal representation when
URIs are simple enough.
@tarcieri
Copy link
Member Author

tarcieri commented Apr 3, 2016

Bonus points: this now fixes #297

@ixti do you have strong feelings about this? I think this gives us more future flexibility around optimizations like e.g. using ::URI in the event a URI contains all "basic ASCII" and is already in its normalized form

@@ -141,7 +141,7 @@ def persistent(host)
return p_client unless block_given?
yield p_client
ensure
p_client.close
p_client.close unless p_client.nil?
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why not if p_client instead?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

👍 (probably should've done a separate commit/PR for that too, but I was lazy)

@ixti
Copy link
Member

ixti commented Apr 3, 2016

I think that's awesome! 👍

@tarcieri
Copy link
Member Author

tarcieri commented Apr 3, 2016

Sweet

@tarcieri tarcieri merged commit 96d276f into master Apr 3, 2016
@tarcieri tarcieri deleted the tonyarcieri/avoid-subclassing-addressable branch April 3, 2016 19:47
@tarcieri tarcieri mentioned this pull request Apr 3, 2016
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants