]> git.ipfire.org Git - thirdparty/vala.git/commitdiff
parser: Cache current token if possible
authorRico Tzschichholz <ricotz@ubuntu.com>
Tue, 1 Nov 2016 16:48:55 +0000 (17:48 +0100)
committerRico Tzschichholz <ricotz@ubuntu.com>
Tue, 1 Nov 2016 21:21:15 +0000 (22:21 +0100)
vala/valagenieparser.vala
vala/valaparser.vala

index 46c600016be6b5dc427e55b4fdbe15ed541d092a..b1a1693915456397f09f765120acb0eb93861f6c 100644 (file)
@@ -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) {
index fc0abd142a3364b30a1e35a88545018d2a6d4bc6..48127eba0b73bc5985844e97accfcb96dc26c2f7 100644 (file)
@@ -90,9 +90,7 @@ public class Vala.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);
@@ -136,12 +134,14 @@ public class Vala.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) {
@@ -151,13 +151,14 @@ public class Vala.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);
        }
 
        SourceReference get_last_src () {
                int last_index = (index + BUFFER_SIZE - 1) % BUFFER_SIZE;
-
-               return new SourceReference (scanner.source_file, tokens[last_index].begin, tokens[last_index].end);
+               var token = tokens[last_index];
+               return new SourceReference (scanner.source_file, token.begin, token.end);
        }
 
        void rollback (SourceLocation location) {