[cost] Add model for ImmutableSet.of

Reviewed By: skcho

Differential Revision: D22411208

fbshipit-source-id: 55f462cd9
master
Ezgi Çiçek 5 years ago committed by Facebook GitHub Bot
parent 05f1d1676e
commit be590bcd4c

@ -886,6 +886,15 @@ module Collection = struct
{exec; check= no_check}
let of_list list =
let exec env ~ret:((id, _) as ret) mem =
let mem = new_collection.exec env ~ret mem in
List.fold_left list ~init:mem ~f:(fun acc {exp= elem_exp} ->
(add id elem_exp).exec env ~ret acc )
in
{exec; check= no_check}
let singleton_collection =
let exec env ~ret:((id, _) as ret) mem =
let {exec= new_exec; check= _} = new_collection in
@ -1576,6 +1585,8 @@ module Call = struct
; +PatternMatch.implements_collections
&:: "singletonMap" <>--> Collection.singleton_collection
; +PatternMatch.implements_collections &::+ unmodifiable <>$ capt_exp $--> Collection.iterator
; +PatternMatch.implements_google "common.collect.ImmutableSet"
&:: "of" &++> Collection.of_list
; +PatternMatch.implements_google "common.base.Preconditions"
&:: "checkArgument" <>$ capt_exp $+...$--> Preconditions.check_argument
; +PatternMatch.implements_google "common.base.Preconditions"

@ -6,6 +6,7 @@
*/
import android.util.SparseArray;
import com.google.common.collect.ImmutableSet;
import java.util.Collection;
import java.util.concurrent.ConcurrentLinkedQueue;
@ -89,4 +90,16 @@ public class CollectionTest {
}
};
}
void immutable_set_of_constant() {
ImmutableSet<Integer> set = ImmutableSet.of();
for (int i = 0; i < set.size(); i++) {}
}
void immutable_set_of_multiple_constant() {
ImmutableSet<Integer> set = ImmutableSet.of(1, 2, 3, 4, 5);
for (int i = 0; i < set.size(); i++) {}
}
}

@ -91,6 +91,8 @@ codetoanalyze/java/performance/CollectionTest.java, CollectionTest$MyEnumType.va
codetoanalyze/java/performance/CollectionTest.java, CollectionTest$MyEnumType.values():CollectionTest$MyEnumType[], 7, OnUIThread:false, []
codetoanalyze/java/performance/CollectionTest.java, CollectionTest.<init>(), 3, OnUIThread:false, []
codetoanalyze/java/performance/CollectionTest.java, CollectionTest.ensure_call(CollectionTest$MyCollection):void, 11 + 5 ⋅ list.length, OnUIThread:false, [{list.length},Call to void CollectionTest.iterate_over_mycollection(CollectionTest$MyCollection),Loop]
codetoanalyze/java/performance/CollectionTest.java, CollectionTest.immutable_set_of_constant():void, 10, OnUIThread:false, []
codetoanalyze/java/performance/CollectionTest.java, CollectionTest.immutable_set_of_multiple_constant():void, 65, OnUIThread:false, []
codetoanalyze/java/performance/CollectionTest.java, CollectionTest.iterate_over_call_quad(int,CollectionTest$MyCollection):void, 6 + 18 ⋅ list.length + 5 ⋅ list.length × list.length + 3 ⋅ (list.length + 1), OnUIThread:false, [{list.length + 1},Loop,{list.length},Call to void CollectionTest.iterate_over_mycollection(CollectionTest$MyCollection),Loop,{list.length},Loop]
codetoanalyze/java/performance/CollectionTest.java, CollectionTest.iterate_over_mycollection(CollectionTest$MyCollection):void, 8 + 5 ⋅ list.length, OnUIThread:false, [{list.length},Loop]
codetoanalyze/java/performance/CollectionTest.java, CollectionTest.iterate_over_mycollection_quad(java.util.concurrent.ConcurrentLinkedQueue):void, 6 + 18 ⋅ mSubscribers.length + 5 ⋅ mSubscribers.length × mSubscribers.elements.*.length.ub + 3 ⋅ (mSubscribers.length + 1), OnUIThread:false, [{mSubscribers.length + 1},Loop,{mSubscribers.elements.*.length.ub},Call to void CollectionTest.iterate_over_mycollection(CollectionTest$MyCollection),Loop,{mSubscribers.length},Loop]

@ -20,6 +20,7 @@ codetoanalyze/java/performance/CantHandle.java, CantHandle.square_root_variant_F
codetoanalyze/java/performance/CantHandle.java, CantHandle.square_root_variant_FP(int):void, 3, INTEGER_OVERFLOW_L5, no_bucket, ERROR, [<LHS trace>,Parameter `x`,Binary operation: ([0, +oo] + 1):signed32]
codetoanalyze/java/performance/CollectionTest.java, CollectionTest$MyEnumType$1.<init>(), 4, INTEGER_OVERFLOW_L5, no_bucket, ERROR, [<LHS trace>,Assignment,Binary operation: ([0, +oo] + 1):signed32]
codetoanalyze/java/performance/CollectionTest.java, CollectionTest$MyEnumType.<clinit>():void, 0, INFINITE_EXECUTION_TIME, no_bucket, ERROR, [Call to CollectionTest$MyEnumType$1.<init>(),Unbounded loop,Loop]
codetoanalyze/java/performance/CollectionTest.java, CollectionTest.immutable_set_of_constant():void, 3, CONDITION_ALWAYS_FALSE, no_bucket, WARNING, [Here]
codetoanalyze/java/performance/CollectionsTest.java, CollectionsTest.emptyList_constant():void, 1, CONDITION_ALWAYS_FALSE, no_bucket, WARNING, [Here]
codetoanalyze/java/performance/CollectionsTest.java, CollectionsTest.emptySet_constant():void, 2, CONDITION_ALWAYS_FALSE, no_bucket, WARNING, [Here]
codetoanalyze/java/performance/CollectionsTest.java, CollectionsTest.globalEmptyList_constant():void, 1, CONDITION_ALWAYS_FALSE, no_bucket, WARNING, [Here]

Loading…
Cancel
Save