Skip to content

Commit 409854f

Browse files
jpervillegkellogg
authored andcommitted
Optimize RDF::URI part readers by returning value without passing through ||=`
See fastruby/fast-ruby#133 for discussion.
1 parent 9e44c5e commit 409854f

1 file changed

Lines changed: 5 additions & 3 deletions

File tree

lib/rdf/model/uri.rb

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -223,6 +223,7 @@ def self.normalize_path(path)
223223
# @param [Boolean] validate (false)
224224
# @param [Boolean] canonicalize (false)
225225
def initialize(*args, validate: false, canonicalize: false, **options)
226+
@value = @object = @hash = nil
226227
uri = args.first
227228
if uri
228229
@value = uri.to_s
@@ -795,7 +796,8 @@ def inspect
795796
# lexical representation of URI, either absolute or relative
796797
# @return [String]
797798
def value
798-
@value ||= [
799+
return @value if @value
800+
@value = [
799801
("#{scheme}:" if absolute?),
800802
("//#{authority}" if authority),
801803
path,
@@ -809,15 +811,15 @@ def value
809811
#
810812
# @return [Integer]
811813
def hash
812-
@hash ||= (value.hash * -1)
814+
@hash || @hash = (value.hash * -1)
813815
end
814816

815817
##
816818
# Returns object representation of this URI, broken into components
817819
#
818820
# @return [Hash{Symbol => String}]
819821
def object
820-
@object ||= parse(@value)
822+
@object || @object = parse(@value)
821823
end
822824
alias_method :to_h, :object
823825

0 commit comments

Comments
 (0)