|
@@ -6,16 +6,20 @@ package haxe.io;
|
|
|
**/
|
|
|
class FPHelper {
|
|
|
|
|
|
- #if !(java || cs)
|
|
|
+ #if neko_v21
|
|
|
+ // stored in helper
|
|
|
+ #elseif neko
|
|
|
+ static var i64tmp = new neko.vm.Tls<Int64>();
|
|
|
+ #elseif !(java || cs)
|
|
|
static var i64tmp = Int64.ofInt(0);
|
|
|
#end
|
|
|
|
|
|
#if neko
|
|
|
#if neko_v21
|
|
|
- static var helper = neko.NativeArray.alloc(2);
|
|
|
+ static var helpers = new neko.vm.Tls<neko.NativeArray<Dynamic>>();
|
|
|
#else
|
|
|
- static var helperf = neko.NativeString.alloc(4);
|
|
|
- static var helperd = neko.NativeString.alloc(8);
|
|
|
+ static var helperf = new neko.vm.Tls<neko.NativeString>();
|
|
|
+ static var helperd = new neko.vm.Tls<neko.NativeString>();
|
|
|
static var _float_of_bytes = neko.Lib.load("std","float_of_bytes",2);
|
|
|
static var _double_of_bytes = neko.Lib.load("std","double_of_bytes",2);
|
|
|
static var _float_bytes = neko.Lib.load("std","float_bytes",2);
|
|
@@ -45,7 +49,9 @@ class FPHelper {
|
|
|
#if neko_v21
|
|
|
return untyped $itof(i);
|
|
|
#else
|
|
|
- var helper = helperf;
|
|
|
+ var helper = helperf.value;
|
|
|
+ if( helper == null )
|
|
|
+ helperf.value = helper = neko.NativeString.alloc(4);
|
|
|
untyped $sset(helper,0,i&0xFF);
|
|
|
untyped $sset(helper,1,(i>>8)&0xFF);
|
|
|
untyped $sset(helper,2,(i>>16)&0xFF);
|
|
@@ -138,7 +144,9 @@ class FPHelper {
|
|
|
#if neko_v21
|
|
|
return untyped $itod(low,high);
|
|
|
#else
|
|
|
- var helper = helperd;
|
|
|
+ var helper = helperd.value;
|
|
|
+ if( helper == null )
|
|
|
+ helperd.value = helper = neko.NativeString.alloc(8);
|
|
|
untyped $sset(helper,0,low&0xFF);
|
|
|
untyped $sset(helper,1,(low>>8)&0xFF);
|
|
|
untyped $sset(helper,2,(low>>16)&0xFF);
|
|
@@ -198,20 +206,28 @@ class FPHelper {
|
|
|
/**
|
|
|
Returns an Int64 representing the bytes representation of the double precision IEEE float value.
|
|
|
WARNING : for performance reason, the same Int64 value might be reused every time. Copy its low/high values before calling again.
|
|
|
+ We still ensure that this is safe to use in a multithread environment
|
|
|
**/
|
|
|
- #if neko_v21 inline #end
|
|
|
public static function doubleToI64( v : Float ) : Int64 {
|
|
|
#if neko
|
|
|
#if neko_v21
|
|
|
- var helper = helper, i64 = i64tmp;
|
|
|
- untyped $dtoi(v,helper);
|
|
|
+ var helper = helpers.value;
|
|
|
+ if( helper == null ) {
|
|
|
+ helpers.value = helper = neko.NativeArray.alloc(2);
|
|
|
+ helper[0] = neko.NativeArray.alloc(2);
|
|
|
+ helper[1] = haxe.Int64.ofInt(0);
|
|
|
+ }
|
|
|
+ var i64 : haxe.Int64 = helper[1], int2 = helper[0];
|
|
|
+ untyped $dtoi(v,int2);
|
|
|
@:privateAccess {
|
|
|
- i64.low = helper[0];
|
|
|
- i64.high = helper[1];
|
|
|
+ i64.low = int2[0];
|
|
|
+ i64.high = int2[1];
|
|
|
}
|
|
|
return i64;
|
|
|
#else
|
|
|
- var r = _double_bytes(v,false), i64 = i64tmp;
|
|
|
+ var r = _double_bytes(v,false), i64 = i64tmp.value;
|
|
|
+ if( i64 == null )
|
|
|
+ i64 = i64tmp.value = haxe.Int64.ofInt(0);
|
|
|
@:privateAccess {
|
|
|
i64.low = untyped $sget(r,0) | ($sget(r,1)<<8) | ($sget(r,2)<<16) | ($sget(r,3)<<24);
|
|
|
i64.high = untyped $sget(r,4) | ($sget(r,5)<<8) | ($sget(r,6)<<16) | ($sget(r,7)<<24);
|