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

Side by Side Diff: pkg/analyzer/lib/file_system/memory_file_system.dart

Issue 941883002: cache pub list results (Closed) Base URL: https://dart.googlecode.com/svn/branches/bleeding_edge/dart
Patch Set: address comments and discussions Created 5 years, 10 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 unified diff | Download patch | Annotate | Revision Log
OLDNEW
1 // Copyright (c) 2014, the Dart project authors. Please see the AUTHORS file 1 // Copyright (c) 2014, the Dart project authors. Please see the AUTHORS file
2 // for details. All rights reserved. Use of this source code is governed by a 2 // for details. All rights reserved. Use of this source code is governed by a
3 // BSD-style license that can be found in the LICENSE file. 3 // BSD-style license that can be found in the LICENSE file.
4 4
5 library memory_file_system; 5 library memory_file_system;
6 6
7 import 'dart:async'; 7 import 'dart:async';
8 import 'dart:collection'; 8 import 'dart:collection';
9 9
10 import 'package:analyzer/src/generated/engine.dart' show TimestampedData; 10 import 'package:analyzer/src/generated/engine.dart' show TimestampedData;
(...skipping 29 matching lines...) Expand all
40 new HashMap<String, _MemoryResource>(); 40 new HashMap<String, _MemoryResource>();
41 final Map<String, String> _pathToContent = new HashMap<String, String>(); 41 final Map<String, String> _pathToContent = new HashMap<String, String>();
42 final Map<String, int> _pathToTimestamp = new HashMap<String, int>(); 42 final Map<String, int> _pathToTimestamp = new HashMap<String, int>();
43 final Map<String, List<StreamController<WatchEvent>>> _pathToWatchers = 43 final Map<String, List<StreamController<WatchEvent>>> _pathToWatchers =
44 new HashMap<String, List<StreamController<WatchEvent>>>(); 44 new HashMap<String, List<StreamController<WatchEvent>>>();
45 int nextStamp = 0; 45 int nextStamp = 0;
46 46
47 @override 47 @override
48 Context get pathContext => posix; 48 Context get pathContext => posix;
49 49
50 /**
51 * Simulate revoked file access
scheglov 2015/02/22 19:31:31 This comment describes the method from the perspec
danrubel 2015/02/24 02:29:45 Good point. I reworked this into a deleteFolder me
52 * and return an object that can be passed to [restore].
53 */
54 clear() {
scheglov 2015/02/22 19:31:31 Could we have some type here and in "restore"? Eve
danrubel 2015/02/24 02:29:45 That makes sense. Instead it was decided that a re
55 var restorePoint = new _MemoryRestorePoint(this);
56 _pathToResource.clear();
57 _pathToContent.clear();
58 _pathToTimestamp.clear();
59 // TODO(danrubel) notify watchers
60 return restorePoint;
61 }
62
63 /**
64 * Simulate restored file access based upon some earlier call to [clear].
65 */
66 void restore(var restorePoint) {
67 _pathToResource.clear();
68 _pathToContent.clear();
69 _pathToTimestamp.clear();
70 (restorePoint as _MemoryRestorePoint).restore(this);
71 // TODO(danrubel) notify watchers
72 }
73
50 void deleteFile(String path) { 74 void deleteFile(String path) {
51 _checkFileAtPath(path); 75 _checkFileAtPath(path);
52 _pathToResource.remove(path); 76 _pathToResource.remove(path);
53 _pathToContent.remove(path); 77 _pathToContent.remove(path);
54 _pathToTimestamp.remove(path); 78 _pathToTimestamp.remove(path);
55 _notifyWatchers(path, ChangeType.REMOVE); 79 _notifyWatchers(path, ChangeType.REMOVE);
56 } 80 }
57 81
58 @override 82 @override
59 Resource getResource(String path) { 83 Resource getResource(String path) {
(...skipping 82 matching lines...) Expand 10 before | Expand all | Expand 10 after
142 { 166 {
143 streamController.add(new WatchEvent(changeType, path)); 167 streamController.add(new WatchEvent(changeType, path));
144 } 168 }
145 } 169 }
146 }); 170 });
147 } 171 }
148 } 172 }
149 173
150 174
151 /** 175 /**
176 * A restore point captures the [MemoryResourceProvider] state
177 * so that it can be restored at later point.
178 */
179 class _MemoryRestorePoint {
180 final Map<String, _MemoryResource> _pathToResource =
181 new HashMap<String, _MemoryResource>();
182 final Map<String, String> _pathToContent = new HashMap<String, String>();
183 final Map<String, int> _pathToTimestamp = new HashMap<String, int>();
184
185 _MemoryRestorePoint(MemoryResourceProvider provider) {
186 _pathToResource.addAll(provider._pathToResource);
187 _pathToContent.addAll(provider._pathToContent);
188 _pathToTimestamp.addAll(provider._pathToTimestamp);
189 }
190
191 void restore(MemoryResourceProvider provider) {
192 provider._pathToResource.addAll(_pathToResource);
193 provider._pathToContent.addAll(_pathToContent);
194 provider._pathToTimestamp.addAll(_pathToTimestamp);
195 }
196 }
197
198
199 /**
152 * An in-memory implementation of [File] which acts like a symbolic link to a 200 * An in-memory implementation of [File] which acts like a symbolic link to a
153 * non-existent file. 201 * non-existent file.
154 */ 202 */
155 class _MemoryDummyLink extends _MemoryResource implements File { 203 class _MemoryDummyLink extends _MemoryResource implements File {
156 _MemoryDummyLink(MemoryResourceProvider provider, String path) 204 _MemoryDummyLink(MemoryResourceProvider provider, String path)
157 : super(provider, path); 205 : super(provider, path);
158 206
159 @override 207 @override
160 bool get exists => false; 208 bool get exists => false;
161 209
(...skipping 214 matching lines...) Expand 10 before | Expand all | Expand 10 after
376 bool operator ==(other) { 424 bool operator ==(other) {
377 if (runtimeType != other.runtimeType) { 425 if (runtimeType != other.runtimeType) {
378 return false; 426 return false;
379 } 427 }
380 return path == other.path; 428 return path == other.path;
381 } 429 }
382 430
383 @override 431 @override
384 String toString() => path; 432 String toString() => path;
385 } 433 }
OLDNEW
« no previous file with comments | « pkg/analysis_server/test/test_all.dart ('k') | pkg/analyzer/lib/source/pub_package_map_provider.dart » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698