mirror of
https://github.com/wesnoth/wesnoth
synced 2025-05-15 09:02:30 +00:00
Made wmlunits 250% faster.
This commit is contained in:
parent
5f706a980b
commit
91c44fee30
@ -64,6 +64,9 @@ class Parser:
|
||||
|
||||
self.textdomain = ""
|
||||
|
||||
# Callback which is called for each macro. If it returns False, the
|
||||
# macro is ignored.
|
||||
self.macro_callback = None
|
||||
self.macro_not_found_callback = None
|
||||
self.no_macros = False
|
||||
|
||||
@ -290,6 +293,10 @@ class Parser:
|
||||
|
||||
preserve = macro
|
||||
macro = macro[:-1] # Get rid of final }
|
||||
|
||||
if self.macro_callback:
|
||||
if not self.macro_callback(macro): return None
|
||||
|
||||
# If the macro starts with ~, assume a file in userdata.
|
||||
if macro[0] == "~":
|
||||
if self.user_dir:
|
||||
|
@ -33,7 +33,7 @@ class ParserWithCoreMacros:
|
||||
parser.parse_top(None)
|
||||
self.core_macros = parser.macros
|
||||
|
||||
def parse(self, text_to_parse):
|
||||
def parse(self, text_to_parse, ignore_macros = None):
|
||||
# Create the real parser.
|
||||
parser = wmlparser.Parser(datadir)
|
||||
parser.do_preprocessor_logic = True
|
||||
@ -43,6 +43,9 @@ class ParserWithCoreMacros:
|
||||
# Suppress complaints about undefined terrain macros
|
||||
parser.set_macro_not_found_callback(lambda wmlparser, name, params:
|
||||
name.startswith("TERRAIN") or name == "DISABLE_TRANSITIONS")
|
||||
|
||||
if ignore_macros:
|
||||
parser.macro_callback = ignore_macros
|
||||
|
||||
# Create a WML root element and parse the given text into it.
|
||||
WML = wmldata.DataSub("WML")
|
||||
@ -116,7 +119,8 @@ class UnitList:
|
||||
|
||||
# Re-parse, this time with the define defined.
|
||||
WML = self.parser.parse(
|
||||
"#define %s\n#enddef\n%s" % (define, text_to_parse))
|
||||
"#define %s\n#enddef\n%s" % (define, text_to_parse),
|
||||
ignore_macros = lambda x: x.find("%s/scenarios" % campaign) == -1)
|
||||
# This time, it oughta work.
|
||||
units = WML.get_first("+units")
|
||||
if not units:
|
||||
|
Loading…
x
Reference in New Issue
Block a user