[inefficient-keyset-iterator] Add documentation

Reviewed By: ngorogiannis

Differential Revision: D22046100

fbshipit-source-id: 71954ce49
master
Ezgi Çiçek 5 years ago committed by Facebook GitHub Bot
parent 2a168991be
commit b491492796

@ -0,0 +1,26 @@
This issue is raised when
- iterating over a HashMap with `ketSet()` iterator
- looking up the key each time
Instead, it is more efficient to iterate over the loop with `entrySet` which returns key-vaue pairs and gets rid of the hashMap lookup.
For instance, we would raise an issue for the following program:
```java
void inefficient_loop_bad(HashMap<String, Integer> testMap) {
for (String key : testMap.keySet()) {
Integer value = testMap.get(key); // extra look-up cost
foo(key, value);
}
}
```
Instead, it is more efficient to have:
```java
void efficient_loop_ok(HashMap<String, Integer> testMap) {
for (Map.Entry<String, Integer> entry : testMap.entrySet()) {
String key = entry.getKey();
Integer value = entry.getValue();
foo(key, value);
}
}
```

@ -633,6 +633,7 @@ let impure_function = register_from_string ~id:"IMPURE_FUNCTION" Error Impurity
let inefficient_keyset_iterator =
register_from_string ~id:"INEFFICIENT_KEYSET_ITERATOR" Error InefficientKeysetIterator
~user_documentation:[%blob "../../documentation/issues/INEFFICIENT_KEYSET_ITERATOR.md"]
let inferbo_alloc_is_big =

Loading…
Cancel
Save