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

Unified Diff: sdk/lib/_internal/pub_generated/lib/src/barback/transformer_cache.dart

Issue 559833004: Cache snapshots of (mostly) immutable transformer phases. (Closed) Base URL: https://dart.googlecode.com/svn/branches/bleeding_edge/dart
Patch Set: Created 6 years, 3 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: sdk/lib/_internal/pub_generated/lib/src/barback/transformer_cache.dart
diff --git a/sdk/lib/_internal/pub_generated/lib/src/barback/transformer_cache.dart b/sdk/lib/_internal/pub_generated/lib/src/barback/transformer_cache.dart
new file mode 100644
index 0000000000000000000000000000000000000000..3ef02b3258944c4c4d885fd84898e05290f3e1b9
--- /dev/null
+++ b/sdk/lib/_internal/pub_generated/lib/src/barback/transformer_cache.dart
@@ -0,0 +1,86 @@
+library pub.barback.transformer_cache;
+import 'package:path/path.dart' as p;
+import '../io.dart';
+import '../log.dart' as log;
+import '../package_graph.dart';
+import '../sdk.dart' as sdk;
+import '../source/cached.dart';
+import '../utils.dart';
+import 'asset_environment.dart';
+import 'transformer_id.dart';
+class TransformerCache {
+ final PackageGraph _graph;
+ bool _saveSnapshots;
+ List<Set<TransformerId>> _oldSnapshotPhases;
+ final _newSnapshotPhases = new List<Set<TransformerId>>();
+ String _dir;
+ String get _manifestPath => p.join(_dir, "manifest.txt");
+ TransformerCache.load(AssetEnvironment environment)
+ : _graph = environment.graph,
+ _saveSnapshots = environment.rootPackage.dir != null {
+ if (_saveSnapshots) {
+ _dir = p.join(
+ environment.rootPackage.dir,
+ ".pub",
+ "transformers",
+ Uri.encodeComponent(environment.mode.name));
+ _oldSnapshotPhases = _parseManifest();
+ } else {
+ _oldSnapshotPhases = const [];
+ _dir = null;
+ }
+ }
+ String snapshotPath(Set<TransformerId> phase, int phaseNumber) {
+ if (!_saveSnapshots) return null;
+ var usesMutableTransformer = phase.any((id) {
+ var package = _graph.lockFile.packages[id.package];
+ if (package == null) return true;
+ var source = _graph.entrypoint.cache.sources[package.source];
+ return source is! CachedSource;
+ });
+ var path = p.join(_dir, "phase$phaseNumber.snapshot");
+ if (usesMutableTransformer) {
+ log.fine(
+ "Phase $phaseNumber contains mutable transformers, not " "caching.");
+ _saveSnapshots = false;
+ deleteEntry(path);
+ return null;
+ }
+ if (_oldSnapshotPhases.length >= phaseNumber &&
+ !_oldSnapshotPhases[phaseNumber - 1].containsAll(phase)) {
+ log.fine("Cached phase $phaseNumber is out-of-date, deleting.");
+ deleteEntry(path);
+ }
+ _newSnapshotPhases.add(phase);
+ return path;
+ }
+ void save() {
+ if (_newSnapshotPhases.isEmpty) {
+ if (_dir != null) deleteEntry(_dir);
+ return;
+ }
+ ensureDir(_dir);
+ writeTextFile(
+ _manifestPath,
+ "${sdk.version}\n" + _newSnapshotPhases.map((phase) {
+ return ordered(phase.map((id) => id.toString())).join(",");
+ }).join("\n"));
+ for (var i =
+ _newSnapshotPhases.length +
+ 1; i < _oldSnapshotPhases.length + 1; i++) {
+ deleteEntry(p.join(_dir, "phase$i.snapshot"));
+ }
+ }
+ List<Set<TransformerId>> _parseManifest() {
+ if (!fileExists(_manifestPath)) return [];
+ var manifest = readTextFile(_manifestPath).split("\n");
+ if (manifest.removeAt(0) != sdk.version.toString()) {
+ deleteEntry(_dir);
+ return [];
+ }
+ return manifest.map((line) {
+ return line.split(
+ ",").map((id) => new TransformerId.parse(id, null)).toSet();
+ }).toList();
+ }
+}

Powered by Google App Engine
This is Rietveld 408576698