Skip to content

Commit 67a0671

Browse files
committed
Replace Array of children with more effective Set
1 parent 1d20305 commit 67a0671

File tree

1 file changed

+6
-3
lines changed

1 file changed

+6
-3
lines changed

lib/concurrent/actress/core.rb

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,8 @@
11
module Concurrent
22
module Actress
33

4+
require 'set'
5+
46
# Core of the actor
57
# @api private
68
class Core
@@ -21,7 +23,7 @@ def initialize(opts = {}, &block)
2123
# noinspection RubyArgCount
2224
@terminated = Event.new
2325
@executor = Type! opts.fetch(:executor, Concurrent.configuration.global_task_pool), Executor
24-
@children = []
26+
@children = Set.new
2527
@reference = Reference.new self
2628
@name = (Type! opts.fetch(:name), String, Symbol).to_s
2729

@@ -61,13 +63,14 @@ def parent
6163
# @return [Array<Reference>] of children actors
6264
def children
6365
guard!
64-
@children.dup
66+
@children.to_a
6567
end
6668

6769
# @api private
6870
def add_child(child)
6971
guard!
70-
@children << (Type! child, Reference)
72+
Type! child, Reference
73+
@children.add child
7174
self
7275
end
7376

0 commit comments

Comments
 (0)