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

Side by Side Diff: pkg/analysis_server/lib/src/index/split_store.dart

Issue 347133002: Explicitly remove AnalysisContext from ContextCodec. (Closed) Base URL: https://dart.googlecode.com/svn/branches/bleeding_edge/dart
Patch Set: Fix for IDs generation Created 6 years, 6 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 index.split.store; 5 library index.split.store;
6 6
7 import 'dart:async'; 7 import 'dart:async';
8 import 'dart:collection'; 8 import 'dart:collection';
9 import 'dart:io'; 9 import 'dart:io';
10 import 'dart:typed_data'; 10 import 'dart:typed_data';
(...skipping 17 matching lines...) Expand all
28 Map<AnalysisContext, int> _contextToIndex = new HashMap<AnalysisContext, int>( 28 Map<AnalysisContext, int> _contextToIndex = new HashMap<AnalysisContext, int>(
29 ); 29 );
30 30
31 /** 31 /**
32 * A table mapping indices to the corresponding contexts. 32 * A table mapping indices to the corresponding contexts.
33 */ 33 */
34 Map<int, AnalysisContext> _indexToContext = new HashMap<int, AnalysisContext>( 34 Map<int, AnalysisContext> _indexToContext = new HashMap<int, AnalysisContext>(
35 ); 35 );
36 36
37 /** 37 /**
38 * The next id to assign.
39 */
40 int _nextId = 0;
41
42 /**
38 * Returns the [AnalysisContext] that corresponds to the given index. 43 * Returns the [AnalysisContext] that corresponds to the given index.
39 */ 44 */
40 AnalysisContext decode(int index) => _indexToContext[index]; 45 AnalysisContext decode(int index) => _indexToContext[index];
41 46
42 /** 47 /**
43 * Returns an unique index for the given [AnalysisContext]. 48 * Returns an unique index for the given [AnalysisContext].
44 */ 49 */
45 int encode(AnalysisContext context) { 50 int encode(AnalysisContext context) {
46 int index = _contextToIndex[context]; 51 int index = _contextToIndex[context];
47 if (index == null) { 52 if (index == null) {
48 index = _indexToContext.length; 53 index = _nextId++;
49 _contextToIndex[context] = index; 54 _contextToIndex[context] = index;
50 _indexToContext[index] = context; 55 _indexToContext[index] = context;
51 } 56 }
52 return index; 57 return index;
53 } 58 }
59
60 /**
61 * Removes the given [context].
62 */
63 void remove(AnalysisContext context) {
64 int id = _contextToIndex.remove(context);
65 if (id != null) {
66 _indexToContext.remove(id);
67 }
68 }
54 } 69 }
55 70
56 71
57 /** 72 /**
58 * A helper that encodes/decodes [Element]s to/from integers. 73 * A helper that encodes/decodes [Element]s to/from integers.
59 */ 74 */
60 class ElementCodec { 75 class ElementCodec {
61 /** 76 /**
62 * A list that works as a mapping of integers to element encodings (in form of integer arrays). 77 * A list that works as a mapping of integers to element encodings (in form of integer arrays).
63 */ 78 */
(...skipping 833 matching lines...) Expand 10 before | Expand all | Expand 10 after
897 context = _unwrapContext(context); 912 context = _unwrapContext(context);
898 if (context == null) { 913 if (context == null) {
899 return; 914 return;
900 } 915 }
901 // remove sources 916 // remove sources
902 removeSources(context, null); 917 removeSources(context, null);
903 // remove context information 918 // remove context information
904 _contextToLibraryToUnits.remove(context); 919 _contextToLibraryToUnits.remove(context);
905 _contextToUnitToLibraries.remove(context); 920 _contextToUnitToLibraries.remove(context);
906 _contextNodeRelations.remove(_contextCodec.encode(context)); 921 _contextNodeRelations.remove(_contextCodec.encode(context));
922 // remove context from codec
923 _contextCodec.remove(context);
907 } 924 }
908 925
909 @override 926 @override
910 void removeSource(AnalysisContext context, Source source) { 927 void removeSource(AnalysisContext context, Source source) {
911 context = _unwrapContext(context); 928 context = _unwrapContext(context);
912 if (context == null) { 929 if (context == null) {
913 return; 930 return;
914 } 931 }
915 // remove nodes for unit/library pairs 932 // remove nodes for unit/library pairs
916 Map<Source, Set<Source>> unitToLibraries = 933 Map<Source, Set<Source>> unitToLibraries =
(...skipping 224 matching lines...) Expand 10 before | Expand all | Expand 10 after
1141 return new Uint8List.fromList(_buffer.takeBytes()); 1158 return new Uint8List.fromList(_buffer.takeBytes());
1142 } 1159 }
1143 1160
1144 void writeInt(int value) { 1161 void writeInt(int value) {
1145 _buffer.addByte((value & 0xFF000000) >> 24); 1162 _buffer.addByte((value & 0xFF000000) >> 24);
1146 _buffer.addByte((value & 0x00FF0000) >> 16); 1163 _buffer.addByte((value & 0x00FF0000) >> 16);
1147 _buffer.addByte((value & 0x0000FF00) >> 8); 1164 _buffer.addByte((value & 0x0000FF00) >> 8);
1148 _buffer.addByte(value & 0xFF); 1165 _buffer.addByte(value & 0xFF);
1149 } 1166 }
1150 } 1167 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698