| OLD | NEW |
| 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.index.store.codec; | 5 library services.src.index.store.codec; |
| 6 | 6 |
| 7 import 'dart:collection'; | 7 import 'dart:collection'; |
| 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/index/store/collection.dart'; | 10 import 'package:analysis_server/src/services/index/store/collection.dart'; |
| (...skipping 86 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 97 return context.getElement(location); | 97 return context.getElement(location); |
| 98 } | 98 } |
| 99 | 99 |
| 100 /** | 100 /** |
| 101 * Returns a unique integer that corresponds to the given [Element]. | 101 * Returns a unique integer that corresponds to the given [Element]. |
| 102 * | 102 * |
| 103 * If [forKey] is `true` then [element] is a part of a key, so it should use | 103 * If [forKey] is `true` then [element] is a part of a key, so it should use |
| 104 * file paths instead of [Element] location URIs. | 104 * file paths instead of [Element] location URIs. |
| 105 */ | 105 */ |
| 106 int encode(Element element, bool forKey) { | 106 int encode(Element element, bool forKey) { |
| 107 if (element is NameElement) { |
| 108 String name = element.name; |
| 109 int nameId = _stringCodec.encode(name); |
| 110 return _encodePath(<int>[nameId]); |
| 111 } |
| 112 // check the location has a cached id |
| 107 ElementLocationImpl location = element.location; | 113 ElementLocationImpl location = element.location; |
| 108 // check the location has a cached id | |
| 109 if (!identical(location.indexOwner, this)) { | 114 if (!identical(location.indexOwner, this)) { |
| 110 location.indexKeyId = null; | 115 location.indexKeyId = null; |
| 111 location.indexLocationId = null; | 116 location.indexLocationId = null; |
| 112 } | 117 } |
| 113 if (forKey) { | 118 if (forKey) { |
| 114 int id = location.indexKeyId; | 119 int id = location.indexKeyId; |
| 115 if (id != null) { | 120 if (id != null) { |
| 116 return id; | 121 return id; |
| 117 } | 122 } |
| 118 } else { | 123 } else { |
| (...skipping 188 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 307 int encode(String name) { | 312 int encode(String name) { |
| 308 int index = nameToIndex[name]; | 313 int index = nameToIndex[name]; |
| 309 if (index == null) { | 314 if (index == null) { |
| 310 index = _indexToName.length; | 315 index = _indexToName.length; |
| 311 nameToIndex[name] = index; | 316 nameToIndex[name] = index; |
| 312 _indexToName.add(name); | 317 _indexToName.add(name); |
| 313 } | 318 } |
| 314 return index; | 319 return index; |
| 315 } | 320 } |
| 316 } | 321 } |
| OLD | NEW |