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

Unified Diff: runtime/lib/lib_prefix.dart

Issue 328923002: Lazy loading of deferred libraries (Closed) Base URL: http://dart.googlecode.com/svn/branches/bleeding_edge/dart/
Patch Set: Created 6 years, 6 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: runtime/lib/lib_prefix.dart
===================================================================
--- runtime/lib/lib_prefix.dart (revision 37209)
+++ runtime/lib/lib_prefix.dart (working copy)
@@ -6,19 +6,45 @@
import "dart:isolate";
// This type corresponds to the VM-internal class LibraryPrefix.
-
class _LibraryPrefix {
- _load() native "LibraryPrefix_load";
+ bool _load() native "LibraryPrefix_load";
+
+ void _invalidateDependentCode()
+ native "LibraryPrefix_invalidateDependentCode";
+
loadLibrary() {
- var completer = new Completer<bool>();
+ var completer = _outstandingLoadRequests[this];
+ if (completer != null) {
+ return completer.future;
+ }
+ completer = new Completer<bool>();
+ _outstandingLoadRequests[this] = completer;
var port = new RawReceivePort();
Ivan Posva 2014/06/12 23:05:11 We can simplify this with Timer.run(() {...}).
hausner 2014/06/12 23:54:37 Done.
port.handler = (_) {
- this._load();
- completer.complete(true);
+ var hasCompleted = this._load();
+ if (hasCompleted) {
+ _invalidateDependentCode();
Ivan Posva 2014/06/12 23:05:11 How about a comment explaining why this is needed?
hausner 2014/06/12 23:54:37 Done.
+ completer.complete(true);
+ _outstandingLoadRequests.remove(this);
+ }
port.close();
};
port.sendPort.send(1);
return completer.future;
}
}
+
+var _outstandingLoadRequests = new Map<_LibraryPrefix, Completer>();
+
+
+// Called from the VM when all outstanding load requests have
+// finished.
+_completeDeferredLoads() {
+ var lenghth = _outstandingLoadRequests;
+ _outstandingLoadRequests.forEach((prefix, completer) {
+ prefix._invalidateDependentCode();
+ completer.complete(true);
+ });
+ _outstandingLoadRequests.clear();
+}
« runtime/bin/dartutils.cc ('K') | « runtime/bin/dartutils.cc ('k') | runtime/lib/object.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698