File tree Expand file tree Collapse file tree 1 file changed +12
-6
lines changed Expand file tree Collapse file tree 1 file changed +12
-6
lines changed Original file line number Diff line number Diff line change @@ -13,11 +13,17 @@ module JSONAPI
1313 # rid = ResourceIdentity.new(PostResource, 12)
1414 #
1515 class ResourceIdentity
16- attr_reader :resource_klass , :id
17-
16+ # Store the identity parts as an array to avoid allocating a new array for the hash method to work on
1817 def initialize ( resource_klass , id )
19- @resource_klass = resource_klass
20- @id = id
18+ @identity_parts = [ resource_klass , id ]
19+ end
20+
21+ def resource_klass
22+ @identity_parts [ 0 ]
23+ end
24+
25+ def id
26+ @identity_parts [ 1 ]
2127 end
2228
2329 def ==( other )
@@ -27,11 +33,11 @@ def ==(other)
2733 end
2834
2935 def eql? ( other )
30- other . is_a? ( ResourceIdentity ) && other . resource_klass == @resource_klass && other . id == @id
36+ hash == other . hash
3137 end
3238
3339 def hash
34- [ @resource_klass , @id ] . hash
40+ @identity_parts . hash
3541 end
3642
3743 def <=>( other_identity )
You can’t perform that action at this time.
0 commit comments