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
13
13
# rid = ResourceIdentity.new(PostResource, 12)
14
14
#
15
15
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
18
17
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 ]
21
27
end
22
28
23
29
def ==( other )
@@ -27,11 +33,11 @@ def ==(other)
27
33
end
28
34
29
35
def eql? ( other )
30
- other . is_a? ( ResourceIdentity ) && other . resource_klass == @resource_klass && other . id == @id
36
+ hash == other . hash
31
37
end
32
38
33
39
def hash
34
- [ @resource_klass , @id ] . hash
40
+ @identity_parts . hash
35
41
end
36
42
37
43
def <=>( other_identity )
You can’t perform that action at this time.
0 commit comments