Skip to content

Commit

Permalink
(NumberOfEntities) improve __add__ performance
Browse files Browse the repository at this point in the history
This does indeed not work child classes, but the __repr__ was also not working for child classes. And no currently there are no child classes, so performance is more important. See ros2#1223

Signed-off-by: Matthijs van der Burgh <[email protected]>
  • Loading branch information
MatthijsBurgh committed May 17, 2024
1 parent 7ccbf53 commit 6964ab4
Showing 1 changed file with 6 additions and 4 deletions.
10 changes: 6 additions & 4 deletions rclpy/rclpy/waitable.py
Original file line number Diff line number Diff line change
Expand Up @@ -36,10 +36,12 @@ def __init__(

def __add__(self, other):
result = self.__class__()
for attr in result.__slots__:
left = getattr(self, attr)
right = getattr(other, attr)
setattr(result, attr, left + right)
result.num_subscriptions = self.num_subscriptions + other.num_subscriptions
result.num_guard_conditions = self.num_guard_conditions + other.num_guard_conditions
result.num_timers = self.num_timers + other.num_timers
result.num_clients = self.num_clients + other.num_clients
result.num_services = self.num_services + other.num_services
result.num_events = self.num_events + other.num_events
return result

def __iadd__(self, other):
Expand Down

0 comments on commit 6964ab4

Please sign in to comment.