public void Add <T>(ref T copySource, out ListLinkedListNode *page, out int index, Allocator allocator) where T : unmanaged { ListLinkedListNode *tryNode; if (LastFull == null) { tryNode = First; } else { tryNode = LastFull->Next; } for (; tryNode != null; tryNode = tryNode->Next) { if (tryNode->TryAdd(ref copySource, out index)) { if (tryNode->IsFull) { LastFull = tryNode; } page = tryNode; return; } UnityEngine.Debug.Log("LAST FULL RENEW"); LastFull = tryNode; } page = ListLinkedListNode.Create <T>(NodeCapacity, allocator); index = 0; page->GetRef <T>(0) = copySource; page->Length = 1; for (tryNode = LastFull; IntPtr.Zero != Interlocked.CompareExchange(ref tryNode->NextNodePtr, new IntPtr(page), IntPtr.Zero); tryNode = tryNode->Next) { ; } }
public void AddRange <T>(T *copySource, int length, out ListLinkedListNode *page, out int start, Allocator allocator) where T : unmanaged { ListLinkedListNode *tryNode; if (LastFull == null) { tryNode = First; } else if (LastFull->NextNodePtr == IntPtr.Zero) { tryNode = LastFull; goto ADDNEWPAGE; } else { tryNode = LastFull->Next; } if (length > NodeCapacity) { NodeCapacity = length; goto ADDNEWPAGE; } while (true) { if (tryNode->TryAdd(copySource, length, out start)) { if (tryNode->IsFull && LastFull->Next == tryNode) { LastFull = tryNode; } page = tryNode; return; } if (tryNode->NextNodePtr == IntPtr.Zero) { goto ADDNEWPAGE; } tryNode = tryNode->Next; } ADDNEWPAGE: page = ListLinkedListNode.Create <T>(NodeCapacity, allocator); start = 0; UnsafeUtility.MemCpy(page->Values, copySource, sizeof(T) * length); while (IntPtr.Zero != Interlocked.CompareExchange(ref tryNode->NextNodePtr, new IntPtr(page), IntPtr.Zero)) { tryNode = tryNode->Next; } }