Açıklama Yok
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

ListUtilities.cs 1.6KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051
  1. using System;
  2. using System.Collections.Generic;
  3. namespace UnityEditor.ShaderGraph
  4. {
  5. static class ListUtilities
  6. {
  7. // Ideally, we should build a non-yield return, struct version of Slice
  8. public static IEnumerable<T> Slice<T>(this List<T> list, int start, int end)
  9. {
  10. for (int i = start; i < end; i++)
  11. yield return list[i];
  12. }
  13. public static int RemoveAllFromRange<T>(this List<T> list, Predicate<T> match, int startIndex, int count)
  14. {
  15. // match behavior of RemoveRange
  16. if ((startIndex < 0) || (count < 0))
  17. throw new ArgumentOutOfRangeException();
  18. int endIndex = startIndex + count;
  19. if (endIndex > list.Count)
  20. throw new ArgumentException();
  21. int readIndex = startIndex;
  22. int writeIndex = startIndex;
  23. while (readIndex < endIndex)
  24. {
  25. T element = list[readIndex];
  26. bool remove = match(element);
  27. if (!remove)
  28. {
  29. // skip some work if nothing removed (especially if T is a large struct)
  30. if (writeIndex < readIndex)
  31. list[writeIndex] = element;
  32. writeIndex++;
  33. }
  34. readIndex++;
  35. }
  36. // once we're done, we can remove the entries at the end in one operation
  37. int numberRemoved = readIndex - writeIndex;
  38. if (numberRemoved > 0)
  39. {
  40. list.RemoveRange(writeIndex, numberRemoved);
  41. }
  42. return numberRemoved;
  43. }
  44. }
  45. }