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

Side by Side Diff: pkg/analyzer/lib/src/context/cache.dart

Issue 1120313004: Get memento objects from tasks, remember in cache and pass back to tasks. (Closed) Base URL: https://dart.googlecode.com/svn/branches/bleeding_edge/dart
Patch Set: Created 5 years, 7 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) 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:collection'; 7 import 'dart:collection';
8 8
9 import 'package:analyzer/src/generated/ast.dart'; 9 import 'package:analyzer/src/generated/ast.dart';
10 import 'package:analyzer/src/generated/engine.dart' 10 import 'package:analyzer/src/generated/engine.dart'
(...skipping 313 matching lines...) Expand 10 before | Expand all | Expand 10 after
324 _resultMap.forEach((ResultDescriptor descriptor, ResultData data) { 324 _resultMap.forEach((ResultDescriptor descriptor, ResultData data) {
325 if (data.value is AstNode || data.value is XmlNode) { 325 if (data.value is AstNode || data.value is XmlNode) {
326 _validateStateChange(descriptor, CacheState.FLUSHED); 326 _validateStateChange(descriptor, CacheState.FLUSHED);
327 data.state = CacheState.FLUSHED; 327 data.state = CacheState.FLUSHED;
328 data.value = descriptor.defaultValue; 328 data.value = descriptor.defaultValue;
329 } 329 }
330 }); 330 });
331 } 331 }
332 332
333 /** 333 /**
334 * Return the memento of the result represented by the given [descriptor].
335 */
336 dynamic getMemento(ResultDescriptor descriptor) {
337 ResultData data = _resultMap[descriptor];
338 if (data == null) {
339 return null;
340 }
341 return data.memento;
342 }
343
344 /**
334 * Return the state of the result represented by the given [descriptor]. 345 * Return the state of the result represented by the given [descriptor].
335 */ 346 */
336 CacheState getState(ResultDescriptor descriptor) { 347 CacheState getState(ResultDescriptor descriptor) {
337 ResultData data = _resultMap[descriptor]; 348 ResultData data = _resultMap[descriptor];
338 if (data == null) { 349 if (data == null) {
339 return CacheState.INVALID; 350 return CacheState.INVALID;
340 } 351 }
341 return data.state; 352 return data.state;
342 } 353 }
343 354
(...skipping 90 matching lines...) Expand 10 before | Expand all | Expand 10 after
434 // If the state is in-process, we can leave the current value in the 445 // If the state is in-process, we can leave the current value in the
435 // cache for any 'get' methods to access. 446 // cache for any 'get' methods to access.
436 // 447 //
437 data.value = descriptor.defaultValue; 448 data.value = descriptor.defaultValue;
438 } 449 }
439 } 450 }
440 } 451 }
441 452
442 /** 453 /**
443 * Set the value of the result represented by the given [descriptor] to the 454 * Set the value of the result represented by the given [descriptor] to the
444 * given [value]. 455 * given [value]. The optional [memento] may help to recompute [value] more
456 * efficiently after invalidation.
445 */ 457 */
446 /*<V>*/ void setValue(ResultDescriptor /*<V>*/ descriptor, dynamic /*V*/ 458 /*<V>*/ void setValue(ResultDescriptor /*<V>*/ descriptor, dynamic /*V*/
447 value, List<TargetedResult> dependedOn) { 459 value, List<TargetedResult> dependedOn, [dynamic memento]) {
448 _validateStateChange(descriptor, CacheState.VALID); 460 _validateStateChange(descriptor, CacheState.VALID);
449 ResultData data = _getResultData(descriptor); 461 ResultData data = _getResultData(descriptor);
450 { 462 {
451 TargetedResult thisResult = new TargetedResult(_target, descriptor); 463 TargetedResult thisResult = new TargetedResult(_target, descriptor);
452 data.invalidate(_cache, thisResult, CacheState.INVALID); 464 data.invalidate(_cache, thisResult, CacheState.INVALID);
453 data.setDependedOnResults(_cache, thisResult, dependedOn); 465 data.setDependedOnResults(_cache, thisResult, dependedOn);
454 } 466 }
455 data.state = CacheState.VALID; 467 data.state = CacheState.VALID;
456 data.value = value == null ? descriptor.defaultValue : value; 468 data.value = value == null ? descriptor.defaultValue : value;
469 data.memento = memento;
457 } 470 }
458 471
459 @override 472 @override
460 String toString() { 473 String toString() {
461 StringBuffer buffer = new StringBuffer(); 474 StringBuffer buffer = new StringBuffer();
462 _writeOn(buffer); 475 _writeOn(buffer);
463 return buffer.toString(); 476 return buffer.toString();
464 } 477 }
465 478
466 /** 479 /**
(...skipping 347 matching lines...) Expand 10 before | Expand all | Expand 10 after
814 */ 827 */
815 CacheState state; 828 CacheState state;
816 829
817 /** 830 /**
818 * The value being cached, or the default value for the result if there is no 831 * The value being cached, or the default value for the result if there is no
819 * value (for example, when the [state] is [CacheState.INVALID]). 832 * value (for example, when the [state] is [CacheState.INVALID]).
820 */ 833 */
821 Object value; 834 Object value;
822 835
823 /** 836 /**
837 * The optional data that is remembered with [value] and, when [value] is
838 * invalidated, may help to recompute it more efficiently.
839 */
840 dynamic memento;
Brian Wilkerson 2015/05/04 16:22:09 nit: I generally prefer 'Object' over 'dynamic' as
841
842 /**
824 * A list of the results on which this result depends. 843 * A list of the results on which this result depends.
825 */ 844 */
826 List<TargetedResult> dependedOnResults = <TargetedResult>[]; 845 List<TargetedResult> dependedOnResults = <TargetedResult>[];
827 846
828 /** 847 /**
829 * A list of the results that depend on this result. 848 * A list of the results that depend on this result.
830 */ 849 */
831 List<TargetedResult> dependentResults = <TargetedResult>[]; 850 List<TargetedResult> dependentResults = <TargetedResult>[];
832 851
833 /** 852 /**
(...skipping 130 matching lines...) Expand 10 before | Expand all | Expand 10 after
964 * structures in the cache, using the [retentionPolicy] to determine which 983 * structures in the cache, using the [retentionPolicy] to determine which
965 * AST structures to flush. 984 * AST structures to flush.
966 */ 985 */
967 UniversalCachePartition(InternalAnalysisContext context, int maxCacheSize, 986 UniversalCachePartition(InternalAnalysisContext context, int maxCacheSize,
968 CacheRetentionPolicy retentionPolicy) 987 CacheRetentionPolicy retentionPolicy)
969 : super(context, maxCacheSize, retentionPolicy); 988 : super(context, maxCacheSize, retentionPolicy);
970 989
971 @override 990 @override
972 bool contains(AnalysisTarget target) => true; 991 bool contains(AnalysisTarget target) => true;
973 } 992 }
OLDNEW
« no previous file with comments | « no previous file | pkg/analyzer/lib/src/task/driver.dart » ('j') | pkg/analyzer/lib/src/task/driver.dart » ('J')

Powered by Google App Engine
This is Rietveld 408576698