public object this[ChainSegment segment] { [MethodImpl(MethodImplOptions.AggressiveInlining)] get { var knownVariableIndex = (int)segment.WellKnownVariable; if (segment.WellKnownVariable != WellKnownVariable.None && _wellKnownVariables[knownVariableIndex].IsNotEmpty) { return(_data[_wellKnownVariables[knownVariableIndex]]); } return(_data.TryGetValue(segment, out var value) ? value : null); } [MethodImpl(MethodImplOptions.AggressiveInlining)] set { var knownVariableIndex = (int)segment.WellKnownVariable; if (segment.WellKnownVariable != WellKnownVariable.None) { _data.AddOrReplace(segment, value, out _wellKnownVariables[knownVariableIndex]); return; } _data.AddOrReplace(segment, value, out _); } }
public IteratorValues(BindingContext bindingContext) : this() { _data = bindingContext.ContextDataObject; _wellKnownVariables = bindingContext.WellKnownVariables; _data.AddOrReplace(ChainSegment.Value, null, out _wellKnownVariables[(int)ChainSegment.Value.WellKnownVariable]); _data.AddOrReplace(ChainSegment.First, BoxedValues.True, out _wellKnownVariables[(int)ChainSegment.First.WellKnownVariable]); _data.AddOrReplace(ChainSegment.Last, BoxedValues.False, out _wellKnownVariables[(int)ChainSegment.Last.WellKnownVariable]); _data.AddOrReplace(ChainSegment.Index, BoxedValues.Zero, out _wellKnownVariables[(int)ChainSegment.Index.WellKnownVariable]); }
public void AddOrReplace() { var objects = new object[245]; for (int i = 0; i < 245; i++) { objects[i] = new object(); } for (int iteration = 0; iteration < 5; iteration++) { for (int i = 0; i < 245; i++) { var key = objects[i]; var value = new object(); FixedSizeDictionary.AddOrReplace(key, value, out var index); Assert.True(FixedSizeDictionary.ContainsKey(index)); Assert.True(FixedSizeDictionary.ContainsKey(key)); Assert.True(FixedSizeDictionary.TryGetValue(key, out var actualValue)); Assert.Equal(value, actualValue); Assert.True(FixedSizeDictionary.TryGetValue(index, out actualValue)); Assert.Equal(value, actualValue); } } }
public ObjectIteratorValues(BindingContext bindingContext) : this() { var configuration = bindingContext.Configuration; _data = bindingContext.ContextDataObject; _supportLastInObjectIterations = configuration.Compatibility.SupportLastInObjectIterations; _wellKnownVariables = bindingContext.WellKnownVariables; if (!_supportLastInObjectIterations) { var undefined = UndefinedBindingResult.Create(ChainSegment.Last); _data.AddOrReplace(ChainSegment.Last, undefined, out _wellKnownVariables[(int)ChainSegment.Last.WellKnownVariable]); } else { _data.AddOrReplace(ChainSegment.Last, BoxedValues.False, out _wellKnownVariables[(int)ChainSegment.Last.WellKnownVariable]); } _data.AddOrReplace(ChainSegment.Key, null, out _wellKnownVariables[(int)ChainSegment.Key.WellKnownVariable]); _data.AddOrReplace(ChainSegment.Value, null, out _wellKnownVariables[(int)ChainSegment.Value.WellKnownVariable]); _data.AddOrReplace(ChainSegment.First, BoxedValues.True, out _wellKnownVariables[(int)ChainSegment.First.WellKnownVariable]); _data.AddOrReplace(ChainSegment.Index, BoxedValues.Zero, out _wellKnownVariables[(int)ChainSegment.Index.WellKnownVariable]); }