Skip to content

Commit da6a4f0

Browse files
committed
Do not leak internal class
1 parent 31cdd3c commit da6a4f0

File tree

1 file changed

+15
-16
lines changed

1 file changed

+15
-16
lines changed

lib/concurrent/atomic/atomic_markable_reference.rb

Lines changed: 15 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@ class AtomicMarkableReference < ::Concurrent::Synchronization::Object
1414
# @!macro [attach] atomic_markable_reference_method_initialize
1515
def initialize(value = nil, mark = false)
1616
super()
17-
self.reference = ImmutableArray[value, mark]
17+
self.reference = immutable_array(value, mark)
1818
end
1919

2020
# @!macro [attach] atomic_markable_reference_method_compare_and_set
@@ -53,7 +53,7 @@ def compare_and_set(expected_val, new_val, expected_mark, new_mark)
5353
return false unless expected_val.equal? curr_val
5454
end
5555

56-
prospect = ImmutableArray[new_val, new_mark]
56+
prospect = immutable_array(new_val, new_mark)
5757

5858
compare_and_set_reference current, prospect
5959
end
@@ -63,7 +63,7 @@ def compare_and_set(expected_val, new_val, expected_mark, new_mark)
6363
#
6464
# Gets the current reference and marked values.
6565
#
66-
# @return [ImmutableArray] the current reference and marked values
66+
# @return [Array] the current reference and marked values
6767
def get
6868
reference
6969
end
@@ -95,9 +95,9 @@ def mark
9595
# @param [Object] new_val the new value
9696
# @param [Boolean] new_mark the new mark
9797
#
98-
# @return [ImmutableArray] both the new value and the new mark
98+
# @return [Array] both the new value and the new mark
9999
def set(new_val, new_mark)
100-
self.reference = ImmutableArray[new_val, new_mark]
100+
self.reference = immutable_array(new_val, new_mark)
101101
end
102102

103103
# @!macro [attach] atomic_markable_reference_method_update
@@ -111,14 +111,14 @@ def set(new_val, new_mark)
111111
# @yieldparam [Object] old_val the starting value of the atomic reference
112112
# @yieldparam [Boolean] old_mark the starting state of marked
113113
#
114-
# @return [ImmutableArray] the new value and new mark
114+
# @return [Array] the new value and new mark
115115
def update
116116
loop do
117117
old_val, old_mark = reference
118118
new_val, new_mark = yield old_val, old_mark
119119

120120
if compare_and_set old_val, new_val, old_mark, new_mark
121-
return ImmutableArray[new_val, new_mark]
121+
return immutable_array(new_val, new_mark)
122122
end
123123
end
124124
end
@@ -134,7 +134,7 @@ def update
134134
# @yieldparam [Object] old_val the starting value of the atomic reference
135135
# @yieldparam [Boolean] old_mark the starting state of marked
136136
#
137-
# @return [ImmutableArray] the new value and marked state
137+
# @return [Array] the new value and marked state
138138
#
139139
# @raise [Concurrent::ConcurrentUpdateError] if the update fails
140140
def try_update!
@@ -148,7 +148,7 @@ def try_update!
148148
'the `AtomicMarkableReference#update` method.'
149149
end
150150

151-
ImmutableArray[new_val, new_mark]
151+
immutable_array(new_val, new_mark)
152152
end
153153

154154
# @!macro [attach] atomic_markable_reference_method_try_update
@@ -161,22 +161,21 @@ def try_update!
161161
# @yieldparam [Object] old_val the starting value of the atomic reference
162162
# @yieldparam [Boolean] old_mark the starting state of marked
163163
#
164-
# @return [ImmutableArray] the new value and marked state, or nil if
164+
# @return [Array] the new value and marked state, or nil if
165165
# the update failed
166166
def try_update
167167
old_val, old_mark = reference
168168
new_val, new_mark = yield old_val, old_mark
169169

170170
return unless compare_and_set old_val, new_val, old_mark, new_mark
171171

172-
ImmutableArray[new_val, new_mark]
172+
immutable_array(new_val, new_mark)
173173
end
174174

175-
# Internal/private ImmutableArray for representing pairs
176-
class ImmutableArray < ::Array
177-
def self.new(*args)
178-
super(*args).freeze
179-
end
175+
private
176+
177+
def immutable_array(*args)
178+
args.freeze
180179
end
181180
end
182181
end

0 commit comments

Comments
 (0)