/// <summary> /// Set a value by name. If no scope has it, then it will be defined in the innermost scope /// </summary> public void SetValue(uint crushedName, double newValue) { unchecked { for (int i = _currentScopeIdx; i >= 0; i--) { var current = _scopes[i]; if (!current.Get(crushedName, out var oldValue)) { continue; } // ReSharper disable once CompareOfFloatsByEqualityOperator if (oldValue == newValue) { return; } if (NanTags.IsAllocated(oldValue)) { PotentialGarbage.Add(newValue); } current.Put(crushedName, newValue, true); return; } // nothing already exists to replace _scopes[_currentScopeIdx].Add(crushedName, newValue); } }
/// <summary> /// Remove innermost scope, and drop back to the previous one /// </summary> public void DropScope() { var last = _scopes[_currentScopeIdx]; _scopes[_currentScopeIdx] = null; _currentScopeIdx--; // this could be done on another thread foreach (var token in last.Values) { if (NanTags.IsAllocated(token)) { PotentialGarbage.Add(token); } } }