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

Unified Diff: lib/html/dartium/html_dartium.dart

Issue 10876084: Cache function proxies (Closed) Base URL: https://dart.googlecode.com/svn/branches/bleeding_edge/dart
Patch Set: Regen dart:html Created 8 years, 4 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:
Download patch
« no previous file with comments | « lib/html/dart2js/html_dart2js.dart ('k') | lib/html/src/Isolates.dart » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: lib/html/dartium/html_dartium.dart
diff --git a/lib/html/dartium/html_dartium.dart b/lib/html/dartium/html_dartium.dart
index 424f0d25c6c21899ce268b66c12fedd39c5cfe5b..6801b0c97f2b4f0c868a4abe16bb52b7e82dfc83 100644
--- a/lib/html/dartium/html_dartium.dart
+++ b/lib/html/dartium/html_dartium.dart
@@ -40842,6 +40842,11 @@ class _JsSerializer extends _Serializer {
}
visitFunction(Function func) {
+ // Look for a cached serialization first. The cached version
+ // should point to the original port.
+ var serialized = _deserializedFunctionTable.find(func);
+ if (serialized != null) return serialized;
+ // Create a new serialization forwarding to this port.
return [ 'funcref',
_functionRegistry._add(func),
visitSendPortSync(_functionRegistry._sendPort), null ];
@@ -40938,6 +40943,34 @@ _deserialize(var message) {
return new _JsDeserializer().deserialize(message);
}
+// TODO(vsm): Replace this with a hash map once functions are
+// hashable.
+class _DeserializedFunctionTable {
+ List data;
+ _DeserializedFunctionTable() {
+ data = [];
+ }
+
+ find(Function f) {
+ for (var item in data) {
+ if (f == item[0]) return item[1];
+ }
+ return null;
+ }
+
+ add(Function f, x) {
+ data.add([f, x]);
+ }
+}
+
+_DeserializedFunctionTable __deserializedFunctionTable = null;
+get _deserializedFunctionTable {
+ if (__deserializedFunctionTable == null) {
+ __deserializedFunctionTable = new _DeserializedFunctionTable();
+ }
+ return __deserializedFunctionTable;
+}
+
class _JsDeserializer extends _Deserializer {
static const _UNSPECIFIED = const Object();
@@ -40969,9 +41002,15 @@ class _JsDeserializer extends _Deserializer {
deserializeFunction(List x) {
var id = x[1];
+ // If the sendPort is local, just return the underlying function.
+ // Otherwise, create a new function that forwards to the remote
+ // port.
SendPortSync port = deserializeSendPort(x[2]);
+ if (port is _LocalSendPortSync) {
+ return _functionRegistry._get(id);
+ }
// TODO: Support varargs when there is support in the language.
- return ([arg0 = _UNSPECIFIED, arg1 = _UNSPECIFIED,
+ var f = ([arg0 = _UNSPECIFIED, arg1 = _UNSPECIFIED,
arg2 = _UNSPECIFIED, arg3 = _UNSPECIFIED]) {
var args = [arg0, arg1, arg2, arg3];
var last = args.indexOf(_UNSPECIFIED);
@@ -40979,6 +41018,8 @@ class _JsDeserializer extends _Deserializer {
var message = [id, args];
return port.callSync(message);
};
+ _deserializedFunctionTable.add(f, x);
+ return f;
}
deserializeProxy(x) {
« no previous file with comments | « lib/html/dart2js/html_dart2js.dart ('k') | lib/html/src/Isolates.dart » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698