Skip to content

Commit

Permalink
Make type lookup faster.
Browse files Browse the repository at this point in the history
Use a map so we don't have to continually do a search in
the inner loop.

Signed-off-by: Chris Lalancette <[email protected]>
  • Loading branch information
clalancette committed Oct 29, 2020
1 parent c39ebce commit 174dd2f
Showing 1 changed file with 9 additions and 6 deletions.
15 changes: 9 additions & 6 deletions ros2param/ros2param/verb/list.py
Original file line number Diff line number Diff line change
Expand Up @@ -101,17 +101,20 @@ def main(self, *, args): # noqa: D102
if not args.node_name:
print(f'{node_name.full_name}:')
response = future.result()
sorted_names = sorted(response.result.names)
# get descriptors for the node if needs to print parameter type
name_to_type_map = {}
if args.param_type is True:
resp = call_describe_parameters(
node=node, node_name=node_name.full_name,
parameter_names=sorted(response.result.names))
for name in sorted(response.result.names):
parameter_names=sorted_names)
for descriptor in resp.descriptors:
name_to_type_map[descriptor.name] = get_parameter_type_string(
descriptor.type)

for name in sorted_names:
if args.param_type is True:
param_type_str = None
for descriptor in resp.descriptors:
if descriptor.name == name:
param_type_str = get_parameter_type_string(descriptor.type)
param_type_str = name_to_type_map[name]
print(f' {name} (type: {param_type_str})')
else:
print(f' {name}')
Expand Down

0 comments on commit 174dd2f

Please sign in to comment.