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.
This commit is contained in:
Thomas Goyne 2014-07-13 20:54:16 -07:00
parent 706a72d5c1
commit 92b8b2851b
1 changed files with 5 additions and 3 deletions

View File

@ -206,10 +206,12 @@ namespace parser {
namespace ass {
std::vector<DialogueToken> TokenizeDialogueBody(std::string const& str, bool karaoke_templater) {
dialogue_tokens<lex::lexertl::actor_lexer<>> tokenizer(karaoke_templater);
static const dialogue_tokens<lex::lexertl::actor_lexer<>> kt(true);
static const dialogue_tokens<lex::lexertl::actor_lexer<>> 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<DialogueToken> data;
auto it = tokenizer.begin(first, last), end = tokenizer.end();