You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
104 lines
2.5 KiB
104 lines
2.5 KiB
/*
|
|
* 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 android.os.Bundle;
|
|
import androidx.collection.ArrayMap;
|
|
import java.util.HashMap;
|
|
import java.util.Iterator;
|
|
import java.util.Map;
|
|
import java.util.Set;
|
|
|
|
class Test {
|
|
|
|
void inefficient_loop_bad(HashMap<String, Integer> testMap) {
|
|
for (String key : testMap.keySet()) {
|
|
testMap.get(key);
|
|
}
|
|
}
|
|
|
|
void inefficient_loop_itr_bad(HashMap<String, Integer> testMap) {
|
|
|
|
Iterator itr2 = testMap.keySet().iterator();
|
|
while (itr2.hasNext()) {
|
|
String key = (String) itr2.next();
|
|
testMap.get(key);
|
|
}
|
|
}
|
|
|
|
void inefficient_loop_itr_heur_bad_FN(HashMap<String, Integer> testMap) {
|
|
|
|
Iterator itr2 = testMap.keySet().iterator();
|
|
int i = 0;
|
|
int j = 1;
|
|
int k = 2;
|
|
int l = 3;
|
|
while (itr2.hasNext()) {
|
|
String key = (String) itr2.next();
|
|
testMap.get(key);
|
|
}
|
|
}
|
|
|
|
void inefficient_loop_itr_heur_bad(HashMap<String, Integer> testMap) {
|
|
|
|
Iterator itr2 = testMap.keySet().iterator();
|
|
int i = 0;
|
|
while (itr2.hasNext()) {
|
|
String key = (String) itr2.next();
|
|
testMap.get(key);
|
|
}
|
|
}
|
|
|
|
void inefficient_loop_itr_heur_btw_bad(HashMap<String, Integer> testMap) {
|
|
|
|
Set<String> keySet = testMap.keySet();
|
|
int i = 0;
|
|
int j = 1;
|
|
int l = 3;
|
|
Iterator itr2 = keySet.iterator();
|
|
while (itr2.hasNext()) {
|
|
String key = (String) itr2.next();
|
|
testMap.get(key);
|
|
}
|
|
}
|
|
|
|
void efficient_loop_itr_ok(HashMap<String, Integer> testMap) {
|
|
|
|
Iterator<Map.Entry<String, Integer>> itr1 = testMap.entrySet().iterator();
|
|
while (itr1.hasNext()) {
|
|
Map.Entry<String, Integer> entry = itr1.next();
|
|
entry.getKey();
|
|
entry.getValue();
|
|
}
|
|
}
|
|
|
|
void efficient_loop_ok(HashMap<String, Integer> testMap) {
|
|
for (Map.Entry<String, Integer> entry : testMap.entrySet()) {
|
|
entry.getKey();
|
|
entry.getValue();
|
|
}
|
|
}
|
|
|
|
void negative_loop_ok(HashMap<String, Integer> testMap1, HashMap<String, Integer> testMap2) {
|
|
for (String key : testMap1.keySet()) {
|
|
testMap2.get(key);
|
|
}
|
|
}
|
|
|
|
// Bundle doesn't implement Map hence have any entrySet
|
|
public void from_bundle_ok(Bundle extras) {
|
|
for (String key : extras.keySet()) {
|
|
Object t = extras.get(key);
|
|
}
|
|
}
|
|
|
|
// ArrayMap extends SimpleMap.
|
|
void inefficient_arraymap_loop_bad(ArrayMap<String, Integer> arrayMap) {
|
|
for (String key : arrayMap.keySet()) {
|
|
arrayMap.get(key);
|
|
}
|
|
}
|
|
}
|