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

Side by Side Diff: runtime/lib/expando_patch.dart

Issue 24556002: Make VM Expando use identityHashCode instead of object's hashCode. (Closed) Base URL: https://dart.googlecode.com/svn/branches/bleeding_edge/dart
Patch Set: Created 7 years, 2 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
« no previous file with comments | « no previous file | tests/corelib/expando_test.dart » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 // Copyright (c) 2012, the Dart project authors. Please see the AUTHORS file 1 // Copyright (c) 2012, 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 patch class Expando<T> { 5 patch class Expando<T> {
6 /* patch */ Expando([String this.name]) 6 /* patch */ Expando([String this.name])
7 : _data = new List(_minSize), 7 : _data = new List(_minSize),
8 _used = 0; 8 _used = 0;
9 9
10 static const _minSize = 8; 10 static const _minSize = 8;
11 static final _deletedEntry = new _WeakProperty(null, null); 11 static final _deletedEntry = new _WeakProperty(null, null);
12 12
13 /* patch */ T operator[](Object object) { 13 /* patch */ T operator[](Object object) {
14 _checkType(object); 14 _checkType(object);
15 15
16 var mask = _size - 1; 16 var mask = _size - 1;
17 var idx = object.hashCode & mask; 17 var idx = object._identityHashCode & mask;
18 var wp = _data[idx]; 18 var wp = _data[idx];
19 19
20 while (wp != null) { 20 while (wp != null) {
21 if (identical(wp.key, object)) { 21 if (identical(wp.key, object)) {
22 return wp.value; 22 return wp.value;
23 } else if (wp.key == null) { 23 } else if (wp.key == null) {
24 // This entry has been cleared by the GC. 24 // This entry has been cleared by the GC.
25 _data[idx] = _deletedEntry; 25 _data[idx] = _deletedEntry;
26 } 26 }
27 idx = (idx + 1) & mask; 27 idx = (idx + 1) & mask;
28 wp = _data[idx]; 28 wp = _data[idx];
29 } 29 }
30 30
31 return null; 31 return null;
32 } 32 }
33 33
34 /* patch */ void operator[]=(Object object, T value) { 34 /* patch */ void operator[]=(Object object, T value) {
35 _checkType(object); 35 _checkType(object);
36 36
37 var mask = _size - 1; 37 var mask = _size - 1;
38 var idx = object.hashCode & mask; 38 var idx = object._identityHashCode & mask;
39 var empty_idx = -1; 39 var empty_idx = -1;
40 var wp = _data[idx]; 40 var wp = _data[idx];
41 41
42 while (wp != null) { 42 while (wp != null) {
43 if (identical(wp.key, object)) { 43 if (identical(wp.key, object)) {
44 if (value != null) { 44 if (value != null) {
45 // Update the associated value. 45 // Update the associated value.
46 wp.value = value; 46 wp.value = value;
47 } else { 47 } else {
48 // Mark the entry as deleted. 48 // Mark the entry as deleted.
49 _data[idx] = _deletedEntry; 49 _data[idx] = _deletedEntry;
50 } 50 }
51 return; 51 return;
52 } else if ((empty_idx < 0) && identical(wp, _deletedEntry)) { 52 } else if ((empty_idx < 0) && identical(wp, _deletedEntry)) {
53 empty_idx = idx; // Insert at this location if not found. 53 empty_idx = idx; // Insert at this location if not found.
54 } else if (wp.key == null) { 54 } else if (wp.key == null) {
55 // This entry has been cleared by the GC. 55 // This entry has been cleared by the GC.
56 _data[idx] = _deletedEntry; 56 _data[idx] = _deletedEntry;
57 if (empty_idx < 0) { 57 if (empty_idx < 0) {
58 empty_idx = idx; // Insert at this location if not found. 58 empty_idx = idx; // Insert at this location if not found.
59 } 59 }
60 } 60 }
61 idx = (idx + 1) & mask; 61 idx = (idx + 1) & mask;
62 wp = _data[idx]; 62 wp = _data[idx];
63 } 63 }
64 64
65 if (value == null) { 65 if (value == null) {
66 // Not entering a null value. We just needed to make sure to clear an 66 // Not entering a null value. We just needed to make sure to clear an
67 // existing value if it existed. 67 // existing value if it existed.
68 return; 68 return;
69 } 69 }
70 70
71 if (empty_idx >= 0) { 71 if (empty_idx >= 0) {
72 // We will be reusing the empty slot below. 72 // We will be reusing the empty slot below.
73 _used--; 73 _used--;
74 idx = empty_idx; 74 idx = empty_idx;
75 } 75 }
76 76
77 if (_used < _limit) { 77 if (_used < _limit) {
(...skipping 56 matching lines...) Expand 10 before | Expand all | Expand 10 after
134 throw new ArgumentError(object); 134 throw new ArgumentError(object);
135 } 135 }
136 } 136 }
137 137
138 get _size => _data.length; 138 get _size => _data.length;
139 get _limit => (3 * (_size ~/ 4)); 139 get _limit => (3 * (_size ~/ 4));
140 140
141 List _data; 141 List _data;
142 int _used; // Number of used (active and deleted) slots. 142 int _used; // Number of used (active and deleted) slots.
143 } 143 }
OLDNEW
« no previous file with comments | « no previous file | tests/corelib/expando_test.dart » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698