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

Unified Diff: lib/html/dart2js/html_dart2js.dart

Issue 10876084: Cache function proxies (Closed) Base URL: https://dart.googlecode.com/svn/branches/bleeding_edge/dart
Patch Set: Add better comments 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
Index: lib/html/dart2js/html_dart2js.dart
diff --git a/lib/html/dart2js/html_dart2js.dart b/lib/html/dart2js/html_dart2js.dart
index e8c588da7ef85aeea7cade4e5ff25d874ab9feb5..476a53a561886858603c22b9616f1c94973aeb3a 100644
--- a/lib/html/dart2js/html_dart2js.dart
+++ b/lib/html/dart2js/html_dart2js.dart
@@ -37737,6 +37737,8 @@ class _JsSerializer extends _Serializer {
}
visitFunction(Function func) {
+ var serialized = _deserializedFunctionTable.find(func);
+ if (serialized != null) return serialized;
return [ 'funcref',
_functionRegistry._add(func),
visitSendPortSync(_functionRegistry._sendPort), null ];
@@ -37833,6 +37835,33 @@ _deserialize(var message) {
return new _JsDeserializer().deserialize(message);
}
+// TODO(vsm): Use a hashmap 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 final _UNSPECIFIED = const Object();
@@ -37865,8 +37894,11 @@ class _JsDeserializer extends _Deserializer {
deserializeFunction(List x) {
var id = x[1];
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);
@@ -37874,6 +37906,8 @@ class _JsDeserializer extends _Deserializer {
var message = [id, args];
return port.callSync(message);
};
+ _deserializedFunctionTable.add(f, x);
+ return f;
}
deserializeProxy(x) {

Powered by Google App Engine
This is Rietveld 408576698