diff options
| author | Rapptz <[email protected]> | 2019-05-29 01:22:36 -0400 |
|---|---|---|
| committer | Rapptz <[email protected]> | 2019-05-29 01:22:53 -0400 |
| commit | 00a0856cc44549a29d5123b997db3a5e593f0896 (patch) | |
| tree | 48071f9464b906b2a39470e31a5013791f8c4da9 /discord/state.py | |
| parent | Speed-up utils.get for the common cases (diff) | |
| download | discord.py-00a0856cc44549a29d5123b997db3a5e593f0896.tar.xz discord.py-00a0856cc44549a29d5123b997db3a5e593f0896.zip | |
Use a dict instead of getattr for parsing events.
Probably not a significant difference but might as well use it here.
The basic idea is to cache the getattr calls instead of repeatedly
doing it (since they're around 105ns on my machine). The dictionary
lookup is about 41ns on my machine.
The next step in speeding up library code some more should be in
the parser bodies themselves but that's a problem to tackle another
day.
Diffstat (limited to 'discord/state.py')
| -rw-r--r-- | discord/state.py | 6 |
1 files changed, 6 insertions, 0 deletions
diff --git a/discord/state.py b/discord/state.py index f04d6ee7..d56b9e75 100644 --- a/discord/state.py +++ b/discord/state.py @@ -33,6 +33,7 @@ import itertools import logging import math import weakref +import inspect from .guild import Guild from .activity import _ActivityTag @@ -88,6 +89,11 @@ class ConnectionState: self._activity = activity self._status = status + self.parsers = parsers = {} + for attr, func in inspect.getmembers(self): + if attr.startswith('parse_'): + parsers[attr[6:].upper()] = func + self.clear() def clear(self): |