Use attrgetter to speed up Member attribute access by 2x.
This commit is contained in:
parent
d96b8a0b80
commit
3c387e9031
@ -25,6 +25,7 @@ DEALINGS IN THE SOFTWARE.
|
|||||||
"""
|
"""
|
||||||
|
|
||||||
import itertools
|
import itertools
|
||||||
|
from operator import attrgetter
|
||||||
|
|
||||||
import discord.abc
|
import discord.abc
|
||||||
|
|
||||||
@ -90,10 +91,12 @@ def flatten_user(cls):
|
|||||||
# if it's a slotted attribute or a property, redirect it
|
# if it's a slotted attribute or a property, redirect it
|
||||||
# slotted members are implemented as member_descriptors in Type.__dict__
|
# slotted members are implemented as member_descriptors in Type.__dict__
|
||||||
if not hasattr(value, '__annotations__'):
|
if not hasattr(value, '__annotations__'):
|
||||||
def getter(self, x=attr):
|
getter = attrgetter('_user.' + attr)
|
||||||
return getattr(self._user, x)
|
|
||||||
setattr(cls, attr, property(getter, doc='Equivalent to :attr:`User.%s`' % attr))
|
setattr(cls, attr, property(getter, doc='Equivalent to :attr:`User.%s`' % attr))
|
||||||
else:
|
else:
|
||||||
|
# Technically, this can also use attrgetter
|
||||||
|
# However I'm not sure how I feel about "functions" returning properties
|
||||||
|
# It probably breaks something in Sphinx.
|
||||||
# probably a member function by now
|
# probably a member function by now
|
||||||
def generate_function(x):
|
def generate_function(x):
|
||||||
def general(self, *args, **kwargs):
|
def general(self, *args, **kwargs):
|
||||||
|
Loading…
x
Reference in New Issue
Block a user