コード例 #1
0
        public static void RemoveAtUnordered(UnsafeList *list, int index)
        {
            UDebug.Assert(list != null);
            UDebug.Assert(list->_items.Ptr != null);

            var count = list->_count;

            // cast to uint trick, which eliminates < 0 check
            if ((uint)index >= (uint)count)
            {
                throw new IndexOutOfRangeException(ThrowHelper.ArgumentOutOfRange_Index);
            }

            // reduce count
            list->_count = --count;

            if (index < count)
            {
                UnsafeBuffer.Move(list->_items, count, index, 1);
            }
        }
コード例 #2
0
        public static void RemoveAt(UnsafeList *list, int index)
        {
            UDebug.Assert(list != null);
            UDebug.Assert(list->_items.Ptr != null);

            var count = list->_count;

            // cast to uint trick, which eliminates < 0 check
            if ((uint)index >= (uint)count)
            {
                throw new IndexOutOfRangeException(ThrowHelper.ArgumentOutOfRange_Index);
            }

            // reduce count
            list->_count = --count;

            // if index is still less than count, it means we removed an item
            // not at the end of the list, and that we have to shift the items
            // down from (index+1, count-index) to (index, count-index)
            if (index < count)
            {
                UnsafeBuffer.Move(list->_items, index + 1, index, count - index);
            }
        }