Use a HashSet to store delegate references in layoutlib

More efficient than an ArrayList since we do a lot of remove operations.

Change-Id: Ic4c89df4560066f1a3ab0e71a3b180a9734f9cd6
(cherry picked from commit 12754d621b20e6a925999096ab6f21c4cbfe594a)
diff --git a/bridge/src/com/android/layoutlib/bridge/impl/DelegateManager.java b/bridge/src/com/android/layoutlib/bridge/impl/DelegateManager.java
index c59b1a6..0c39026 100644
--- a/bridge/src/com/android/layoutlib/bridge/impl/DelegateManager.java
+++ b/bridge/src/com/android/layoutlib/bridge/impl/DelegateManager.java
@@ -24,8 +24,8 @@
 
 import java.io.PrintStream;
 import java.lang.ref.WeakReference;
-import java.util.ArrayList;
-import java.util.List;
+import java.util.HashSet;
+import java.util.Set;
 import java.util.concurrent.atomic.AtomicLong;
 
 /**
@@ -33,7 +33,7 @@
  *
  * This is used in conjunction with layoublib_create: certain Android java classes are mere
  * wrappers around a heavily native based implementation, and we need a way to run these classes
- * in our Eclipse rendering framework without bringing all the native code from the Android
+ * in our Android Studio rendering framework without bringing all the native code from the Android
  * platform.
  *
  * Thus we instruct layoutlib_create to modify the bytecode of these classes to replace their
@@ -61,7 +61,7 @@
  * following mechanism:
  *
  * - {@link #addNewDelegate(Object)} and {@link #removeJavaReferenceFor(long)} adds and removes
- *   the delegate to/from a list. This list hold the reference and prevents the GC from reclaiming
+ *   the delegate to/from a set. This set holds the reference and prevents the GC from reclaiming
  *   the delegate.
  *
  * - {@link #addNewDelegate(Object)} also adds the delegate to a {@link SparseArray} that holds a
@@ -76,12 +76,12 @@
     @SuppressWarnings("FieldCanBeLocal")
     private final Class<T> mClass;
     private static final SparseWeakArray<Object> sDelegates = new SparseWeakArray<>();
-    /** list used to store delegates when their main object holds a reference to them.
+    /** Set used to store delegates when their main object holds a reference to them.
      * This is to ensure that the WeakReference in the SparseWeakArray doesn't get GC'ed
      * @see #addNewDelegate(Object)
      * @see #removeJavaReferenceFor(long)
      */
-    private static final List<Object> sJavaReferences = new ArrayList<>();
+    private static final Set<Object> sJavaReferences = new HashSet<>();
     private static final AtomicLong sDelegateCounter = new AtomicLong(1);
 
     public DelegateManager(Class<T> theClass) {