diff --git a/OpenDreamRuntime/DreamValue.cs b/OpenDreamRuntime/DreamValue.cs index 2c4deecd50..df51839060 100644 --- a/OpenDreamRuntime/DreamValue.cs +++ b/OpenDreamRuntime/DreamValue.cs @@ -455,11 +455,19 @@ public bool Equals(DreamValue other) { case DreamValueType.DreamObject: { Debug.Assert(_refValue is DreamObject or null, "Failed to cast _refValue to DreamObject"); Debug.Assert(other._refValue is DreamObject or null, "Failed to cast other._refValue to DreamObject"); - if (_refValue != null && Unsafe.As(_refValue).Deleted) + var thisObj = Unsafe.As(_refValue); + var otherObj = Unsafe.As(other._refValue); + if (thisObj != null && thisObj.Deleted) { _refValue = null; - if (other._refValue != null && Unsafe.As(other._refValue).Deleted) + thisObj = null; + } + + if (otherObj != null && otherObj.Deleted) { other._refValue = null; - break; + otherObj = null; + } + + return thisObj == otherObj; } } diff --git a/OpenDreamRuntime/Objects/Types/DreamList.cs b/OpenDreamRuntime/Objects/Types/DreamList.cs index 737bd22083..1c98194ba2 100644 --- a/OpenDreamRuntime/Objects/Types/DreamList.cs +++ b/OpenDreamRuntime/Objects/Types/DreamList.cs @@ -205,7 +205,9 @@ public virtual void AddValue(DreamValue value) { //Does not include associations public virtual bool ContainsValue(DreamValue value) { - for (int i = 0; i < _values.Count; i++) { + var count = _values.Count; + + for (int i = 0; i < count; i++) { if (_values[i].Equals(value)) return true; }