< Summary

Class:GDX.Collections.Generic.SimpleListExtensions
Assembly:GDX
File(s):./Packages/com.dotbunny.gdx/GDX/Collections/Generic/SimpleListExtensions.cs
Covered lines:157
Uncovered lines:62
Coverable lines:219
Total lines:572
Line coverage:71.6% (157 of 219)
Covered branches:0
Total branches:0
Covered methods:15
Total methods:21
Method coverage:71.4% (15 of 21)

Coverage History

Metrics

MethodBranch coverage Crap Score Cyclomatic complexity NPath complexity Sequence coverage
AddUncheckedUniqueItem[T](...)0%220100%
AddUncheckedUniqueReference[T](...)0%220100%
AddWithExpandCheckUniqueItem[T](...)0%220100%
AddWithExpandCheckUniqueValue[T](...)0%330100%
AddWithExpandCheckUniqueReference[T](...)0%220100%
Contains[T](...)0%12300%
ContainsItem[T](...)0%330100%
ContainsValue[T](...)0%33092.31%
ContainsReference[T](...)0%330100%
FirstIndexOf[T](...)0%3.013091.67%
FirstIndexOfItem[T](...)0%12300%
FirstIndexOfValue[T](...)0%12300%
LastIndexOf[T](...)0%12300%
LastIndexOfItem[T](...)0%12300%
LastIndexOfValue[T](...)0%12300%
RemoveFirstItem[T](...)0%33092.86%
RemoveFirstReference[T](...)0%33092.86%
RemoveItems[T](...)0%330100%
RemoveReferences[T](...)0%330100%
RemoveLastItem[T](...)0%33092.86%
RemoveLastReference[T](...)0%33092.86%

File(s)

./Packages/com.dotbunny.gdx/GDX/Collections/Generic/SimpleListExtensions.cs

