/* * 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.util.SparseArray; import java.util.Collection; import java.util.concurrent.ConcurrentLinkedQueue; public class CollectionTest { interface MyCollection extends Collection {} void iterate_over_mycollection(MyCollection list) { for (int i = 0, size = list.size(); i < size; ++i) {} } void iterate_over_some_java_collection( ConcurrentLinkedQueue> mSubscribers) { for (MyCollection list : mSubscribers) {} } // Expected |mSubscribers| * |list| but we get |mSubscribers| // because we are not tracking elements of collections void iterate_over_mycollection_quad_FN( ConcurrentLinkedQueue> mSubscribers) { for (MyCollection list : mSubscribers) { iterate_over_mycollection(list); } } // expected: same as iterate_over_mycollection(list) void ensure_call(MyCollection list) { iterate_over_mycollection(list); } // expected: O (|size| . |list|) void loop_over_call(int size, MyCollection list) { for (int i = 0; i < size; i++) { iterate_over_mycollection(list); } } // expected: O (|list|^2) void iterate_over_call_quad(int size, MyCollection list) { for (Integer i : list) { iterate_over_mycollection(list); } } // expected O (|list|^3) void nested_iterator_qubic(int size, MyCollection list1, MyCollection list2) { for (Integer i : list1) { for (Integer j : list2) { iterate_over_mycollection(list1); iterate_over_mycollection(list1); } } } void sparse_array_linear(SparseArray arr) { for (int i = 0; i < arr.size(); i++) {} } void sparse_array_new_constant() { SparseArray new_arr = new SparseArray(); new_arr.put(1, 1); for (int i = 0; i < new_arr.size(); i++) {} } static class Dummy {} public enum MyEnumType { /* The elements of enum is initialized in ``. */ A(1); public final int mValue; private MyEnumType(int i) { mValue = i; } /* This field is also initialized in ``, in which `` is called. */ private static Dummy s = new Dummy() { { /* This loop is in `` function. It needs the results of `` in order to get `MyEnumType.values()`. */ for (MyEnumType type : MyEnumType.values()) {} } }; } }