[vala] parser: Cache current token if possible
- From: Rico Tzschichholz <ricotz src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [vala] parser: Cache current token if possible
- Date: Tue, 1 Nov 2016 21:21:59 +0000 (UTC)
commit 9b8d8acf2745835616d23fee2afe4505aef147b1
Author: Rico Tzschichholz <ricotz ubuntu com>
Date: Tue Nov 1 17:48:55 2016 +0100
parser: Cache current token if possible
vala/valagenieparser.vala | 13 +++++++------
vala/valaparser.vala | 17 +++++++++--------
2 files changed, 16 insertions(+), 14 deletions(-)
---
diff --git a/vala/valagenieparser.vala b/vala/valagenieparser.vala
index 46c6000..b1a1693 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) {
diff --git a/vala/valaparser.vala b/vala/valaparser.vala
index fc0abd1..48127eb 100644
--- a/vala/valaparser.vala
+++ b/vala/valaparser.vala
@@ -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) {
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]