Skip to content

Commit da94dfe

Browse files
committed
Merge pull request #529 from thedarkone/mri-map-backend-iteration-fixes
Conc::Map - MRI backend fixes
2 parents 8b12b1e + fec11e7 commit da94dfe

File tree

4 files changed

+19
-9
lines changed

4 files changed

+19
-9
lines changed

lib/concurrent/collection/map/non_concurrent_map_backend.rb

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -76,10 +76,6 @@ def key?(key)
7676
@backend.key?(key)
7777
end
7878

79-
def value?(value)
80-
@backend.value?(value)
81-
end
82-
8379
def delete(key)
8480
@backend.delete(key)
8581
end

lib/concurrent/collection/map/synchronized_map_backend.rb

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -53,10 +53,6 @@ def key?(key)
5353
synchronize { super }
5454
end
5555

56-
def value?(value)
57-
synchronize { super }
58-
end
59-
6056
def delete(key)
6157
synchronize { super }
6258
end

lib/concurrent/map.rb

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -149,7 +149,7 @@ def value?(value)
149149
return true if value.equal?(v)
150150
end
151151
false
152-
end unless method_defined?(:value?)
152+
end
153153

154154
def keys
155155
arr = []
@@ -202,6 +202,15 @@ def marshal_load(hash)
202202

203203
undef :freeze
204204

205+
# @!visibility private
206+
DEFAULT_OBJ_ID_STR_WIDTH = (2**50).class == Fixnum ? 14 : 7 # we want to look "native", 7 for 32-bit, 14 for 64-bit
207+
# override default #inspect() method: firstly, we don't want to be spilling our guts (i-vars), secondly, MRI backend's
208+
# #inspect() call on its @backend i-var will bump @backend's iter level while possibly yielding GVL
209+
def inspect
210+
id_str = (object_id << 1).to_s(16).rjust(DEFAULT_OBJ_ID_STR_WIDTH, '0')
211+
"#<#{self.class.name}:0x#{id_str} entries=#{size} default_proc=#{@default_proc.inspect}>"
212+
end
213+
205214
private
206215
def raise_fetch_no_key
207216
raise KeyError, 'key not found'

spec/concurrent/map_spec.rb

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -826,6 +826,15 @@ def key # assert_collision_resistance expects to be able to call .key to get the
826826
expect { Marshal.dump(Concurrent::Map.new {}) }.to raise_error(TypeError)
827827
end
828828

829+
it '#inspect' do
830+
regexp = /\A#<Concurrent::Map:0x[0-9a-f]+ entries=[0-9]+ default_proc=.*>\Z/i
831+
expect(Concurrent::Map.new.inspect).to match(regexp)
832+
expect((Concurrent::Map.new {}).inspect).to match(regexp)
833+
map = Concurrent::Map.new
834+
map[:foo] = :bar
835+
expect(map.inspect).to match(regexp)
836+
end
837+
829838
private
830839

831840
def with_or_without_default_proc(&block)

0 commit comments

Comments
 (0)