mirror of
https://github.com/dart-lang/sdk
synced 2024-09-20 12:31:18 +00:00
Convert null-marker in HashMap.forEach.
R=johnniwinther@google.com Review URL: https://codereview.chromium.org//22561003 git-svn-id: https://dart.googlecode.com/svn/branches/bleeding_edge/dart@25925 260f80e4-7a28-3924-810f-c04153c831b5
This commit is contained in:
parent
dd7d7f5012
commit
57f68eeb94
|
@ -94,7 +94,7 @@ patch class HashMap<K, V> {
|
|||
for (int offset = 0; offset < table.length; offset += entrySize) {
|
||||
Object entry = table[offset];
|
||||
if (!_hashTable._isFree(entry)) {
|
||||
K key = entry;
|
||||
K key = identical(entry, _NULL) ? null : entry;
|
||||
V value = _hashTable._value(offset);
|
||||
action(key, value);
|
||||
_hashTable._checkModification(modificationCount);
|
||||
|
|
19
tests/language/hash_map_null_key_foreach_test.dart
Normal file
19
tests/language/hash_map_null_key_foreach_test.dart
Normal file
|
@ -0,0 +1,19 @@
|
|||
// Copyright (c) 2013, the Dart project authors. Please see the AUTHORS file
|
||||
// for details. All rights reserved. Use of this source code is governed by a
|
||||
// BSD-style license that can be found in the LICENSE file.
|
||||
|
||||
import "package:expect/expect.dart";
|
||||
|
||||
// Regression test for using `null` as a key with `forEach`.
|
||||
|
||||
main() {
|
||||
var x = new Map<int, int>();
|
||||
x[1] = 2;
|
||||
x[null] = 1;
|
||||
int c = 0;
|
||||
x.forEach((int i, int j) {
|
||||
c++;
|
||||
Expect.isTrue(i == null || i is int, 'int or null expected');
|
||||
});
|
||||
Expect.equals(2, c);
|
||||
}
|
Loading…
Reference in a new issue