Skip to content

Commit

Permalink
Add comment detailing what many would find unreadbale
Browse files Browse the repository at this point in the history
  • Loading branch information
mikeshardmind committed Apr 18, 2023
1 parent ade4b3d commit d802dc3
Showing 1 changed file with 8 additions and 0 deletions.
8 changes: 8 additions & 0 deletions discord/flags.py
Original file line number Diff line number Diff line change
Expand Up @@ -1567,6 +1567,14 @@ class ArrayFlags(BaseFlags):
@classmethod
def _from_value(cls: Type[Self], value: List[int]) -> Self:
self = cls.__new__(cls)
# This is a micro-optimization given the frequency this object can be created.
# (1).__lshift__ is used in place of lambda x: 1 << x
# prebinding to a method of a constant rather than define a lambda.
# Pairing this with map, is essentially equivalent to (1 << x for x in value)
# reduction using operator.or_ instead of defining a lambda each call
# Discord sends these starting with a value of 1
# Rather than subtract 1 from each element prior to left shift,
# we shift right by 1 once at the end.
self.value = reduce(or_, map((1).__lshift__, value), 0) >> 1
return self

Expand Down

0 comments on commit d802dc3

Please sign in to comment.