Przeglądaj źródła

Merge pull request #1381 from dotnet/dev/bartde/immutable_list_indexof

Use Array.IndexOf for better perf
Bart J.F. De Smet 5 lat temu
rodzic
commit
c0b7c7a469

+ 3 - 22
Rx.NET/Source/src/System.Reactive/Internal/ImmutableList.cs

@@ -10,15 +10,9 @@ namespace System.Reactive
 
         private readonly T[] _data;
 
-        private ImmutableList()
-        {
-            _data = Array.Empty<T>();
-        }
+        private ImmutableList() => _data = Array.Empty<T>();
 
-        public ImmutableList(T[] data)
-        {
-            _data = data;
-        }
+        public ImmutableList(T[] data) => _data = data;
 
         public T[] Data => _data;
 
@@ -34,7 +28,7 @@ namespace System.Reactive
 
         public ImmutableList<T> Remove(T value)
         {
-            var i = IndexOf(value);
+            var i = Array.IndexOf(_data, value);
             if (i < 0)
             {
                 return this;
@@ -53,18 +47,5 @@ namespace System.Reactive
 
             return new ImmutableList<T>(newData);
         }
-
-        private int IndexOf(T value)
-        {
-            for (var i = 0; i < _data.Length; ++i)
-            {
-                if (Equals(_data[i], value))
-                {
-                    return i;
-                }
-            }
-
-            return -1;
-        }
     }
 }