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/dart/element/element.dart' | 10 import 'package:analyzer/src/dart/element/element.dart' |
| (...skipping 585 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 596 deltaResult == DeltaResult.INVALIDATE_NO_DELTA) { | 596 deltaResult == DeltaResult.INVALIDATE_NO_DELTA) { |
| 597 _resultMap.remove(descriptor); | 597 _resultMap.remove(descriptor); |
| 598 // { | 598 // { |
| 599 // String indent = ' ' * level; | 599 // String indent = ' ' * level; |
| 600 // print('[$id]$indent invalidate $descriptor for $target'); | 600 // print('[$id]$indent invalidate $descriptor for $target'); |
| 601 // } | 601 // } |
| 602 } | 602 } |
| 603 // Stop depending on other results. | 603 // Stop depending on other results. |
| 604 if (deltaResult != DeltaResult.KEEP_CONTINUE) { | 604 if (deltaResult != DeltaResult.KEEP_CONTINUE) { |
| 605 TargetedResult thisResult = new TargetedResult(target, descriptor); | 605 TargetedResult thisResult = new TargetedResult(target, descriptor); |
| 606 for (TargetedResult dependedOnResult in thisData.dependedOnResults) { | 606 List<AnalysisCache> caches = _partition.containingCaches; |
| 607 for (AnalysisCache cache in _partition.containingCaches) { | 607 int cacheLength = caches.length; |
| 608 List<TargetedResult> results = thisData.dependedOnResults; | |
| 609 int resultLength = results.length; | |
| 610 for (int i = 0; i < resultLength; i++) { | |
| 611 TargetedResult dependedOnResult = results[i]; | |
| 612 for (int j = 0; j < cacheLength; j++) { | |
| 613 AnalysisCache cache = caches[j]; | |
| 608 CacheEntry entry = cache.get(dependedOnResult.target); | 614 CacheEntry entry = cache.get(dependedOnResult.target); |
| 609 if (entry != null) { | 615 if (entry != null) { |
| 610 ResultData data = | 616 ResultData data = |
| 611 entry.getResultDataOrNull(dependedOnResult.result); | 617 entry.getResultDataOrNull(dependedOnResult.result); |
| 612 if (data != null) { | 618 if (data != null) { |
| 613 data.dependentResults.remove(thisResult); | 619 data.dependentResults.remove(thisResult); |
| 614 } | 620 } |
| 615 } | 621 } |
| 616 } | 622 } |
| 617 } | 623 } |
| (...skipping 11 matching lines...) Expand all Loading... | |
| 629 // Notify controller. | 635 // Notify controller. |
| 630 _partition.onResultInvalidated | 636 _partition.onResultInvalidated |
| 631 .add(new InvalidatedResult(this, descriptor, thisData.value)); | 637 .add(new InvalidatedResult(this, descriptor, thisData.value)); |
| 632 } | 638 } |
| 633 | 639 |
| 634 /** | 640 /** |
| 635 * Invalidates all the results of this entry, with propagation. | 641 * Invalidates all the results of this entry, with propagation. |
| 636 */ | 642 */ |
| 637 void _invalidateAll() { | 643 void _invalidateAll() { |
| 638 List<ResultDescriptor> results = _resultMap.keys.toList(); | 644 List<ResultDescriptor> results = _resultMap.keys.toList(); |
| 639 for (ResultDescriptor result in results) { | 645 int length = results.length; |
| 646 for (int i = 0; i < length; i++) { | |
| 647 ResultDescriptor result = results[i]; | |
| 640 _invalidate(nextInvalidateId++, result, null, 0); | 648 _invalidate(nextInvalidateId++, result, null, 0); |
| 641 } | 649 } |
| 642 } | 650 } |
| 643 | 651 |
| 644 /** | 652 /** |
| 645 * Invalidate results that depend on [thisData]. | 653 * Invalidate results that depend on [thisData]. |
| 646 */ | 654 */ |
| 647 void _invalidateDependentResults( | 655 void _invalidateDependentResults( |
| 648 int id, ResultData thisData, Delta delta, int level) { | 656 int id, ResultData thisData, Delta delta, int level) { |
| 649 // It is necessary to copy the results to a list to avoid a concurrent | 657 // It is necessary to copy the results to a list to avoid a concurrent |
| 650 // modification of the set of dependent results. | 658 // modification of the set of dependent results. |
| 659 List<AnalysisCache> caches = _partition.containingCaches; | |
| 660 int cacheLength = caches.length; | |
| 651 List<TargetedResult> dependentResults = thisData.dependentResults.toList(); | 661 List<TargetedResult> dependentResults = thisData.dependentResults.toList(); |
| 652 for (TargetedResult dependentResult in dependentResults) { | 662 int resultLength = dependentResults.length; |
| 653 for (AnalysisCache cache in _partition.containingCaches) { | 663 for (int i = 0; i < resultLength; i++) { |
| 664 TargetedResult dependentResult = dependentResults[i]; | |
| 665 for (int j = 0; j < cacheLength; j++) { | |
| 666 AnalysisCache cache = caches[j]; | |
| 654 CacheEntry entry = cache.get(dependentResult.target); | 667 CacheEntry entry = cache.get(dependentResult.target); |
| 655 if (entry != null) { | 668 if (entry != null) { |
| 656 entry._invalidate(id, dependentResult.result, delta, level); | 669 entry._invalidate(id, dependentResult.result, delta, level); |
| 657 } | 670 } |
| 658 } | 671 } |
| 659 } | 672 } |
| 660 } | 673 } |
| 661 | 674 |
| 662 /** | 675 /** |
| 663 * If the given `target` is an element, mark it as being a cache key. | 676 * If the given `target` is an element, mark it as being a cache key. |
| 664 */ | 677 */ |
| 665 void _markAsCacheKey(AnalysisTarget target) { | 678 void _markAsCacheKey(AnalysisTarget target) { |
| 666 if (target is ElementImpl) { | 679 if (target is ElementImpl) { |
| 667 target.setModifier(Modifier.CACHE_KEY, true); | 680 target.setModifier(Modifier.CACHE_KEY, true); |
| 668 } | 681 } |
| 669 } | 682 } |
| 670 | 683 |
| 671 /** | 684 /** |
| 672 * Set the [dependedOn] on which this result depends. | 685 * Set the [dependedOn] on which this result depends. |
| 673 */ | 686 */ |
| 674 void _setDependedOnResults(ResultData thisData, TargetedResult thisResult, | 687 void _setDependedOnResults(ResultData thisData, TargetedResult thisResult, |
| 675 List<TargetedResult> dependedOn) { | 688 List<TargetedResult> dependedOn) { |
| 676 thisData.dependedOnResults.forEach((TargetedResult dependedOnResult) { | 689 List<AnalysisCache> caches = _partition.containingCaches; |
| 677 for (AnalysisCache cache in _partition.containingCaches) { | 690 int cacheLength = caches.length; |
| 691 | |
| 692 List<TargetedResult> oldResults = thisData.dependedOnResults; | |
| 693 int oldLength = oldResults.length; | |
| 694 for (int i = 0; i < oldLength; i++) { | |
| 695 TargetedResult dependedOnResult = oldResults[i]; | |
| 696 for (int j = 0; j < cacheLength; j++) { | |
| 697 AnalysisCache cache = caches[j]; | |
| 678 CacheEntry entry = cache.get(dependedOnResult.target); | 698 CacheEntry entry = cache.get(dependedOnResult.target); |
| 679 if (entry != null) { | 699 if (entry != null) { |
| 680 ResultData data = entry.getResultDataOrNull(dependedOnResult.result); | 700 ResultData data = entry.getResultDataOrNull(dependedOnResult.result); |
| 681 if (data != null) { | 701 if (data != null) { |
| 682 data.dependentResults.remove(thisResult); | 702 data.dependentResults.remove(thisResult); |
| 683 } | 703 } |
| 684 } | 704 } |
| 685 } | 705 } |
| 686 }); | 706 } |
| 687 thisData.dependedOnResults = dependedOn; | 707 thisData.dependedOnResults = dependedOn; |
| 688 thisData.dependedOnResults.forEach((TargetedResult dependedOnResult) { | 708 int newLength = dependedOn.length; |
| 689 for (AnalysisCache cache in _partition.containingCaches) { | 709 for (int i = 0; i < newLength; i++) { |
| 710 TargetedResult dependedOnResult = dependedOn[i]; | |
| 711 for (int j = 0; j < cacheLength; j++) { | |
| 712 AnalysisCache cache = caches[j]; | |
| 690 CacheEntry entry = cache.get(dependedOnResult.target); | 713 CacheEntry entry = cache.get(dependedOnResult.target); |
| 691 if (entry != null) { | 714 if (entry != null) { |
| 692 ResultData data = entry.getResultDataOrNull(dependedOnResult.result); | 715 ResultData data = entry.getResultDataOrNull(dependedOnResult.result); |
| 693 if (data != null) { | 716 if (data != null) { |
| 694 data.dependentResults.add(thisResult); | 717 data.dependentResults.add(thisResult); |
| 695 } | 718 } |
| 696 } | 719 } |
| 697 } | 720 } |
| 698 }); | 721 } |
| 699 } | 722 } |
| 700 | 723 |
| 701 /** | 724 /** |
| 702 * Set states of the given and dependent results to [CacheState.ERROR] and | 725 * Set states of the given and dependent results to [CacheState.ERROR] and |
| 703 * their values to the corresponding default values | 726 * their values to the corresponding default values |
| 704 */ | 727 */ |
| 705 void _setErrorState(ResultDescriptor descriptor, CaughtException exception) { | 728 void _setErrorState(ResultDescriptor descriptor, CaughtException exception) { |
| 706 ResultData thisData = getResultData(descriptor); | 729 ResultData thisData = getResultData(descriptor); |
| 707 // Set the error state. | 730 // Set the error state. |
| 708 _exception = exception; | 731 _exception = exception; |
| 709 thisData.state = CacheState.ERROR; | 732 thisData.state = CacheState.ERROR; |
| 710 thisData.value = descriptor.defaultValue; | 733 thisData.value = descriptor.defaultValue; |
| 711 // Propagate the error state. | 734 // Propagate the error state. |
| 735 List<AnalysisCache> caches = _partition.containingCaches; | |
| 736 int cacheLength = caches.length; | |
| 712 thisData.dependentResults.forEach((TargetedResult dependentResult) { | 737 thisData.dependentResults.forEach((TargetedResult dependentResult) { |
| 713 for (AnalysisCache cache in _partition.containingCaches) { | 738 for (int j = 0; j < cacheLength; j++) { |
|
scheglov
2016/05/25 17:44:46
Could be 'i'.
Brian Wilkerson
2016/05/25 17:48:42
Done
| |
| 739 AnalysisCache cache = caches[j]; | |
| 714 CacheEntry entry = cache.get(dependentResult.target); | 740 CacheEntry entry = cache.get(dependentResult.target); |
| 715 if (entry != null) { | 741 if (entry != null) { |
| 716 entry._setErrorState(dependentResult.result, exception); | 742 entry._setErrorState(dependentResult.result, exception); |
| 717 } | 743 } |
| 718 } | 744 } |
| 719 }); | 745 }); |
| 720 } | 746 } |
| 721 | 747 |
| 722 /** | 748 /** |
| 723 * Set the value of the flag with the given [index] to the given [value]. | 749 * Set the value of the flag with the given [index] to the given [value]. |
| (...skipping 599 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 1323 void resultAccessed(TargetedResult result) {} | 1349 void resultAccessed(TargetedResult result) {} |
| 1324 | 1350 |
| 1325 @override | 1351 @override |
| 1326 List<TargetedResult> resultStored(TargetedResult newResult, newValue) { | 1352 List<TargetedResult> resultStored(TargetedResult newResult, newValue) { |
| 1327 return TargetedResult.EMPTY_LIST; | 1353 return TargetedResult.EMPTY_LIST; |
| 1328 } | 1354 } |
| 1329 | 1355 |
| 1330 @override | 1356 @override |
| 1331 void targetRemoved(AnalysisTarget target) {} | 1357 void targetRemoved(AnalysisTarget target) {} |
| 1332 } | 1358 } |
| OLD | NEW |