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

Unified Diff: pkg/analyzer/lib/src/task/options.dart

Issue 1505623002: ErrorCode hashing for faster lookup in validation. (Closed) Base URL: git@github.com:dart-lang/sdk.git@master
Patch Set: master_merge Created 5 years 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
« no previous file with comments | « no previous file | no next file » | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: pkg/analyzer/lib/src/task/options.dart
diff --git a/pkg/analyzer/lib/src/task/options.dart b/pkg/analyzer/lib/src/task/options.dart
index 059649012a84d9155084abbb12155e43bf5f7e59..ee6823efffc25234ea54c70e1c31af27900f8593 100644
--- a/pkg/analyzer/lib/src/task/options.dart
+++ b/pkg/analyzer/lib/src/task/options.dart
@@ -4,6 +4,8 @@
library analyzer.src.task.options;
+import 'dart:collection';
+
import 'package:analyzer/analyzer.dart';
import 'package:analyzer/plugin/options.dart';
import 'package:analyzer/source/analysis_options_provider.dart';
@@ -126,9 +128,20 @@ class ErrorFilterOptionValidator extends OptionsValidator {
new List.from(AnalyzerOptions.ignoreSynonyms)
..addAll(AnalyzerOptions.includeSynonyms));
- bool recognizedErrorCode(String name) =>
- ErrorCode.values.any((ErrorCode code) => code.name == name) ||
- StaticInfo.names.contains(name);
+ /// Lazily populated set of error codes (hashed for speedy lookup).
+ static HashSet<String> _errorCodes;
+
+ /// Legal error code names.
+ static Set<String> get errorCodes {
+ if (_errorCodes == null) {
+ _errorCodes = new HashSet<String>();
+ // Engine codes.
+ _errorCodes.addAll(ErrorCode.values.map((ErrorCode code) => code.name));
+ // Strong-mode codes.
+ _errorCodes.addAll(StaticInfo.names);
+ }
+ return _errorCodes;
+ }
@override
void validate(ErrorReporter reporter, Map<String, YamlNode> options) {
@@ -143,7 +156,7 @@ class ErrorFilterOptionValidator extends OptionsValidator {
filters.nodes.forEach((k, v) {
if (k is YamlScalar) {
value = toUpperCase(k.value);
- if (!recognizedErrorCode(value)) {
+ if (!errorCodes.contains(value)) {
reporter.reportErrorForSpan(
AnalysisOptionsWarningCode.UNRECOGNIZED_ERROR_CODE,
k.span,
« no previous file with comments | « no previous file | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698