Merge pull request #3815 from blongden/cmdset_merge_improvements

Improve performance on larger cmdsets
This commit is contained in:
Griatch 2025-10-22 13:33:52 +02:00 committed by GitHub
commit e9a69ee3df
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
2 changed files with 3 additions and 3 deletions

View File

@ -32,7 +32,6 @@ from collections import defaultdict
from copy import copy
from itertools import chain
from traceback import format_exc
from weakref import WeakValueDictionary
from django.conf import settings
from django.utils.translation import gettext as _
@ -49,7 +48,7 @@ _IN_GAME_ERRORS = settings.IN_GAME_ERRORS
__all__ = ("cmdhandler", "InterruptCommand")
_GA = object.__getattribute__
_CMDSET_MERGE_CACHE = WeakValueDictionary()
_CMDSET_MERGE_CACHE = {}
# tracks recursive calls by each caller
# to avoid infinite loops (commands calling themselves)

View File

@ -248,7 +248,8 @@ class CmdSet(object, metaclass=_CmdSetMeta):
if cmdset_a.duplicates and cmdset_a.priority == cmdset_b.priority:
cmdset_c.commands.extend(cmdset_b.commands)
else:
cmdset_c.commands.extend([cmd for cmd in cmdset_b if cmd not in cmdset_a])
existing_commands = set(cmdset_a.commands)
cmdset_c.commands.extend([cmd for cmd in cmdset_b if cmd not in existing_commands])
return cmdset_c
def _intersect(self, cmdset_a, cmdset_b):