Procházet zdrojové kódy

changed hl BytesData definition

Nicolas Cannasse před 9 roky
rodič
revize
dab467234b

+ 14 - 3
std/haxe/io/BytesData.hx

@@ -39,14 +39,25 @@ package haxe.io;
 	typedef BytesData = js.html.ArrayBuffer;
 #elseif hl
 	class BytesDataImpl {
-		public var b : hl.types.Bytes;
+		public var bytes : hl.types.Bytes;
 		public var length : Int;
 		public function new(b,length) {
-			this.b = b;
+			this.bytes = b;
 			this.length = length;
 		}
 	}
-	typedef BytesData = BytesDataImpl;
+	@:forward(bytes,length)
+	abstract BytesDataAbstract(BytesDataImpl) {
+		public inline function new(b, length) {
+			this = new BytesDataImpl(b, length);
+		}
+		@:arrayAccess inline function get(i:Int) return this.bytes[i];
+		@:arrayAccess inline function set(i:Int,v:Int) return this.bytes[i] = v;
+		@:to inline function toBytes() : hl.types.Bytes {
+			return this == null ? null : this.bytes;
+		}
+	}
+	typedef BytesData = BytesDataAbstract;
 #else
 	typedef BytesData = Array<Int>;
 #end

+ 1 - 1
std/haxe/io/Output.hx

@@ -69,7 +69,7 @@ class Output {
 			#elseif cpp
 				writeByte(untyped b[pos]);
 			#elseif hl
-				writeByte(@:privateAccess b.b[pos]);
+				writeByte(b[pos]);
 			#else
 				writeByte(untyped b[pos]);
 			#end

+ 2 - 2
std/hl/_std/haxe/io/Bytes.hx

@@ -165,11 +165,11 @@ class Bytes {
 	}
 
 	public static function ofData( b : BytesData ) : Bytes {
-		return new Bytes(b.b,b.length);
+		return new Bytes(b.bytes,b.length);
 	}
 
 	public inline static function fastGet( b : BytesData, pos : Int ) : Int {
-		return b.b[pos];
+		return b[pos];
 	}
 
 }

+ 1 - 1
std/hl/_std/sys/io/FileInput.hx

@@ -38,7 +38,7 @@ import sys.io.File;
 
 	public override function readBytes( s : haxe.io.Bytes, p : Int, l : Int ) : Int {
 		if( p < 0 || l < 0 || p + l > s.length ) throw haxe.io.Error.OutsideBounds;
-		var v = file_read(__f, s.getData().b, p, l);
+		var v = file_read(__f, s.getData(), p, l);
 		if( v <= 0 ) throw new haxe.io.Eof();
 		return v;
 	}

+ 1 - 1
std/hl/_std/sys/io/FileOutput.hx

@@ -36,7 +36,7 @@ import sys.io.File;
 
 	public override function writeBytes( s : haxe.io.Bytes, p : Int, l : Int ) : Int {
 		if( p < 0 || l < 0 || p + l > s.length ) throw haxe.io.Error.OutsideBounds;
-		var v = file_write(__f, s.getData().b, p, l);
+		var v = file_write(__f, s.getData(), p, l);
 		if( v <= 0 ) throw new haxe.io.Eof();
 		return v;
 	}