From 92b8b2851b0e12c82269d59e1bfee1beaaddca54 Mon Sep 17 00:00:00 2001 From: Thomas Goyne Date: Sun, 13 Jul 2014 20:54:16 -0700 Subject: [PATCH] Don't build the dialogue lexer on every use Building the lexer takes much longer than actually lexing, and since the lexer is stateless there's no reason not to just make it static. --- libaegisub/common/parser.cpp | 8 +++++--- 1 file changed, 5 insertions(+), 3 deletions(-) diff --git a/libaegisub/common/parser.cpp b/libaegisub/common/parser.cpp index c855c7e20..ef53ed0d2 100644 --- a/libaegisub/common/parser.cpp +++ b/libaegisub/common/parser.cpp @@ -206,10 +206,12 @@ namespace parser { namespace ass { std::vector TokenizeDialogueBody(std::string const& str, bool karaoke_templater) { - dialogue_tokens> tokenizer(karaoke_templater); + static const dialogue_tokens> kt(true); + static const dialogue_tokens> not_kt(false); + auto const& tokenizer = karaoke_templater ? kt : not_kt; - char const* first = str.c_str(); - char const* last = first + str.size(); + char const *first = str.c_str(); + char const *last = first + str.size(); std::vector data; auto it = tokenizer.begin(first, last), end = tokenizer.end();