diff options
author | Rico Tzschichholz <ricotz@ubuntu.com> | 2016-11-01 17:48:55 +0100 |
---|---|---|
committer | Rico Tzschichholz <ricotz@ubuntu.com> | 2016-11-01 22:21:15 +0100 |
commit | 9b8d8acf2745835616d23fee2afe4505aef147b1 (patch) | |
tree | e1be5c58b3bd4b7ce25e76c85c54c401975fbb80 /vala/valagenieparser.vala | |
parent | e6f8e4ceec38e9b1878fa4074c7db3751d7a38b1 (diff) | |
download | vala-9b8d8acf2745835616d23fee2afe4505aef147b1.tar.gz |
parser: Cache current token if possible
Diffstat (limited to 'vala/valagenieparser.vala')
-rw-r--r-- | vala/valagenieparser.vala | 13 |
1 files changed, 7 insertions, 6 deletions
diff --git a/vala/valagenieparser.vala b/vala/valagenieparser.vala index 46c600016..b1a169391 100644 --- a/vala/valagenieparser.vala +++ b/vala/valagenieparser.vala @@ -100,9 +100,7 @@ public class Vala.Genie.Parser : CodeVisitor { if (size <= 0) { SourceLocation begin, end; TokenType type = scanner.read_token (out begin, out end); - tokens[index].type = type; - tokens[index].begin = begin; - tokens[index].end = end; + tokens[index] = { type, begin, end }; size = 1; } return (tokens[index].type != TokenType.EOF); @@ -183,12 +181,14 @@ public class Vala.Genie.Parser : CodeVisitor { } string get_current_string () { - return ((string) tokens[index].begin.pos).substring (0, (int) (tokens[index].end.pos - tokens[index].begin.pos)); + var token = tokens[index]; + return ((string) token.begin.pos).substring (0, (int) (token.end.pos - token.begin.pos)); } string get_last_string () { int last_index = (index + BUFFER_SIZE - 1) % BUFFER_SIZE; - return ((string) tokens[last_index].begin.pos).substring (0, (int) (tokens[last_index].end.pos - tokens[last_index].begin.pos)); + var token = tokens[last_index]; + return ((string) token.begin.pos).substring (0, (int) (token.end.pos - token.begin.pos)); } SourceReference get_src (SourceLocation begin) { @@ -198,7 +198,8 @@ public class Vala.Genie.Parser : CodeVisitor { } SourceReference get_current_src () { - return new SourceReference (scanner.source_file, tokens[index].begin, tokens[index].end); + var token = tokens[index]; + return new SourceReference (scanner.source_file, token.begin, token.end); } void rollback (SourceLocation location) { |