[cost] fix enumerator when not used in for-each loop in ObjC

Summary:
In the previous diffs, we implement enumerator in order to estimate the cost of for-each loop in ObjC, but when we have FP case when enumerator is used not in for-each loop. For example, the following code has top cost before the fix.

```
void nsarray_enumerator_linear_FP(NSArray* array) {
  id obj;
  NSInteger sum = 0;

  NSEnumerator* enumerator = [array objectEnumerator];

  while (obj = [enumerator nextObject]) {
    sum += (NSInteger)obj;
  }
}
```

Reviewed By: skcho

Differential Revision: D23294895

fbshipit-source-id: 50c7b359f
master
Qianyi Shu 4 years ago committed by Facebook GitHub Bot
parent 87ff05c9b8
commit 41f2533ff8

@ -1193,7 +1193,7 @@ module AliasMap = struct
| AliasTarget.Simple {i} when IntLit.iszero i && Loc.is_frontend_tmp rhs ->
add_alias ~lhs:(KeyLhs.of_id id) ~rhs:l (AliasTarget.Simple {i; java_tmp= Some rhs}) acc
|> add_alias ~lhs:(KeyLhs.of_loc rhs) ~rhs:l (AliasTarget.Simple {i; java_tmp= None})
| AliasTarget.IteratorNextObject _ ->
| AliasTarget.IteratorNextObject _ | AliasTarget.IteratorSimple _ ->
add_alias ~lhs:(KeyLhs.of_loc l) ~rhs tgt acc
| _ ->
acc

@ -152,7 +152,7 @@ void nsarray_iterate_linear(NSArray* array) {
}
}
void nsarray_enumerator_linear_FP(NSArray* array) {
void nsarray_enumerator_linear(NSArray* array) {
NSEnumerator* enumerator = [array objectEnumerator];
id obj;

@ -7,7 +7,7 @@ codetoanalyze/objc/performance/NSArray.m, nsarray_binary_search_log_FN, 10, OnU
codetoanalyze/objc/performance/NSArray.m, nsarray_contains_object_linear, 3 + array->elements.length.ub, OnUIThread:false, [{array->elements.length.ub},Modeled call to NSArray.containsObject:]
codetoanalyze/objc/performance/NSArray.m, nsarray_count_bounded_linear, 3 + 3 ⋅ array->elements.length.ub + 3 ⋅ (array->elements.length.ub + 1), OnUIThread:false, [{array->elements.length.ub + 1},Loop,{array->elements.length.ub},Loop]
codetoanalyze/objc/performance/NSArray.m, nsarray_empty_array_constant, 8, OnUIThread:false, []
codetoanalyze/objc/performance/NSArray.m, nsarray_enumerator_linear_FP, , OnUIThread:false, [Unbounded loop,Loop]
codetoanalyze/objc/performance/NSArray.m, nsarray_enumerator_linear, 6 + 4 ⋅ array->elements.length.ub + 4 ⋅ (array->elements.length.ub + 1), OnUIThread:false, [{array->elements.length.ub + 1},Loop,{array->elements.length.ub},Loop]
codetoanalyze/objc/performance/NSArray.m, nsarray_find_linear, 4 + 9 ⋅ array->elements.length.ub + 3 ⋅ (array->elements.length.ub + 1), OnUIThread:false, [{array->elements.length.ub + 1},Loop,{array->elements.length.ub},Loop]
codetoanalyze/objc/performance/NSArray.m, nsarray_first_object_constant, 4, OnUIThread:false, []
codetoanalyze/objc/performance/NSArray.m, nsarray_get_first_constant, 27, OnUIThread:false, []

@ -1,5 +1,4 @@
codetoanalyze/objc/performance/NSArray.m, nsarray_empty_array_constant, 3, CONDITION_ALWAYS_FALSE, no_bucket, WARNING, [Here]
codetoanalyze/objc/performance/NSArray.m, nsarray_enumerator_linear_FP, 0, INFINITE_EXECUTION_TIME, no_bucket, ERROR, [Unbounded loop,Loop]
codetoanalyze/objc/performance/NSArray.m, nsarray_init_constant, 3, CONDITION_ALWAYS_FALSE, no_bucket, WARNING, [Here]
codetoanalyze/objc/performance/NSDictionary.m, nsdictionary_init_with_dictionary_linear_FP, 0, INFINITE_EXECUTION_TIME, no_bucket, ERROR, [Unbounded loop,Loop]
codetoanalyze/objc/performance/NSDictionary.m, nsdictionary_init_with_dictionary_linear_FP, 2, INTEGER_OVERFLOW_U5, no_bucket, ERROR, [<LHS trace>,Unknown value from: NSDictionary.initWithDictionary:,Binary operation: ([0, +oo] + 1):signed32]

Loading…
Cancel
Save