Fix missing length modification in ImVectorWrapper.Insert

This commit is contained in:
Soreepeong 2023-12-08 23:20:25 +09:00
parent b89df8b130
commit 0c3ebd4b5b

View file

@ -519,10 +519,11 @@ public unsafe struct ImVectorWrapper<T> : IList<T>, IList, IReadOnlyList<T>, IDi
if (index < 0 || index > this.LengthUnsafe) if (index < 0 || index > this.LengthUnsafe)
throw new IndexOutOfRangeException(); throw new IndexOutOfRangeException();
this.EnsureCapacityExponential(this.CapacityUnsafe + 1); this.EnsureCapacityExponential(this.LengthUnsafe + 1);
var num = this.LengthUnsafe - index; var num = this.LengthUnsafe - index;
Buffer.MemoryCopy(this.DataUnsafe + index, this.DataUnsafe + index + 1, num * sizeof(T), num * sizeof(T)); Buffer.MemoryCopy(this.DataUnsafe + index, this.DataUnsafe + index + 1, num * sizeof(T), num * sizeof(T));
this.DataUnsafe[index] = item; this.DataUnsafe[index] = item;
this.LengthUnsafe += 1;
} }
/// <inheritdoc cref="List{T}.InsertRange"/> /// <inheritdoc cref="List{T}.InsertRange"/>
@ -535,6 +536,7 @@ public unsafe struct ImVectorWrapper<T> : IList<T>, IList, IReadOnlyList<T>, IDi
Buffer.MemoryCopy(this.DataUnsafe + index, this.DataUnsafe + index + count, num * sizeof(T), num * sizeof(T)); Buffer.MemoryCopy(this.DataUnsafe + index, this.DataUnsafe + index + count, num * sizeof(T), num * sizeof(T));
foreach (var item in items) foreach (var item in items)
this.DataUnsafe[index++] = item; this.DataUnsafe[index++] = item;
this.LengthUnsafe += count;
} }
else else
{ {
@ -551,6 +553,7 @@ public unsafe struct ImVectorWrapper<T> : IList<T>, IList, IReadOnlyList<T>, IDi
Buffer.MemoryCopy(this.DataUnsafe + index, this.DataUnsafe + index + items.Length, num * sizeof(T), num * sizeof(T)); Buffer.MemoryCopy(this.DataUnsafe + index, this.DataUnsafe + index + items.Length, num * sizeof(T), num * sizeof(T));
foreach (var item in items) foreach (var item in items)
this.DataUnsafe[index++] = item; this.DataUnsafe[index++] = item;
this.LengthUnsafe += items.Length;
} }
/// <summary> /// <summary>
@ -566,6 +569,7 @@ public unsafe struct ImVectorWrapper<T> : IList<T>, IList, IReadOnlyList<T>, IDi
this.destroyer?.Invoke(&this.DataUnsafe[index]); this.destroyer?.Invoke(&this.DataUnsafe[index]);
Buffer.MemoryCopy(this.DataUnsafe + index + 1, this.DataUnsafe + index, num * sizeof(T), num * sizeof(T)); Buffer.MemoryCopy(this.DataUnsafe + index + 1, this.DataUnsafe + index, num * sizeof(T), num * sizeof(T));
this.LengthUnsafe -= 1;
} }
/// <inheritdoc/> /// <inheritdoc/>