Chromium Code Reviews| OLD | NEW |
|---|---|
| 1 // Copyright (c) 2015, the Dart project authors. Please see the AUTHORS file | 1 // Copyright (c) 2015, 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 analyzer.src.context.cache; | 5 library analyzer.src.context.cache; |
| 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' | 10 import 'package:analyzer/src/generated/engine.dart' |
| (...skipping 197 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 208 } | 208 } |
| 209 partition.put(entry); | 209 partition.put(entry); |
| 210 return; | 210 return; |
| 211 } | 211 } |
| 212 } | 212 } |
| 213 // TODO(brianwilkerson) Handle the case where no partition was found, | 213 // TODO(brianwilkerson) Handle the case where no partition was found, |
| 214 // possibly by throwing an exception. | 214 // possibly by throwing an exception. |
| 215 } | 215 } |
| 216 | 216 |
| 217 /** | 217 /** |
| 218 * Remove all information related to the given [target] from this cache. | 218 * Remove all information related to the given [target] from this cache and |
| 219 * return the entry associated with the target. | |
|
Paul Berry
2015/07/15 19:50:01
Let's also document the fact that we return `null`
Brian Wilkerson
2015/07/15 21:23:37
Done
| |
| 219 */ | 220 */ |
| 220 void remove(AnalysisTarget target) { | 221 CacheEntry remove(AnalysisTarget target) { |
| 221 int count = _partitions.length; | 222 int count = _partitions.length; |
| 222 for (int i = 0; i < count; i++) { | 223 for (int i = 0; i < count; i++) { |
| 223 CachePartition partition = _partitions[i]; | 224 CachePartition partition = _partitions[i]; |
| 224 if (partition.isResponsibleFor(target)) { | 225 if (partition.isResponsibleFor(target)) { |
| 225 if (_TRACE_CHANGES) { | 226 if (_TRACE_CHANGES) { |
| 226 AnalysisEngine.instance.logger | 227 AnalysisEngine.instance.logger |
| 227 .logInformation('Removed the cache entry for $target.'); | 228 .logInformation('Removed the cache entry for $target.'); |
| 228 } | 229 } |
| 229 partition.remove(target); | 230 return partition.remove(target); |
| 230 return; | |
| 231 } | 231 } |
| 232 } | 232 } |
| 233 return null; | |
| 233 } | 234 } |
| 234 | 235 |
| 235 /** | 236 /** |
| 236 * Return the number of targets that are mapped to cache entries. | 237 * Return the number of targets that are mapped to cache entries. |
| 237 */ | 238 */ |
| 238 int size() { | 239 int size() { |
| 239 int size = 0; | 240 int size = 0; |
| 240 int count = _partitions.length; | 241 int count = _partitions.length; |
| 241 for (int i = 0; i < count; i++) { | 242 for (int i = 0; i < count; i++) { |
| 242 size += _partitions[i].size(); | 243 size += _partitions[i].size(); |
| (...skipping 646 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 889 throw new StateError( | 890 throw new StateError( |
| 890 'The entry for $target is already in ${entry._partition}'); | 891 'The entry for $target is already in ${entry._partition}'); |
| 891 } | 892 } |
| 892 entry._partition = this; | 893 entry._partition = this; |
| 893 entry.fixExceptionState(); | 894 entry.fixExceptionState(); |
| 894 _targetMap[target] = entry; | 895 _targetMap[target] = entry; |
| 895 _addIfSource(target); | 896 _addIfSource(target); |
| 896 } | 897 } |
| 897 | 898 |
| 898 /** | 899 /** |
| 899 * Remove all information related to the given [target] from this cache. | 900 * Remove all information related to the given [target] from this partition |
| 901 * and return the entry associated with the target. | |
|
Paul Berry
2015/07/15 19:50:01
Similar comment here.
Brian Wilkerson
2015/07/15 21:23:37
Done
| |
| 900 */ | 902 */ |
| 901 void remove(AnalysisTarget target) { | 903 CacheEntry remove(AnalysisTarget target) { |
| 902 for (CacheFlushManager flushManager in _flushManagerMap.values) { | 904 for (CacheFlushManager flushManager in _flushManagerMap.values) { |
| 903 flushManager.targetRemoved(target); | 905 flushManager.targetRemoved(target); |
| 904 } | 906 } |
| 905 CacheEntry entry = _targetMap.remove(target); | 907 CacheEntry entry = _targetMap.remove(target); |
| 906 if (entry != null) { | 908 if (entry != null) { |
| 907 entry._invalidateAll(); | 909 entry._invalidateAll(); |
| 908 } | 910 } |
| 909 _removeIfSource(target); | 911 _removeIfSource(target); |
| 912 return entry; | |
| 910 } | 913 } |
| 911 | 914 |
| 912 /** | 915 /** |
| 913 * Records that a value of the result described by the given [descriptor] | 916 * Records that a value of the result described by the given [descriptor] |
| 914 * for the given [target] was just read from the cache. | 917 * for the given [target] was just read from the cache. |
| 915 */ | 918 */ |
| 916 void resultAccessed(AnalysisTarget target, ResultDescriptor descriptor) { | 919 void resultAccessed(AnalysisTarget target, ResultDescriptor descriptor) { |
| 917 CacheFlushManager flushManager = _getFlushManager(descriptor); | 920 CacheFlushManager flushManager = _getFlushManager(descriptor); |
| 918 TargetedResult result = new TargetedResult(target, descriptor); | 921 TargetedResult result = new TargetedResult(target, descriptor); |
| 919 flushManager.resultAccessed(result); | 922 flushManager.resultAccessed(result); |
| (...skipping 54 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 974 _flushManagerMap[policy] = manager; | 977 _flushManagerMap[policy] = manager; |
| 975 } | 978 } |
| 976 return manager; | 979 return manager; |
| 977 } | 980 } |
| 978 | 981 |
| 979 bool _isPriorityAnalysisTarget(AnalysisTarget target) { | 982 bool _isPriorityAnalysisTarget(AnalysisTarget target) { |
| 980 return context.priorityTargets.contains(target); | 983 return context.priorityTargets.contains(target); |
| 981 } | 984 } |
| 982 | 985 |
| 983 /** | 986 /** |
| 984 * If the given [target] is a [Source], removes it from [_sources]. | 987 * If the given [target] is a [Source], remove it from the list of [_sources]. |
| 985 */ | 988 */ |
| 986 void _removeIfSource(AnalysisTarget target) { | 989 void _removeIfSource(AnalysisTarget target) { |
| 987 if (target is Source) { | 990 if (target is Source) { |
| 988 _sources.remove(target); | 991 _sources.remove(target); |
| 989 { | 992 String fullName = target.fullName; |
| 990 String fullName = target.fullName; | 993 List<Source> sources = _pathToSources[fullName]; |
| 991 List<Source> sources = _pathToSources[fullName]; | 994 if (sources != null) { |
| 992 if (sources != null) { | 995 sources.remove(target); |
| 993 sources.remove(target); | 996 if (sources.isEmpty) { |
| 994 if (sources.isEmpty) { | 997 _pathToSources.remove(fullName); |
| 995 _pathToSources.remove(fullName); | |
| 996 } | |
| 997 } | 998 } |
| 998 } | 999 } |
| 999 } | 1000 } |
| 1000 } | 1001 } |
| 1001 } | 1002 } |
| 1002 | 1003 |
| 1003 /** | 1004 /** |
| 1004 * The description for a change. | 1005 * The description for a change. |
| 1005 */ | 1006 */ |
| 1006 class Delta { | 1007 class Delta { |
| (...skipping 172 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 1179 void resultAccessed(TargetedResult result) {} | 1180 void resultAccessed(TargetedResult result) {} |
| 1180 | 1181 |
| 1181 @override | 1182 @override |
| 1182 List<TargetedResult> resultStored(TargetedResult newResult, newValue) { | 1183 List<TargetedResult> resultStored(TargetedResult newResult, newValue) { |
| 1183 return TargetedResult.EMPTY_LIST; | 1184 return TargetedResult.EMPTY_LIST; |
| 1184 } | 1185 } |
| 1185 | 1186 |
| 1186 @override | 1187 @override |
| 1187 void targetRemoved(AnalysisTarget target) {} | 1188 void targetRemoved(AnalysisTarget target) {} |
| 1188 } | 1189 } |
| OLD | NEW |