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

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

Issue 2278273003: VM: New, faster default Map construction. (Closed)
Patch Set: Created 4 years, 3 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
« no previous file with comments | « no previous file | runtime/lib/linked_hash_map.cc » ('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) 2015, the Dart project authors. Please see the AUTHORS file 1 // Copyright (c) 2015, 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 import 'dart:typed_data'; 5 import 'dart:typed_data';
6 import 'dart:_internal' as internal; 6 import 'dart:_internal' as internal;
7 7
8 // Hash table with open addressing that separates the index from keys/values. 8 // Hash table with open addressing that separates the index from keys/values.
9 9
10 abstract class _HashFieldBase { 10 abstract class _HashFieldBase {
(...skipping 105 matching lines...) Expand 10 before | Expand all | Expand 10 after
116 class _IdenticalAndIdentityHashCode { 116 class _IdenticalAndIdentityHashCode {
117 int _hashCode(e) => identityHashCode(e); 117 int _hashCode(e) => identityHashCode(e);
118 bool _equals(e1, e2) => identical(e1, e2); 118 bool _equals(e1, e2) => identical(e1, e2);
119 } 119 }
120 120
121 // VM-internalized implementation of a default-constructed LinkedHashMap. 121 // VM-internalized implementation of a default-constructed LinkedHashMap.
122 class _InternalLinkedHashMap<K, V> extends _HashVMBase 122 class _InternalLinkedHashMap<K, V> extends _HashVMBase
123 with MapMixin<K, V>, _LinkedHashMapMixin<K, V>, _HashBase, 123 with MapMixin<K, V>, _LinkedHashMapMixin<K, V>, _HashBase,
124 _OperatorEqualsAndHashCode 124 _OperatorEqualsAndHashCode
125 implements LinkedHashMap<K, V> { 125 implements LinkedHashMap<K, V> {
126 factory _InternalLinkedHashMap() native "LinkedHashMap_allocate"; 126 _InternalLinkedHashMap() {
sra1 2016/08/26 00:36:36 How about using initializers so that it is obvious
Florian Schneider 2016/08/26 00:40:32 Initializers only work with real fields, not with
127 _index = new Uint32List(_HashBase._INITIAL_INDEX_SIZE);
128 _hashMask = _HashBase._indexSizeToHashMask(_HashBase._INITIAL_INDEX_SIZE);
129 _data = new List(_HashBase._INITIAL_INDEX_SIZE);
130 _usedData = 0;
131 _deletedKeys = 0;
132 }
127 } 133 }
128 134
129 class _LinkedHashMapMixin<K, V> { 135 class _LinkedHashMapMixin<K, V> {
130 int get length => (_usedData >> 1) - _deletedKeys; 136 int get length => (_usedData >> 1) - _deletedKeys;
131 bool get isEmpty => length == 0; 137 bool get isEmpty => length == 0;
132 bool get isNotEmpty => !isEmpty; 138 bool get isNotEmpty => !isEmpty;
133 139
134 void _rehash() { 140 void _rehash() {
135 if ((_deletedKeys << 2) > _usedData) { 141 if ((_deletedKeys << 2) > _usedData) {
136 // TODO(koda): Consider shrinking. 142 // TODO(koda): Consider shrinking.
(...skipping 449 matching lines...) Expand 10 before | Expand all | Expand 10 after
586 E lookup(Object o) => _validKey(o) ? super.lookup(o) : null; 592 E lookup(Object o) => _validKey(o) ? super.lookup(o) : null;
587 bool remove(Object o) => _validKey(o) ? super.remove(o) : false; 593 bool remove(Object o) => _validKey(o) ? super.remove(o) : false;
588 594
589 _CompactLinkedCustomHashSet(this._equality, this._hasher, validKey) 595 _CompactLinkedCustomHashSet(this._equality, this._hasher, validKey)
590 : _validKey = (validKey != null) ? validKey : new _TypeTest<E>().test; 596 : _validKey = (validKey != null) ? validKey : new _TypeTest<E>().test;
591 597
592 Set<E> toSet() => 598 Set<E> toSet() =>
593 new _CompactLinkedCustomHashSet<E>(_equality, _hasher, _validKey) 599 new _CompactLinkedCustomHashSet<E>(_equality, _hasher, _validKey)
594 ..addAll(this); 600 ..addAll(this);
595 } 601 }
OLDNEW
« no previous file with comments | « no previous file | runtime/lib/linked_hash_map.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698