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

Unified Diff: lib/html/src/shared_FactoryProviders.dart

Issue 9732019: dart:html perf optimization based on runing Dromaeo benchmarks (Closed) Base URL: https://dart.googlecode.com/svn/branches/bleeding_edge/dart
Patch Set: Fixes Created 8 years, 9 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/html/src/shared_FactoryProviders.dart
diff --git a/lib/html/src/shared_FactoryProviders.dart b/lib/html/src/shared_FactoryProviders.dart
index 99c90a25eef827ab961618f60f2d4ccd012267b4..e9ea9238de2f682b10f3e8331f4ff1b90c25dbed 100644
--- a/lib/html/src/shared_FactoryProviders.dart
+++ b/lib/html/src/shared_FactoryProviders.dart
@@ -2,16 +2,11 @@
// for details. All rights reserved. Use of this source code is governed by a
// BSD-style license that can be found in the LICENSE file.
-class _TextFactoryProvider {
-
- factory Text(String data) => _document._createTextNode(data);
-}
-
class _EventFactoryProvider {
factory Event(String type, [bool canBubble = true,
bool cancelable = true]) {
- final _EventImpl e = _document._createEvent("Event");
- e._initEvent(type, canBubble, cancelable);
+ final _EventImpl e = _document.$dom_createEvent("Event");
+ e.$dom_initEvent(type, canBubble, cancelable);
return e;
}
}
@@ -22,8 +17,8 @@ class _MouseEventFactoryProvider {
[bool canBubble = true, bool cancelable = true, bool ctrlKey = false,
bool altKey = false, bool shiftKey = false, bool metaKey = false,
EventTarget relatedTarget = null]) {
- final e = _document._createEvent("MouseEvent");
- e._initMouseEvent(type, canBubble, cancelable, view, detail,
+ final e = _document.$dom_createEvent("MouseEvent");
+ e.$dom_initMouseEvent(type, canBubble, cancelable, view, detail,
screenX, screenY, clientX, clientY, ctrlKey, altKey, shiftKey, metaKey,
button, relatedTarget);
return e;
@@ -42,62 +37,6 @@ class _CSSStyleDeclarationFactoryProvider {
}
}
-final _START_TAG_REGEXP = const RegExp('<(\\w+)');
-class _ElementFactoryProvider {
- static final _CUSTOM_PARENT_TAG_MAP = const {
- 'body' : 'html',
- 'head' : 'html',
- 'caption' : 'table',
- 'td': 'tr',
- 'colgroup': 'table',
- 'col' : 'colgroup',
- 'tr' : 'tbody',
- 'tbody' : 'table',
- 'tfoot' : 'table',
- 'thead' : 'table',
- 'track' : 'audio',
- };
-
- /** @domName Document.createElement */
- factory Element.html(String html) {
- // TODO(jacobr): this method can be made more robust and performant.
- // 1) Cache the dummy parent elements required to use innerHTML rather than
- // creating them every call.
- // 2) Verify that the html does not contain leading or trailing text nodes.
- // 3) Verify that the html does not contain both <head> and <body> tags.
- // 4) Detatch the created element from its dummy parent.
- String parentTag = 'div';
- String tag;
- final match = _START_TAG_REGEXP.firstMatch(html);
- if (match !== null) {
- tag = match.group(1).toLowerCase();
- if (_CUSTOM_PARENT_TAG_MAP.containsKey(tag)) {
- parentTag = _CUSTOM_PARENT_TAG_MAP[tag];
- }
- }
- final _ElementImpl temp = new Element.tag(parentTag);
- temp.innerHTML = html;
-
- Element element;
- if (temp.elements.length == 1) {
- element = temp.elements.first;
- } else if (parentTag == 'html' && temp.elements.length == 2) {
- // Work around for edge case in WebKit and possibly other browsers where
- // both body and head elements are created even though the inner html
- // only contains a head or body element.
- element = temp.elements[tag == 'head' ? 0 : 1];
- } else {
- throw new IllegalArgumentException('HTML had ${temp.elements.length} ' +
- 'top level elements but 1 expected');
- }
- element.remove();
- return element;
- }
-
- /** @domName Document.createElement */
- factory Element.tag(String tag) => _document._createElement(tag);
-}
-
class _DocumentFragmentFactoryProvider {
/** @domName Document.createDocumentFragment */
factory DocumentFragment() => document.createDocumentFragment();
@@ -135,7 +74,7 @@ class _DocumentFragmentFactoryProvider {
class _SVGElementFactoryProvider {
factory SVGElement.tag(String tag) {
final Element temp =
- _document._createElementNS("http://www.w3.org/2000/svg", tag);
+ _document.$dom_createElementNS("http://www.w3.org/2000/svg", tag);
return temp;
}

Powered by Google App Engine
This is Rietveld 408576698