Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

chore: avoid re-resolving a query in dynamic port bindings if the current selection matches #446

Open
wants to merge 1 commit into
base: transition-to-runkit
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
16 changes: 16 additions & 0 deletions lib/syskit/dynamic_port_binding.rb
Original file line number Diff line number Diff line change
Expand Up @@ -99,6 +99,10 @@ def attach_to_task(task)
# the port was updated, and false otherwise. The tuple's second element
# is the new resolved port which may be nil if no ports can be found
def update
if @resolved_port && @port_resolver&.current_selection_valid?(@resolved_port)
return false, @resolved_port
end

port = @port_resolver&.update
return false, @resolved_port if @resolved_port == port

Expand Down Expand Up @@ -294,6 +298,10 @@ def initialize(plan, matcher)
@last_provider_task = nil
end

def current_selection_valid?(port)
@matcher === port
end

def update
port = @matcher.each_in_plan(@plan).first
port&.to_actual_port
Expand All @@ -319,6 +327,10 @@ def initialize(port)
@port = port
end

def current_selection_valid?(port)
kapeps marked this conversation as resolved.
Show resolved Hide resolved
!!port.component.plan
end

def update
@port if @port.component.plan
end
Expand All @@ -337,6 +349,10 @@ def initialize(port)
@port = port
end

def current_selection_valid?(port)
!!port.component.to_task.plan
end

def update
@port if @port.component.to_task.plan
end
Expand Down
6 changes: 3 additions & 3 deletions lib/syskit/queries/port_matcher.rb
Original file line number Diff line number Diff line change
Expand Up @@ -57,9 +57,9 @@ def with_type(type)
def ===(port)
return unless port.kind_of?(Port)

(@name_filter === object.name) &&
(!@type_filter || @type_filter == object.type) &&
(@component_matcher === object.component)
(@name_filter === port.name) &&
(!@type_filter || @type_filter == port.type) &&
(@component_matcher === port.component)
end

def each_in_plan(plan, &block)
Expand Down
7 changes: 7 additions & 0 deletions test/queries/test_port_matcher.rb
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,13 @@ module Queries
PortMatcher.new(@task_m).with_name("out_d")
end

it "can find ports with ===" do
plan.add(task = @task_m.new)
matcher = PortMatcher.new(@task_m).with_name("out_d")
assert matcher === task.out_d_port
refute matcher === task.out_f_port
end

it "optionally allows to filter with a name pattern" do
plan.add(task = @task_m.new)
assert_matcher_finds [task.out_d_port, task.out_f_port],
Expand Down