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

Side by Side Diff: pkg/analysis_server/lib/src/services/search/search_engine_internal.dart

Issue 971833003: Optimize top-level element declarations search. (Closed) Base URL: https://dart.googlecode.com/svn/branches/bleeding_edge/dart
Patch Set: Created 5 years, 9 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 services.src.search.search_engine; 5 library services.src.search.search_engine;
6 6
7 import 'dart:async'; 7 import 'dart:async';
8 8
9 import 'package:analysis_server/src/services/index/index.dart'; 9 import 'package:analysis_server/src/services/index/index.dart';
10 import 'package:analysis_server/src/services/search/search_engine.dart'; 10 import 'package:analysis_server/src/services/search/search_engine.dart';
(...skipping 85 matching lines...) Expand 10 before | Expand all | Expand 10 after
96 Future<List<SearchMatch>> searchSubtypes(ClassElement type) { 96 Future<List<SearchMatch>> searchSubtypes(ClassElement type) {
97 _Requestor requestor = new _Requestor(_index); 97 _Requestor requestor = new _Requestor(_index);
98 requestor.add(type, IndexConstants.IS_EXTENDED_BY, MatchKind.REFERENCE); 98 requestor.add(type, IndexConstants.IS_EXTENDED_BY, MatchKind.REFERENCE);
99 requestor.add(type, IndexConstants.IS_MIXED_IN_BY, MatchKind.REFERENCE); 99 requestor.add(type, IndexConstants.IS_MIXED_IN_BY, MatchKind.REFERENCE);
100 requestor.add(type, IndexConstants.IS_IMPLEMENTED_BY, MatchKind.REFERENCE); 100 requestor.add(type, IndexConstants.IS_IMPLEMENTED_BY, MatchKind.REFERENCE);
101 return requestor.merge(); 101 return requestor.merge();
102 } 102 }
103 103
104 @override 104 @override
105 Future<List<SearchMatch>> searchTopLevelDeclarations(String pattern) { 105 Future<List<SearchMatch>> searchTopLevelDeclarations(String pattern) {
106 UniverseElement universe = UniverseElement.INSTANCE;
107 _Requestor requestor = new _Requestor(_index);
108 requestor.add(universe, IndexConstants.DEFINES, MatchKind.DECLARATION);
109 RegExp regExp = new RegExp(pattern); 106 RegExp regExp = new RegExp(pattern);
110 return requestor.merge().then((List<SearchMatch> matches) { 107 List<Element> elements = _index.getTopDeclarations((String name) => regExp.h asMatch(name));
111 return matches.where((SearchMatch match) { 108 List<SearchMatch> matches = <SearchMatch>[];
112 String name = match.element.displayName; 109 for (var element in elements) {
113 return regExp.hasMatch(name); 110 SourceRange range = new SourceRange(element.nameOffset, element.name.lengt h);
114 }).toList(); 111 matches.add(new SearchMatch(MatchKind.DECLARATION, element, range, true, f alse));
115 }); 112 }
113 // TODO(scheglov) it does not have to be a Future
114 return new Future.value(matches);
115 // _Requestor requestor = new _Requestor(_index);
Brian Wilkerson 2015/03/02 19:20:07 Remove the old code or document why it's still her
scheglov 2015/03/02 19:55:46 Done.
116 // requestor.add(universe, IndexConstants.DEFINES, MatchKind.DECLARATION);
117 // return requestor.merge().then((List<SearchMatch> matches) {
118 // return matches.where((SearchMatch match) {
119 // String name = match.element.displayName;
120 // return regExp.hasMatch(name);
121 // }).toList();
122 // });
116 } 123 }
117 124
118 Future<List<SearchMatch>> _searchReferences(Element element) { 125 Future<List<SearchMatch>> _searchReferences(Element element) {
119 _Requestor requestor = new _Requestor(_index); 126 _Requestor requestor = new _Requestor(_index);
120 requestor.add( 127 requestor.add(
121 element, 128 element,
122 IndexConstants.IS_REFERENCED_BY, 129 IndexConstants.IS_REFERENCED_BY,
123 MatchKind.REFERENCE); 130 MatchKind.REFERENCE);
124 return requestor.merge(); 131 return requestor.merge();
125 } 132 }
(...skipping 108 matching lines...) Expand 10 before | Expand all | Expand 10 after
234 }); 241 });
235 futures.add(matchesFuture); 242 futures.add(matchesFuture);
236 } 243 }
237 244
238 Future<List<SearchMatch>> merge() { 245 Future<List<SearchMatch>> merge() {
239 return Future.wait(futures).then((List<List<SearchMatch>> matchesList) { 246 return Future.wait(futures).then((List<List<SearchMatch>> matchesList) {
240 return matchesList.expand((matches) => matches).toList(); 247 return matchesList.expand((matches) => matches).toList();
241 }); 248 });
242 } 249 }
243 } 250 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698