Răsfoiți Sursa

faster bytes unserializing (no need for BytesBuffer)

Nicolas Cannasse 16 ani în urmă
părinte
comite
95baf53484
2 a modificat fișierele cu 9 adăugiri și 7 ștergeri
  1. 1 0
      doc/CHANGES.txt
  2. 8 7
      std/haxe/Unserializer.hx

+ 1 - 0
doc/CHANGES.txt

@@ -7,6 +7,7 @@ TODO :
 	flash9 : fixed get_full_path error with -D fdb
 	flash9 : fixed get_full_path error with -D fdb
 	js : fixed Array.remove on IE
 	js : fixed Array.remove on IE
 	flash8 : removed extra empty AS3 tag (causing some issue with F8 loadMovie)
 	flash8 : removed extra empty AS3 tag (causing some issue with F8 loadMovie)
+	improved speed of Bytes unserializing (no need for BytesBuffer)
 
 
 2009-03-22: 2.03
 2009-03-22: 2.03
 	optimized Type.enumEq : use index instead of tag comparison for neko/flash9/php
 	optimized Type.enumEq : use index instead of tag comparison for neko/flash9/php

+ 8 - 7
std/haxe/Unserializer.hx

@@ -310,29 +310,30 @@ class Unserializer {
 				codes = initCodes();
 				codes = initCodes();
 				CODES = codes;
 				CODES = codes;
 			}
 			}
-			var b = new haxe.io.BytesBuffer();
 			var i = pos;
 			var i = pos;
 			var rest = len & 3;
 			var rest = len & 3;
+			var size = (len >> 2) * 3 + ((rest >= 2) ? rest - 1 : 0);
 			var max = i + (len - rest);
 			var max = i + (len - rest);
+			var bytes = haxe.io.Bytes.alloc(size);
+			var bpos = 0;
 			while( i < max ) {
 			while( i < max ) {
 				var c1 = codes[untyped buf.cca(i++)];
 				var c1 = codes[untyped buf.cca(i++)];
 				var c2 = codes[untyped buf.cca(i++)];
 				var c2 = codes[untyped buf.cca(i++)];
-				b.addByte((c1 << 2) | (c2 >> 4));
+				bytes.set(bpos++,(c1 << 2) | (c2 >> 4));
 				var c3 = codes[untyped buf.cca(i++)];
 				var c3 = codes[untyped buf.cca(i++)];
-				b.addByte(((c2 << 4) | (c3 >> 2)) #if !flash9 & 0xFF #end );
+				bytes.set(bpos++,(c2 << 4) | (c3 >> 2));
 				var c4 = codes[untyped buf.cca(i++)];
 				var c4 = codes[untyped buf.cca(i++)];
-				b.addByte(((c3 << 6) | c4) #if !flash9 & 0xFF #end );
+				bytes.set(bpos++,(c3 << 6) | c4);
 			}
 			}
 			if( rest >= 2 ) {
 			if( rest >= 2 ) {
 				var c1 = codes[untyped buf.cca(i++)];
 				var c1 = codes[untyped buf.cca(i++)];
 				var c2 = codes[untyped buf.cca(i++)];
 				var c2 = codes[untyped buf.cca(i++)];
-				b.addByte((c1 << 2) | (c2 >> 4));
+				bytes.set(bpos++,(c1 << 2) | (c2 >> 4));
 				if( rest == 3 ) {
 				if( rest == 3 ) {
 					var c3 = codes[untyped buf.cca(i++)];
 					var c3 = codes[untyped buf.cca(i++)];
-					b.addByte(((c2 << 4) | (c3 >> 2)) #if !flash9 & 0xFF #end );
+					bytes.set(bpos++,(c2 << 4) | (c3 >> 2));
 				}
 				}
 			}
 			}
-			var bytes = b.getBytes();
  			#end
  			#end
 			pos += len;
 			pos += len;
 			cache.push(bytes);
 			cache.push(bytes);