Optimize var.get_role

It will now return as soon as it finds the role for the player,
instead of calling var.list_players_and_roles every single time.
I haven't tested in a real-world scenario, but in a test game
with 10000 players (don't ask), the speed improvement is very clear
(~1-2s per player when sending out nighttime PMs instead of ~10s).
This commit is contained in:
nyuszika7h 2015-06-30 20:35:39 +02:00
parent ad26f0b693
commit b968f83e8b

View File

@ -345,7 +345,12 @@ def list_players_and_roles():
plr[p] = x
return plr
get_role = lambda plyr: list_players_and_roles()[plyr]
def get_role(p):
for role, pl in ROLES.items():
if role in TEMPLATE_RESTRICTIONS.keys():
continue # only get actual roles
if p in pl:
return role
def get_reveal_role(nick):
if HIDDEN_TRAITOR and get_role(nick) == "traitor":