diff options
Diffstat (limited to 'amqp/connection.py')
-rw-r--r-- | amqp/connection.py | 7 |
1 files changed, 5 insertions, 2 deletions
diff --git a/amqp/connection.py b/amqp/connection.py index 1dd52c1..24bfb66 100644 --- a/amqp/connection.py +++ b/amqp/connection.py @@ -482,8 +482,11 @@ class Connection(AbstractChannel): self._transport = self.connection = self.channels = None def _get_free_channel_id(self): - for channel_id in range(1, self.channel_max): - if channel_id not in self._used_channel_ids: + # Cast to a set for fast lookups, and keep stored as an array for lower memory usage. + used_channel_ids = set(self._used_channel_ids) + + for channel_id in range(1, self.channel_max + 1): + if channel_id not in used_channel_ids: self._used_channel_ids.append(channel_id) return channel_id |