Przeglądaj źródła

[cs] Skip value type check, which is too heavy. See #4301

Since a value type will never be `ReferenceEquals` to null,
we can skip the call altogether and just check if it equals to null
Cauê Waneck 10 lat temu
rodzic
commit
9954e860c7
1 zmienionych plików z 12 dodań i 7 usunięć
  1. 12 7
      std/cs/internal/Null.hx

+ 12 - 7
std/cs/internal/Null.hx

@@ -55,16 +55,21 @@ package cs.internal;
 	@:readOnly public var hasValue(default,never):Bool;
 
 	@:functionCode('
-			if (!haxe.lang.NullMetadata<T>.IsValueType && System.Object.ReferenceEquals(v, default(T)))
-			{
-				hasValue = false;
-			}
-
-			this.@value = v;
-			this.hasValue = hasValue;
+		object obj = null;
+		if (hasValue && System.Object.ReferenceEquals(v, obj))
+		{
+			hasValue = false;
+		}
+		this.value = v;
+		this.hasValue = hasValue;
 	')
 	public function new(v:T, hasValue:Bool)
 	{
+		var obj:Dynamic = null;
+		if (hasValue && cs.system.Object.ReferenceEquals(v, obj))
+		{
+			hasValue = false;
+		}
 		untyped this.value = v;
 		untyped this.hasValue = hasValue;
 	}