Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(1212)

Unified Diff: lib/src/token.dart

Issue 987433005: remove most string concat, fixes #7 (Closed) Base URL: git@github.com:dart-lang/html.git@master
Patch Set: Created 5 years, 10 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
Index: lib/src/token.dart
diff --git a/lib/src/token.dart b/lib/src/token.dart
index e4f25e5db98f7c3d647c55dfabcf8815f8288afa..9a2843c5f8cee0fb00371b1a15796c61f96cbc99 100644
--- a/lib/src/token.dart
+++ b/lib/src/token.dart
@@ -47,8 +47,25 @@ class EndTagToken extends TagToken {
}
abstract class StringToken extends Token {
- String data;
- StringToken(this.data);
+ StringBuffer _buffer;
+
+ String _string;
+ String get data {
+ if (_string == null) {
+ _string = _buffer.toString();
+ _buffer = null;
+ }
+ return _string;
+ }
+
+ StringToken(string)
+ : _string = string,
+ _buffer = string == null ? new StringBuffer() : null;
+
+ StringToken add(String data) {
+ _buffer.write(data);
+ return this;
+ }
}
class ParseErrorToken extends StringToken {
@@ -64,6 +81,13 @@ class CharactersToken extends StringToken {
CharactersToken([String data]) : super(data);
int get kind => TokenKind.characters;
+
+ /// Replaces the token's [data]. This should only be used to wholly replace
+ /// data, not to append data.
+ void replaceData(String newData) {
+ _string = newData;
+ _buffer = null;
+ }
}
class SpaceCharactersToken extends StringToken {
@@ -103,7 +127,7 @@ class TagAttribute {
int startValue;
int endValue;
- TagAttribute(this.name, [this.value = '']);
+ TagAttribute();
}
class TokenKind {
« no previous file with comments | « lib/parser.dart ('k') | lib/src/tokenizer.dart » ('j') | lib/src/tokenizer.dart » ('J')

Powered by Google App Engine
This is Rietveld 408576698