From 27216892547bb073777056379d549a6dc42872cb Mon Sep 17 00:00:00 2001 From: Rapptz Date: Mon, 24 Sep 2018 23:22:49 -0400 Subject: Optimise tight loops in DiscordGateway.received_message * type(x) is y is faster than isinstance(x, y) * Re-arrange if-statements for common statements * Drop handler getattr for most events that don't use it --- discord/client.py | 13 +++++-------- 1 file changed, 5 insertions(+), 8 deletions(-) (limited to 'discord/client.py') diff --git a/discord/client.py b/discord/client.py index 31b2a5a1..23907574 100644 --- a/discord/client.py +++ b/discord/client.py @@ -125,7 +125,11 @@ class Client: proxy_auth = options.pop('proxy_auth', None) self.http = HTTPClient(connector, proxy=proxy, proxy_auth=proxy_auth, loop=self.loop) - self._connection = ConnectionState(dispatch=self.dispatch, chunker=self._chunker, + self._handlers = { + 'ready': self._handle_ready + } + + self._connection = ConnectionState(dispatch=self.dispatch, chunker=self._chunker, handlers=self._handlers, syncer=self._syncer, http=self.http, loop=self.loop, **options) self._connection.shard_count = self.shard_count @@ -261,13 +265,6 @@ class Client: for idx in reversed(removed): del listeners[idx] - try: - actual_handler = getattr(self, handler) - except AttributeError: - pass - else: - actual_handler(*args, **kwargs) - try: coro = getattr(self, method) except AttributeError: -- cgit v1.2.3