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

Side by Side Diff: pkg/analysis_server/lib/src/computer/computer_navigation.dart

Issue 366463002: Change Maps to HashMaps to save in performance, index and generated directories not touched (Closed) Base URL: https://dart.googlecode.com/svn/branches/bleeding_edge/dart
Patch Set: Created 6 years, 5 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 computer.navigation; 5 library computer.navigation;
6 6
7 import 'dart:collection';
8
7 import 'package:analysis_server/src/constants.dart'; 9 import 'package:analysis_server/src/constants.dart';
8 import 'package:analyzer/src/generated/ast.dart'; 10 import 'package:analyzer/src/generated/ast.dart';
9 import 'package:analyzer/src/generated/element.dart'; 11 import 'package:analyzer/src/generated/element.dart';
10 import 'package:analyzer/src/generated/scanner.dart'; 12 import 'package:analyzer/src/generated/scanner.dart';
11 import 'package:analyzer/src/generated/source.dart'; 13 import 'package:analyzer/src/generated/source.dart';
12 14
13 import 'element.dart' as computer; 15 import 'element.dart' as computer;
14 16
15 17
16 /** 18 /**
17 * A computer for navigation regions in a Dart [CompilationUnit]. 19 * A computer for navigation regions in a Dart [CompilationUnit].
18 */ 20 */
19 class DartUnitNavigationComputer { 21 class DartUnitNavigationComputer {
20 final CompilationUnit _unit; 22 final CompilationUnit _unit;
21 23
22 final List<Map<String, Object>> _regions = <Map<String, Object>>[]; 24 final List<HashMap<String, Object>> _regions = <HashMap<String, Object>>[];
23 25
24 DartUnitNavigationComputer(this._unit); 26 DartUnitNavigationComputer(this._unit);
25 27
26 /** 28 /**
27 * Returns the computed navigation regions, not `null`. 29 * Returns the computed navigation regions, not `null`.
28 */ 30 */
29 List<Map<String, Object>> compute() { 31 List<HashMap<String, Object>> compute() {
30 _unit.accept(new _DartUnitNavigationComputerVisitor(this)); 32 _unit.accept(new _DartUnitNavigationComputerVisitor(this));
31 return new List.from(_regions); 33 return new List.from(_regions);
32 } 34 }
33 35
34 void _addRegion(int offset, int length, Element element) { 36 void _addRegion(int offset, int length, Element element) {
35 Map<String, Object> target = _createTarget(element); 37 HashMap<String, Object> target = _createTarget(element);
36 if (target == null) { 38 if (target == null) {
37 return; 39 return;
38 } 40 }
39 _regions.add({ 41 _regions.add({
40 OFFSET: offset, 42 OFFSET: offset,
41 LENGTH: length, 43 LENGTH: length,
42 TARGETS: [target] 44 TARGETS: [target]
43 }); 45 });
44 } 46 }
45 47
(...skipping 23 matching lines...) Expand all
69 71
70 void _addRegion_tokenStart_nodeEnd(Token a, AstNode b, Element element) { 72 void _addRegion_tokenStart_nodeEnd(Token a, AstNode b, Element element) {
71 int offset = a.offset; 73 int offset = a.offset;
72 int length = b.end - offset; 74 int length = b.end - offset;
73 _addRegion(offset, length, element); 75 _addRegion(offset, length, element);
74 } 76 }
75 77
76 /** 78 /**
77 * Returns the JSON for the given [Element], maybe `null` if `null` was given. 79 * Returns the JSON for the given [Element], maybe `null` if `null` was given.
78 */ 80 */
79 Map<String, Object> _createTarget(Element element) { 81 HashMap<String, Object> _createTarget(Element element) {
80 if (element == null) { 82 if (element == null) {
81 return null; 83 return null;
82 } 84 }
83 if (element is FieldFormalParameterElement) { 85 if (element is FieldFormalParameterElement) {
84 element = (element as FieldFormalParameterElement).field; 86 element = (element as FieldFormalParameterElement).field;
85 } 87 }
86 // prepare Source 88 // prepare Source
87 Source source = element.source; 89 Source source = element.source;
88 if (source == null) { 90 if (source == null) {
89 return null; 91 return null;
(...skipping 115 matching lines...) Expand 10 before | Expand all | Expand 10 after
205 207
206 @override 208 @override
207 visitSimpleIdentifier(SimpleIdentifier node) { 209 visitSimpleIdentifier(SimpleIdentifier node) {
208 if (node.parent is ConstructorDeclaration) { 210 if (node.parent is ConstructorDeclaration) {
209 } else { 211 } else {
210 computer._addRegionForNode(node, node.bestElement); 212 computer._addRegionForNode(node, node.bestElement);
211 } 213 }
212 return super.visitSimpleIdentifier(node); 214 return super.visitSimpleIdentifier(node);
213 } 215 }
214 } 216 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698