#LineLine coverage
 1// Copyright (c) 2020-2024 dotBunny Inc.
 2// dotBunny licenses this file to you under the BSL-1.0 license.
 3// See the LICENSE file in the project root for more information.
 4
 5using System;
 6using System.Runtime.CompilerServices;
 7
 8namespace GDX.Collections.Generic
 9{
 10    /// <summary>
 11    ///     <see cref="GDX.Collections.Generic.SimpleList{T}" /> Based Extension Methods
 12    /// </summary>
 13    /// <remarks>
 14    ///     Methods found in this extensions class are less performant then the included methods in
 15    ///     <see cref="GDX.Collections.Generic.SimpleList{T}" />. They are seperated out to clearly delineate this
 16    ///     performance regression.
 17    /// </remarks>
 18    public static class SimpleListExtensions
 19    {
 20        /// <summary>
 21        ///     Add an item to the <see cref="SimpleList{T}" /> without checking the internal size,
 22        ///     making sure that the item is not already contained in the <see cref="SimpleList{T}" />.
 23        /// </summary>
 24        /// <param name="targetSimpleList">The target <see cref="SimpleList{T}" /> to add to.</param>
 25        /// <param name="targetItem">The target class object to add.</param>
 26        /// <typeparam name="T">The type of the <see cref="SimpleList{T}" />.</typeparam>
 27        /// <returns>true/false if the operation was able to add the item successfully.</returns>
 28        [MethodImpl(MethodImplOptions.AggressiveInlining)]
 29        public static bool AddUncheckedUniqueItem<T>(ref this SimpleList<T> targetSimpleList, T targetItem)
 30            where T : class
 931        {
 932            if (targetSimpleList.ContainsItem(targetItem))
 133            {
 134                return false;
 35            }
 36
 837            targetSimpleList.AddUnchecked(targetItem);
 738            return true;
 839        }
 40
 41        /// <summary>
 42        ///     Add an object reference to the <see cref="SimpleList{T}" /> without checking the internal size,
 43        ///     making sure that the reference is not already contained in the <see cref="SimpleList{T}" />.
 44        ///     Does not prevent addition of different objects for which Equals returns true.
 45        /// </summary>
 46        /// <param name="targetSimpleList">The target <see cref="SimpleList{T}" /> to add to.</param>
 47        /// <param name="targetReference">The target class object to add.</param>
 48        /// <typeparam name="T">The type of the <see cref="SimpleList{T}" />.</typeparam>
 49        /// <returns>true/false if the operation was able to add the reference successfully.</returns>
 50        [MethodImpl(MethodImplOptions.AggressiveInlining)]
 51        public static bool AddUncheckedUniqueReference<T>(ref this SimpleList<T> targetSimpleList, T targetReference)
 52            where T : class
 953        {
 954            if (targetSimpleList.ContainsReference(targetReference))
 155            {
 156                return false;
 57            }
 58
 859            targetSimpleList.AddUnchecked(targetReference);
 760            return true;
 861        }
 62
 63        /// <summary>
 64        ///     Add an item to the <see cref="SimpleList{T}" /> with checking the internal size (expanding as necessary)
 65        ///     making sure that the item is not already contained in the <see cref="SimpleList{T}" />.
 66        /// </summary>
 67        /// <param name="targetSimpleList">The target <see cref="SimpleList{T}" /> to add to.</param>
 68        /// <param name="targetItem">The target class object to add.</param>
 69        /// <typeparam name="T">The type of the <see cref="SimpleList{T}" />.</typeparam>
 70        /// <returns>true/false if the operation was able to add the item successfully.</returns>
 71        [MethodImpl(MethodImplOptions.AggressiveInlining)]
 72        public static bool AddWithExpandCheckUniqueItem<T>(ref this SimpleList<T> targetSimpleList, T targetItem)
 73            where T : class
 874        {
 875            if (targetSimpleList.ContainsItem(targetItem))
 176            {
 177                return false;
 78            }
 79
 780            targetSimpleList.AddWithExpandCheck(targetItem);
 781            return true;
 882        }
 83
 84        /// <summary>
 85        ///     Add an item to the <see cref="SimpleList{T}" /> with checking the internal size (expanding as necessary)
 86        ///     making sure that the item is not already contained in the <see cref="SimpleList{T}" />.
 87        /// </summary>
 88        /// <param name="targetSimpleList">The target <see cref="SimpleList{T}" /> to add to.</param>
 89        /// <param name="targetItem">The target class object to add.</param>
 90        /// <typeparam name="T">The type of the <see cref="SimpleList{T}" />.</typeparam>
 91        /// <returns>true/false if the operation was able to add the item successfully.</returns>
 92        [MethodImpl(MethodImplOptions.AggressiveInlining)]
 93        public static bool AddWithExpandCheckUniqueValue<T>(ref this SimpleList<T> targetSimpleList, T targetItem)
 94            where T : IEquatable<T>
 895        {
 896            int count = targetSimpleList.Count;
 3497            for (int i = 0; i < count; i++)
 1098            {
 1099                if (targetSimpleList.Array[i].Equals(targetItem))
 1100                {
 1101                    return false;
 102                }
 9103            }
 104
 7105            targetSimpleList.AddWithExpandCheck(targetItem);
 7106            return true;
 8107        }
 108
 109        /// <summary>
 110        ///     Add an object reference to the <see cref="SimpleList{T}" /> with checking the internal size (expanding a
 111        ///     necessary),
 112        ///     making sure that the reference is not already contained in the <see cref="SimpleList{T}" />.
 113        ///     Does not prevent addition of different objects for which Equals returns true.
 114        /// </summary>
 115        /// <param name="targetSimpleList">The target <see cref="SimpleList{T}" /> to add to.</param>
 116        /// <param name="targetReference">The target class object to add.</param>
 117        /// <typeparam name="T">The type of the <see cref="SimpleList{T}" />.</typeparam>
 118        /// <returns>true/false if the operation was able to add the reference successfully.</returns>
 119        [MethodImpl(MethodImplOptions.AggressiveInlining)]
 120        public static bool AddWithExpandCheckUniqueReference<T>(ref this SimpleList<T> targetSimpleList,
 121            T targetReference)
 122            where T : class
 8123        {
 8124            if (targetSimpleList.ContainsReference(targetReference))
 1125            {
 1126                return false;
 127            }
 128
 7129            targetSimpleList.AddWithExpandCheck(targetReference);
 7130            return true;
 8131        }
 132
 133        /// <summary>
 134        ///     <para>Does <paramref name="targetSimpleList" /> contain <paramref name="targetItem" />?</para>
 135        /// </summary>
 136        /// <param name="targetSimpleList">The <see cref="SimpleList{T}" /> to look in.</param>
 137        /// <param name="targetItem">The target class object to look for.</param>
 138        /// <typeparam name="T">The type of the <see cref="SimpleList{T}" />.</typeparam>
 139        /// <returns>true/false</returns>
 140        [MethodImpl(MethodImplOptions.AggressiveInlining)]
 141        public static bool Contains<T>(ref this SimpleList<T> targetSimpleList, T targetItem) where T : IEquatable<T>
 0142        {
 0143            int length = targetSimpleList.Count;
 0144            T[] array = targetSimpleList.Array;
 145
 0146            for (int i = 0; i < length; i++)
 0147            {
 0148                if (array[i].Equals(targetItem))
 0149                {
 0150                    return true;
 151                }
 0152            }
 153
 0154            return false;
 0155        }
 156
 157        /// <summary>
 158        ///     <para>Does <paramref name="targetSimpleList" /> contain <paramref name="targetItem" />?</para>
 159        /// </summary>
 160        /// <remarks>Avoids using <see cref="System.Collections.Generic.EqualityComparer{T}" />.</remarks>
 161        /// <param name="targetSimpleList">The <see cref="SimpleList{T}" /> to look in.</param>
 162        /// <param name="targetItem">The target class object to look for.</param>
 163        /// <typeparam name="T">The type of the <see cref="SimpleList{T}" />.</typeparam>
 164        /// <returns>true/false</returns>
 165        [MethodImpl(MethodImplOptions.AggressiveInlining)]
 166        public static bool ContainsItem<T>(ref this SimpleList<T> targetSimpleList, T targetItem) where T : class
 22167        {
 22168            int length = targetSimpleList.Count;
 22169            T[] array = targetSimpleList.Array;
 170
 96171            for (int i = 0; i < length; i++)
 32172            {
 32173                if (array[i] == targetItem)
 6174                {
 6175                    return true;
 176                }
 26177            }
 178
 16179            return false;
 22180        }
 181
 182        /// <summary>
 183        ///     <para>Does <paramref name="targetSimpleList" /> contain <paramref name="targetItem" />?</para>
 184        /// </summary>
 185        /// <remarks>Avoids using <see cref="System.Collections.Generic.EqualityComparer{T}" />.</remarks>
 186        /// <param name="targetSimpleList">The <see cref="SimpleList{T}" /> to look in.</param>
 187        /// <param name="targetItem">The target class object to look for.</param>
 188        /// <typeparam name="T">The type of the <see cref="SimpleList{T}" />.</typeparam>
 189        /// <returns>true/false</returns>
 190        [MethodImpl(MethodImplOptions.AggressiveInlining)]
 191        public static bool ContainsValue<T>(ref this SimpleList<T> targetSimpleList, T targetItem)
 192            where T : IEquatable<T>
 2193        {
 2194            int length = targetSimpleList.Count;
 2195            T[] array = targetSimpleList.Array;
 196
 12197            for (int i = 0; i < length; i++)
 5198            {
 5199                if (array[i].Equals(targetItem))
 1200                {
 1201                    return true;
 202                }
 4203            }
 204
 1205            return false;
 2206        }
 207
 208        /// <summary>
 209        ///     <para>Does <paramref name="targetSimpleList" /> contain <paramref name="targetItem" />?</para>
 210        /// </summary>
 211        /// <remarks>Ignores equality check and end up comparing object pointers.</remarks>
 212        /// <param name="targetSimpleList">The <see cref="SimpleList{T}" /> to look in.</param>
 213        /// <param name="targetItem">The target class object to look for.</param>
 214        /// <typeparam name="T">The type of the <see cref="SimpleList{T}" />.</typeparam>
 215        /// <returns>true/false</returns>
 216        [MethodImpl(MethodImplOptions.AggressiveInlining)]
 217        public static bool ContainsReference<T>(ref this SimpleList<T> targetSimpleList, T targetItem) where T : class
 22218        {
 22219            int length = targetSimpleList.Count;
 22220            T[] array = targetSimpleList.Array;
 221
 96222            for (int i = 0; i < length; i++)
 32223            {
 224#pragma warning disable
 225                // ReSharper disable All
 32226                if ((System.Object)array[i] == (System.Object)targetItem)
 6227                {
 6228                    return true;
 229                }
 230                // ReSharper restore All
 231#pragma warning restore
 26232            }
 233
 16234            return false;
 22235        }
 236
 237        /// <summary>
 238        ///     Find the first index of <paramref name="targetItem" /> in <paramref name="targetSimpleList" />.
 239        /// </summary>
 240        /// <remarks>This will work for <see cref="string" /> comparisons.</remarks>
 241        /// <param name="targetSimpleList">The <see cref="SimpleList{T}" /> to look in.</param>
 242        /// <param name="targetItem">The object to be found.</param>
 243        /// <typeparam name="T">The type of the array.</typeparam>
 244        /// <returns>
 245        ///     The index of <paramref name="targetItem" /> in <paramref name="targetSimpleList" /> backing array, or -1
 246        ///     not found.
 247        /// </returns>
 248        public static int FirstIndexOf<T>(ref this SimpleList<T> targetSimpleList, T targetItem) where T : IEquatable<T>
 52249        {
 52250            int length = targetSimpleList.Count;
 156251            for (int i = 0; i < length; i++)
 78252            {
 78253                if (targetSimpleList.Array[i].Equals(targetItem))
 52254                {
 52255                    return i;
 256                }
 26257            }
 258
 0259            return -1;
 52260        }
 261
 262        /// <summary>
 263        ///     Find the first index of <paramref name="targetItem" /> in <paramref name="targetSimpleList" />.
 264        /// </summary>
 265        /// <remarks>Ignores equality check and end up comparing object pointers. Do NOT use this for <see cref="string"
 266        /// <param name="targetSimpleList">The <see cref="SimpleList{T}" /> to look in.</param>
 267        /// <param name="targetItem">The object to be found.</param>
 268        /// <typeparam name="T">The type of the array.</typeparam>
 269        /// <returns>
 270        ///     The index of <paramref name="targetItem" /> in <paramref name="targetSimpleList" /> backing array, or -1
 271        ///     not found.
 272        /// </returns>
 273        public static int FirstIndexOfItem<T>(ref this SimpleList<T> targetSimpleList, T targetItem) where T : class
 0274        {
 0275            int length = targetSimpleList.Count;
 0276            for (int i = 0; i < length; i++)
 0277            {
 0278                if (targetSimpleList.Array[i] == targetItem)
 0279                {
 0280                    return i;
 281                }
 0282            }
 283
 0284            return -1;
 0285        }
 286
 287        /// <summary>
 288        ///     Find the first index of <paramref name="targetValue" /> in <paramref name="targetSimpleList" />.
 289        /// </summary>
 290        /// <param name="targetSimpleList">The <see cref="SimpleList{T}" /> to look in.</param>
 291        /// <param name="targetValue">The value to be found.</param>
 292        /// <typeparam name="T">The type of the array.</typeparam>
 293        /// <returns>
 294        ///     The index of <paramref name="targetValue" /> in <paramref name="targetSimpleList" /> backing array, or -
 295        ///     not found.
 296        /// </returns>
 297        public static int FirstIndexOfValue<T>(ref this SimpleList<T> targetSimpleList, T targetValue) where T : struct
 0298        {
 0299            int length = targetSimpleList.Count;
 0300            for (int i = 0; i < length; i++)
 0301            {
 0302                if (targetSimpleList.Array[i].Equals(targetValue))
 0303                {
 0304                    return i;
 305                }
 0306            }
 307
 0308            return -1;
 0309        }
 310
 311
 312        /// <summary>
 313        ///     Find the last index of <paramref name="targetItem" /> in <paramref name="targetSimpleList" />.
 314        /// </summary>
 315        /// <remarks>This will work for <see cref="string" /> comparisons.</remarks>
 316        /// <param name="targetSimpleList">The <see cref="SimpleList{T}" /> to look in.</param>
 317        /// <param name="targetItem">The object to be found.</param>
 318        /// <typeparam name="T">The type of the array.</typeparam>
 319        /// <returns>
 320        ///     The index of <paramref name="targetItem" /> in <paramref name="targetSimpleList" /> backing array, or -1
 321        ///     not found.
 322        /// </returns>
 323        public static int LastIndexOf<T>(ref this SimpleList<T> targetSimpleList, T targetItem) where T : IEquatable<T>
 0324        {
 0325            int length = targetSimpleList.Count;
 0326            for (int i = length - 1; i >= 0; i--)
 0327            {
 0328                if (targetSimpleList.Array[i].Equals(targetItem))
 0329                {
 0330                    return i;
 331                }
 0332            }
 333
 0334            return -1;
 0335        }
 336
 337        /// <summary>
 338        ///     Find the last index of <paramref name="targetItem" /> in <paramref name="targetSimpleList" />.
 339        /// </summary>
 340        /// <param name="targetSimpleList">The <see cref="SimpleList{T}" /> to look in.</param>
 341        /// <param name="targetItem">The object to be found.</param>
 342        /// <typeparam name="T">The type of the array.</typeparam>
 343        /// <returns>
 344        ///     The index of <paramref name="targetItem" /> in <paramref name="targetSimpleList" /> backing array, or -1
 345        ///     not found.
 346        /// </returns>
 347        public static int LastIndexOfItem<T>(ref this SimpleList<T> targetSimpleList, T targetItem) where T : class
 0348        {
 0349            int length = targetSimpleList.Count;
 0350            for (int i = length - 1; i >= 0; i--)
 0351            {
 0352                if (targetSimpleList.Array[i] == targetItem)
 0353                {
 0354                    return i;
 355                }
 0356            }
 357
 0358            return -1;
 0359        }
 360
 361        /// <summary>
 362        ///     Find the last index of <paramref name="targetValue" /> in <paramref name="targetSimpleList" />.
 363        /// </summary>
 364        /// <param name="targetSimpleList">The <see cref="SimpleList{T}" /> to look in.</param>
 365        /// <param name="targetValue">The value to be found.</param>
 366        /// <typeparam name="T">The type of the array.</typeparam>
 367        /// <returns>
 368        ///     The index of <paramref name="targetValue" /> in <paramref name="targetSimpleList" /> backing array, or -
 369        ///     not found.
 370        /// </returns>
 371        public static int LastIndexOfValue<T>(ref this SimpleList<T> targetSimpleList, T targetValue) where T : struct
 0372        {
 0373            int length = targetSimpleList.Count;
 0374            for (int i = length - 1; i >= 0; i--)
 0375            {
 0376                if (targetSimpleList.Array[i].Equals(targetValue))
 0377                {
 0378                    return i;
 379                }
 0380            }
 381
 0382            return -1;
 0383        }
 384
 385        /// <summary>
 386        ///     <para>Removes the first <paramref name="targetItem" /> from the provided <paramref name="targetSimpleLis
 387        /// </summary>
 388        /// <remarks>Avoids using <see cref="System.Collections.Generic.EqualityComparer{T}" />.</remarks>
 389        /// <param name="targetSimpleList">The target <see cref="SimpleList{T}" />.</param>
 390        /// <param name="targetItem">The target object to remove from the <paramref name="targetSimpleList" />.</param>
 391        /// <typeparam name="T">The type of the <see cref="SimpleList{T}" />.</typeparam>
 392        /// <returns>true/false if an item was removed.</returns>
 393        [MethodImpl(MethodImplOptions.AggressiveInlining)]
 394        public static bool RemoveFirstItem<T>(ref this SimpleList<T> targetSimpleList, T targetItem) where T : class
 2395        {
 2396            int length = targetSimpleList.Count;
 2397            T[] array = targetSimpleList.Array;
 398
 18399            for (int i = 0; i < length; i++)
 8400            {
 401                // Skip to next if its not what we are looking for
 8402                if (array[i] != targetItem)
 7403                {
 7404                    continue;
 405                }
 406
 1407                targetSimpleList.RemoveAt(i);
 1408                return true;
 409            }
 410
 1411            return false;
 2412        }
 413
 414        /// <summary>
 415        ///     <para>Removes the first <paramref name="targetReference" /> from the provided <paramref name="targetSimp
 416        ///     Only removes direct object references, i.e. equivalent strings at different memory addresses would not b
 417        /// </summary>
 418        /// <remarks>Avoids using <see cref="System.Collections.Generic.EqualityComparer{T}" />.</remarks>
 419        /// <param name="targetSimpleList">The target <see cref="SimpleList{T}" />.</param>
 420        /// <param name="targetReference">The target object to remove from the <paramref name="targetSimpleList" />.</pa
 421        /// <typeparam name="T">The type of the <see cref="SimpleList{T}" />.</typeparam>
 422        /// <returns>true/false if an object reference was removed.</returns>
 423        [MethodImpl(MethodImplOptions.AggressiveInlining)]
 424        public static bool RemoveFirstReference<T>(ref this SimpleList<T> targetSimpleList, T targetReference)
 425            where T : class
 2426        {
 2427            int length = targetSimpleList.Count;
 2428            T[] array = targetSimpleList.Array;
 429
 18430            for (int i = 0; i < length; i++)
 8431            {
 432#pragma warning disable
 433                // ReSharper disable All
 8434                if ((System.Object)array[i] == (System.Object)targetReference)
 1435                {
 1436                    targetSimpleList.RemoveAt(i);
 1437                    return true;
 438                }
 439                // ReSharper restore All
 440#pragma warning restore
 7441            }
 442
 1443            return false;
 2444        }
 445
 446        /// <summary>
 447        ///     <para>Removes all <paramref name="targetItem" /> from the provided <paramref name="targetSimpleList" />.
 448        /// </summary>
 449        /// <remarks>Avoids using <see cref="System.Collections.Generic.EqualityComparer{T}" />.</remarks>
 450        /// <param name="targetSimpleList">The target <see cref="SimpleList{T}" />.</param>
 451        /// <param name="targetItem">The item to remove from the <paramref name="targetSimpleList" />.</param>
 452        /// <typeparam name="T">The type of the <see cref="SimpleList{T}" />.</typeparam>
 453        /// <returns>true/false if items were removed.</returns>
 454        public static bool RemoveItems<T>(ref this SimpleList<T> targetSimpleList, T targetItem) where T : class
 1455        {
 1456            int length = targetSimpleList.Count;
 1457            T[] array = targetSimpleList.Array;
 1458            bool removedItems = false;
 459
 14460            for (int i = length - 1; i >= 0; i--)
 6461            {
 462                // Skip to next if its not what we are looking for
 6463                if (array[i] != targetItem)
 4464                {
 4465                    continue;
 466                }
 467
 2468                targetSimpleList.RemoveAt(i);
 2469                removedItems = true;
 2470            }
 471
 1472            return removedItems;
 1473        }
 474
 475        /// <summary>
 476        ///     <para>
 477        ///         Removes all instances of references to <paramref name="targetReference" /> from the provided
 478        ///         <paramref name="targetSimpleList" />.
 479        ///     </para>
 480        ///     Only removes direct object references, i.e. equivalent strings at different memory addresses would not b
 481        /// </summary>
 482        /// <remarks>Avoids using <see cref="System.Collections.Generic.EqualityComparer{T}" />.</remarks>
 483        /// <param name="targetSimpleList">The target <see cref="SimpleList{T}" />.</param>
 484        /// <param name="targetReference">The object reference to remove from the <paramref name="targetSimpleList" />.<
 485        /// <typeparam name="T">The type of the <see cref="SimpleList{T}" />.</typeparam>
 486        /// <returns>true/false if any references were removed.</returns>
 487        public static bool RemoveReferences<T>(ref this SimpleList<T> targetSimpleList, T targetReference)
 488            where T : class
 1489        {
 1490            int length = targetSimpleList.Count;
 1491            T[] array = targetSimpleList.Array;
 1492            bool removedItems = false;
 493
 14494            for (int i = length - 1; i >= 0; i--)
 6495            {
 496#pragma warning disable
 497                // ReSharper disable All
 6498                if ((System.Object)array[i] == (System.Object)targetReference)
 2499                {
 2500                    targetSimpleList.RemoveAt(i);
 2501                    removedItems = true;
 2502                }
 503                // ReSharper restore All
 504#pragma warning restore
 6505            }
 506
 1507            return removedItems;
 1508        }
 509
 510        /// <summary>
 511        ///     <para>Removes the last <paramref name="targetItem" /> from the provided <paramref name="targetSimpleList
 512        /// </summary>
 513        /// <remarks>Avoids using <see cref="System.Collections.Generic.EqualityComparer{T}" />.</remarks>
 514        /// <param name="targetSimpleList">The target <see cref="SimpleList{T}" />.</param>
 515        /// <param name="targetItem">The target object to remove from the <paramref name="targetSimpleList" />.</param>
 516        /// <typeparam name="T">The type of the <see cref="SimpleList{T}" />.</typeparam>
 517        /// <returns>true/false if an item was removed.</returns>
 518        public static bool RemoveLastItem<T>(ref this SimpleList<T> targetSimpleList, T targetItem) where T : class
 2519        {
 2520            int length = targetSimpleList.Count;
 2521            T[] array = targetSimpleList.Array;
 522
 18523            for (int i = length - 1; i >= 0; i--)
 8524            {
 525                // Skip to next if its not what we are looking for
 8526                if (array[i] != targetItem)
 7527                {
 7528                    continue;
 529                }
 530
 1531                targetSimpleList.RemoveAt(i);
 1532                return true;
 533            }
 534
 1535            return false;
 2536        }
 537
 538        /// <summary>
 539        ///     <para>
 540        ///         Removes the last reference to <paramref name="targetReference" /> from the provided
 541        ///         <paramref name="targetSimpleList" />.
 542        ///     </para>
 543        ///     Only removes direct object references, i.e. equivalent strings at different memory addresses would not b
 544        /// </summary>
 545        /// <remarks>Avoids using <see cref="System.Collections.Generic.EqualityComparer{T}" />.</remarks>
 546        /// <param name="targetSimpleList">The target <see cref="SimpleList{T}" />.</param>
 547        /// <param name="targetReference">The target object reference to remove from the <paramref name="targetSimpleLis
 548        /// <typeparam name="T">The type of the <see cref="SimpleList{T}" />.</typeparam>
 549        /// <returns>true/false if an object reference was removed.</returns>
 550        public static bool RemoveLastReference<T>(ref this SimpleList<T> targetSimpleList, T targetReference)
 551            where T : class
 2552        {
 2553            int length = targetSimpleList.Count;
 2554            T[] array = targetSimpleList.Array;
 555
 18556            for (int i = length - 1; i >= 0; i--)
 8557            {
 558#pragma warning disable
 559                // ReSharper disable All
 8560                if ((System.Object)array[i] == (System.Object)targetReference)
 1561                {
 1562                    targetSimpleList.RemoveAt(i);
 1563                    return true;
 564                }
 565                // ReSharper restore All
 566#pragma warning restore
 7567            }
 568
 1569            return false;
 2570        }
 571    }
 572}

Coverage by test methods






























Methods/Properties

AddUncheckedUniqueItem[T](, T)
AddUncheckedUniqueReference[T](, T)
AddWithExpandCheckUniqueItem[T](, T)
AddWithExpandCheckUniqueValue[T](, T)
AddWithExpandCheckUniqueReference[T](, T)
Contains[T](, T)
ContainsItem[T](, T)
ContainsValue[T](, T)
ContainsReference[T](, T)
FirstIndexOf[T](, T)
FirstIndexOfItem[T](, T)
FirstIndexOfValue[T](, T)
LastIndexOf[T](, T)
LastIndexOfItem[T](, T)
LastIndexOfValue[T](, T)
RemoveFirstItem[T](, T)
RemoveFirstReference[T](, T)
RemoveItems[T](, T)
RemoveReferences[T](, T)
RemoveLastItem[T](, T)
RemoveLastReference[T](, T)