Created
August 19, 2013 23:27
-
-
Save jacobo/6275395 to your computer and use it in GitHub Desktop.
my pull request
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
| From 767031e6fc1f313b29a982dc2f315596ac97bf47 Mon Sep 17 00:00:00 2001 | |
| From: Jacob Burkhart & Martin Emde <[email protected]> | |
| Date: Mon, 19 Aug 2013 16:25:02 -0700 | |
| Subject: [PATCH] Optimize more by not using normalized_ methods | |
| --- | |
| Rakefile | 9 ++++++--- | |
| lib/gitable/scp_uri.rb | 10 +++++----- | |
| lib/gitable/uri.rb | 5 ++--- | |
| 3 files changed, 13 insertions(+), 11 deletions(-) | |
| diff --git a/Rakefile b/Rakefile | |
| index c1e153b..a611d0a 100644 | |
| --- a/Rakefile | |
| +++ b/Rakefile | |
| @@ -14,6 +14,7 @@ end | |
| task :benchmark do | |
| require 'benchmark' | |
| + require 'uri' | |
| require File.expand_path('lib/gitable/uri', File.dirname(__FILE__)) | |
| n = 10000 | |
| @@ -21,8 +22,10 @@ task :benchmark do | |
| uri = "git://github.com/martinemde/gitable.git" | |
| dup = Gitable::URI.parse(uri) | |
| Benchmark.bmbm do |x| | |
| - x.report('dup') { n.times { Gitable::URI.parse(dup) } } | |
| - x.report(uri) { n.times { Gitable::URI.parse(uri) } } | |
| - x.report(scp) { n.times { Gitable::URI.parse(scp) } } | |
| + x.report('dup') { n.times { Gitable::URI.parse(dup) } } | |
| + x.report(uri) { n.times { Gitable::URI.parse(uri) } } | |
| + x.report(scp) { n.times { Gitable::URI.parse(scp) } } | |
| + x.report("addressable") { n.times { Addressable::URI.parse(uri) } } | |
| + x.report("uri") { n.times { URI.parse(uri) } } | |
| end | |
| end | |
| diff --git a/lib/gitable/scp_uri.rb b/lib/gitable/scp_uri.rb | |
| index ff91bba..81716ea 100644 | |
| --- a/lib/gitable/scp_uri.rb | |
| +++ b/lib/gitable/scp_uri.rb | |
| @@ -33,7 +33,7 @@ module Gitable | |
| super | |
| if new_path[0..0] != '/' # addressable adds a / but scp-style uris are altered by this behavior | |
| @path = path.sub(%r|^/+|,'') | |
| - @normalized_path = normalized_path.sub(%r|^/+|,'') | |
| + @normalized_path = nil | |
| validate | |
| end | |
| path | |
| @@ -82,19 +82,19 @@ module Gitable | |
| def validate | |
| return if @validation_deferred | |
| - if normalized_host.to_s.empty? | |
| + if host.to_s.empty? | |
| raise InvalidURIError, "Hostname segment missing: '#{to_s}'" | |
| end | |
| - unless normalized_scheme.to_s.empty? | |
| + unless scheme.to_s.empty? | |
| raise InvalidURIError, "Scp style URI must not have a scheme: '#{to_s}'" | |
| end | |
| - if !normalized_port.to_s.empty? | |
| + if !port.to_s.empty? | |
| raise InvalidURIError, "Scp style URI cannot have a port: '#{to_s}'" | |
| end | |
| - if normalized_path.to_s.empty? | |
| + if path.to_s.empty? | |
| raise InvalidURIError, "Absolute URI missing hierarchical segment: '#{to_s}'" | |
| end | |
| diff --git a/lib/gitable/uri.rb b/lib/gitable/uri.rb | |
| index 78332af..ef2c443 100644 | |
| --- a/lib/gitable/uri.rb | |
| +++ b/lib/gitable/uri.rb | |
| @@ -50,9 +50,8 @@ module Gitable | |
| authority = scheme | |
| end | |
| - if host.nil? && uri.match(SCP_REGEXP) | |
| - authority, path = uri.scan(SCP_REGEXP).flatten | |
| - Gitable::ScpURI.new(:authority => authority, :path => path) | |
| + if host.nil? && (parts = uri.scan(SCP_REGEXP)) && parts.any? | |
| + Gitable::ScpURI.new(:authority => parts.first[0], :path => parts.first[1]) | |
| else | |
| new( | |
| :scheme => scheme, | |
| -- | |
| 1.7.4.4 | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment