private static void RunArrayBenchmark() { ArrayElementGetter getter = null; ArrayElementSetter setter = null; var initMap = new Dictionary <string, Action> { { "Init setter", () => { setter = PeopleArray.GetType().DelegateForSetElement(); } }, { "Init getter", () => { getter = PeopleArray.GetType().DelegateForGetElement(); } } }; var actionMap = new Dictionary <string, Action> { { "Direct set", () => { PeopleArray[5] = null; } }, { "Direct get", () => { var person = PeopleArray[5]; } }, { "Reflection set", () => ((Array)(object)PeopleArray).SetValue(null, 5) }, { "Reflection get", () => ((Array)(object)PeopleArray).GetValue(5) }, { "Fasterflect set", () => PeopleArray.SetElement(5, null) }, { "Fasterflect get", () => PeopleArray.GetElement(5) }, { "Fasterflect cached set", () => setter(PeopleArray, 5, null) }, { "Fasterflect cached get", () => getter(PeopleArray, 5) }, }; Execute("Benchmark for Array Element Access", initMap, actionMap); }
/// <summary> /// Creates an <see cref="ArrayElementGetter"/> which sets an element of an array. /// </summary> /// <param name="arrayType">The <see cref="Type"/> of the array's elements.</param> /// <returns>An <see cref="ArrayElementGetter"/> which sets an element of an array.</returns> public static ArrayElementSetter ArraySetter(Type arrayType) { ArrayElementSetter value = ArraySetters.Get(arrayType); if (value != null) { return(value); } value = (ArrayElementSetter) new ArraySetEmitter(arrayType).GetDelegate(); ArraySetters.Insert(arrayType, value); return(value); }
public override void DrawPopupContent() { DrawTable("ArrayElementInputTable", elementObj.GetType(), elementIndex.ToString(), errored); if (ImGui.Button("OK")) { bool res = ArrayElementSetter.TrySetValue(arrayObj, elementObj.GetType(), elementIndex, inputText); if (res) { errored = false; CloseWindow(); } else { errored = true; } } }