瀏覽代碼

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

Use Array.IndexOf for better perf
Bart J.F. De Smet 5 年之前
父節點
當前提交
c0b7c7a469
共有 1 個文件被更改,包括 3 次插入22 次删除
  1. 3 22
      Rx.NET/Source/src/System.Reactive/Internal/ImmutableList.cs

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

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