Kaynağa Gözat

added hl.Api.comparePointer (require hl 1.6)
fixed ArrayDyn comparison wrt the underlying array object.

Nicolas Cannasse 7 yıl önce
ebeveyn
işleme
be1a102a91
3 değiştirilmiş dosya ile 9 ekleme ve 1 silme
  1. 1 0
      std/hl/Api.hx
  2. 4 1
      std/hl/_std/String.hx
  3. 4 0
      std/hl/types/ArrayDyn.hx

+ 1 - 0
std/hl/Api.hx

@@ -37,5 +37,6 @@ extern class Api {
 	@:hlNative("std", "set_error_handler") static function setErrorHandler( v : Dynamic -> Void ) : Void;
 	@:hlNative("std", "breakpoint") static function breakPoint() : Void;
 	@:hlNative("std", "sys_is64") static function is64() : Bool;
+	@:hlNative("std", "ptr_compare") static function comparePointer( a : Dynamic, b : Dynamic ) : Int;
 
 }

+ 4 - 1
std/hl/_std/String.hx

@@ -182,7 +182,10 @@ class String {
 		return bytes;
 	}
 
-	@:keep function __compare( s : String ) : Int {
+	@:keep function __compare( v : Dynamic ) : Int {
+		var s = Std.instance(v, String);
+		if( s == null )
+			return hl.Api.comparePointer(this, v);
 		var v = bytes.compare(0, s.bytes, 0, (length < s.length ? length : s.length) << 1);
 		return v == 0 ? length - s.length : v;
 	}

+ 4 - 0
std/hl/types/ArrayDyn.hx

@@ -217,6 +217,10 @@ class ArrayDyn extends ArrayAccess {
 		return null;
 	}
 
+	@:keep function __compare( a : Dynamic ) : Int {
+		return a == this || a == array ? 0 : hl.Api.comparePointer(this,a);
+	}
+
 	public static function alloc( a : ArrayBase, allowReinterpret = false ) : ArrayDyn {
 		var arr : ArrayDyn = untyped $new(ArrayDyn);
 		arr.array = a;