Show More
Commit Description:
Optimize PreserveCounts and only recalculate when needed....
Commit Description:
Optimize PreserveCounts and only recalculate when needed. Previously would recalculate preservecounts every Update call (~1 per frame), which isn't necessary when there's no tick. Might be some room to tweak, like doing these updates only when preserves change. Some measurements: This takes about 30ms versus the .25 ms with no preserve (then like .0002ms). When the map is filled up with preserve, about 35ms and 9ms. With a handful of cells, it's more like 0.8ms (before JIT optimizes most of it away).
File last commit:
Show/Diff file:
Action:
ImGui.NET/ImVector.cs
75 lines | 1.9 KiB | text/x-csharp | CSharpLexer
using System;
using System.Runtime.CompilerServices;
namespace ImGuiNET
{
public unsafe struct ImVector
{
public readonly int Size;
public readonly int Capacity;
public readonly IntPtr Data;
public ref T Ref<T>(int index)
{
return ref Unsafe.AsRef<T>((byte*)Data + index * Unsafe.SizeOf<T>());
}
public IntPtr Address<T>(int index)
{
return (IntPtr)((byte*)Data + index * Unsafe.SizeOf<T>());
}
}
public unsafe struct ImVector<T>
{
public readonly int Size;
public readonly int Capacity;
public readonly IntPtr Data;
public ImVector(ImVector vector)
{
Size = vector.Size;
Capacity = vector.Capacity;
Data = vector.Data;
}
public ImVector(int size, int capacity, IntPtr data)
{
Size = size;
Capacity = capacity;
Data = data;
}
public ref T this[int index] => ref Unsafe.AsRef<T>((byte*)Data + index * Unsafe.SizeOf<T>());
}
public unsafe struct ImPtrVector<T>
{
public readonly int Size;
public readonly int Capacity;
public readonly IntPtr Data;
private readonly int _stride;
public ImPtrVector(ImVector vector, int stride)
: this(vector.Size, vector.Capacity, vector.Data, stride)
{ }
public ImPtrVector(int size, int capacity, IntPtr data, int stride)
{
Size = size;
Capacity = capacity;
Data = data;
_stride = stride;
}
public T this[int index]
{
get
{
byte* address = (byte*)Data + index * _stride;
T ret = Unsafe.Read<T>(&address);
return ret;
}
}
}
}