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

Unified Diff: lib/dom.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
« no previous file with comments | « no previous file | lib/parser.dart » ('j') | lib/src/tokenizer.dart » ('J')
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: lib/dom.dart
diff --git a/lib/dom.dart b/lib/dom.dart
index 6201f69dbf9ccd9ea93d927b2c6b2545db79878d..76eb85fdd1b9a49d830cbcb15bb209b1c055965a 100644
--- a/lib/dom.dart
+++ b/lib/dom.dart
@@ -402,18 +402,32 @@ class DocumentType extends Node {
}
class Text extends Node {
- String data;
+ /// The text node's data, stored as either a String or StringBuffer.
+ /// We support storing a StringBuffer here to support fast [appendData].
+ /// It will flatten back to a String on read.
+ var _data;
- Text(this.data) : super._();
+ Text(String data) : _data = data != null ? data : '', super._();
int get nodeType => Node.TEXT_NODE;
+ String get data => _data = _data.toString();
+ set data(String value) {
+ _data = value != null ? value : '';
+ }
+
String toString() => '"$data"';
void _addOuterHtml(StringBuffer str) => writeTextNodeAsHtml(str, this);
Text clone(bool deep) => new Text(data);
+ void appendData(String data) {
+ if (_data is! StringBuffer) _data = new StringBuffer(_data);
+ StringBuffer sb = _data;
+ sb.write(data);
+ }
+
String get text => data;
set text(String value) {
data = value;
@@ -539,13 +553,19 @@ class Element extends Node with _ParentNode, _ElementAndDocument {
void _addOuterHtml(StringBuffer str) {
// http://www.whatwg.org/specs/web-apps/current-work/multipage/the-end.html#serializing-html-fragments
// Element is the most complicated one.
- str.write('<${_getSerializationPrefix(namespaceUri)}$localName');
+ str.write('<');
+ str.write(_getSerializationPrefix(namespaceUri));
+ str.write(localName);
if (attributes.length > 0) {
attributes.forEach((key, v) {
// Note: AttributeName.toString handles serialization of attribute
// namespace, if needed.
- str.write(' $key="${htmlSerializeEscape(v, attributeMode: true)}"');
+ str.write(' ');
+ str.write(key);
+ str.write('="');
+ str.write(htmlSerializeEscape(v, attributeMode: true));
+ str.write('"');
});
}
« no previous file with comments | « no previous file | lib/parser.dart » ('j') | lib/src/tokenizer.dart » ('J')

Powered by Google App Engine
This is Rietveld 408576698