|
|
|
/*
|
|
|
|
* Copyright (c) Facebook, Inc. and its affiliates.
|
|
|
|
*
|
|
|
|
* This source code is licensed under the MIT license found in the
|
|
|
|
* LICENSE file in the root directory of this source tree.
|
|
|
|
*/
|
|
|
|
|
|
|
|
import java.util.Map;
|
|
|
|
|
|
|
|
class SlowIterTests {
|
|
|
|
static <K, V> void aBad(Map<K, V> m) {
|
|
|
|
for (K k : m.keySet()) {
|
|
|
|
System.out.printf("%s -> %s\n", k, m.get(k));
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
static <K, V> void aOk(Map<K, V> m) {
|
|
|
|
for (Map.Entry<K, V> e : m.entrySet()) {
|
|
|
|
System.out.printf("%s -> %s\n", e.getKey(), e.getValue());
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
// Inter-procedural variant of aBad.
|
|
|
|
static <K, V> void bBad(Map<K, V> m) {
|
|
|
|
for (K k : m.keySet()) {
|
|
|
|
print(k, m);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
static <K, V> void print(K k, Map<K, V> m) {
|
|
|
|
System.out.printf("%s -> %s\n", k, m.get(k));
|
|
|
|
}
|
|
|
|
}
|