public unsafe void UnsafeList_TrimExcess() { var sizeOf = UnsafeUtility.SizeOf <int>(); var alignOf = UnsafeUtility.AlignOf <int>(); using (var list = new UnsafeList(sizeOf, alignOf, 32, Allocator.Persistent, NativeArrayOptions.ClearMemory)) { var capacity = list.Capacity; list.Add(1); list.TrimExcess <int>(); Assert.AreEqual(1, list.Length); Assert.AreEqual(1, list.Capacity); list.RemoveAtSwapBack <int>(0); Assert.AreEqual(list.Length, 0); list.TrimExcess <int>(); Assert.AreEqual(list.Capacity, 0); list.Add(1); Assert.AreEqual(list.Length, 1); Assert.AreNotEqual(list.Capacity, 0); list.Clear(); } }
internal bool TryRemoveChildAllocator(AllocatorHandle handle, int childAllocatorIndex) { if (!NeedsUseAfterFreeTracking()) { return(false); } if (childAllocatorIndex == InvalidChildAllocatorIndex) { return(false); } childAllocatorIndex = math.min(childAllocatorIndex, ChildAllocators.Length - 1); while (childAllocatorIndex >= 0) { unsafe { var allocatorHandle = ChildAllocators.Ptr + childAllocatorIndex; if (AreTheSame(*allocatorHandle, handle)) { ChildAllocators.RemoveAtSwapBack(childAllocatorIndex); return(true); } } --childAllocatorIndex; } return(false); }
internal bool TryRemoveSafetyHandle(AtomicSafetyHandle handle, int safetyHandleIndex) { if (!NeedsUseAfterFreeTracking()) { return(false); } if (safetyHandleIndex == InvalidChildSafetyHandleIndex) { return(false); } safetyHandleIndex = math.min(safetyHandleIndex, ChildSafetyHandles.Length - 1); while (safetyHandleIndex >= 0) { unsafe { var safetyHandle = ChildSafetyHandles.Ptr + safetyHandleIndex; if (AreTheSame(*safetyHandle, handle)) { ChildSafetyHandles.RemoveAtSwapBack(safetyHandleIndex); return(true); } } --safetyHandleIndex; } return(false); }
public bool Remove(K entity) { int index = contents.IndexOf <K>(entity); if (index >= 0) { contents.RemoveAtSwapBack <K>(index); return(true); } return(false); }
public static bool AddWriterTypeIndex(int typeIndex, ref UnsafeList reading, ref UnsafeList writing) { if (writing.Contains(typeIndex)) { return(false); } var readingIndex = reading.IndexOf(typeIndex); if (readingIndex != -1) { reading.RemoveAtSwapBack <int>(readingIndex); } writing.Add(typeIndex); return(true); }
public static bool Add(ComponentType type, ref UnsafeList reading, ref UnsafeList writing) { if (!type.RequiresJobDependency) { return(false); } // If any other dependency is added the Entity type dependency is removed to avoid the overhead of having all jobs // depend on this. if ((reading.m_size == 1) && reading.Contains(TypeManager.GetTypeIndex <Entity>())) { reading.m_size = 0; } if (type.AccessModeType == ComponentType.AccessMode.ReadOnly) { if (reading.Contains(type.TypeIndex)) { return(false); } if (writing.Contains(type.TypeIndex)) { return(false); } reading.Add(type.TypeIndex); return(true); } else { if (writing.Contains(type.TypeIndex)) { return(false); } var readingIndex = reading.IndexOf(type.TypeIndex); if (readingIndex != -1) { reading.RemoveAtSwapBack <int>(readingIndex); } writing.Add(type.TypeIndex); return(true); } }
internal unsafe void CalculateDependents(NativeArray <int> instanceIds, NativeHashSet <int> outDependents) { var toBeProcessed = new UnsafeList <int>(0, Allocator.Temp); toBeProcessed.AddRange(instanceIds.GetUnsafeReadOnlyPtr(), instanceIds.Length); while (toBeProcessed.Length != 0) { var instance = toBeProcessed.Ptr[toBeProcessed.Length - 1]; toBeProcessed.RemoveAtSwapBack(toBeProcessed.Length - 1); if (outDependents.Add(instance)) { var dependentIds = _dependentsByInstanceId.GetValuesForKey(instance); while (dependentIds.MoveNext()) { if (!outDependents.Contains(dependentIds.Current)) { toBeProcessed.Add(dependentIds.Current); } } } } }