Răsfoiți Sursa

don't use a while() to resize buffer (only in JS)

Nicolas Cannasse 8 ani în urmă
părinte
comite
58383db63f
2 a modificat fișierele cu 9 adăugiri și 4 ștergeri
  1. 5 3
      hxd/FloatBuffer.hx
  2. 4 1
      hxd/IndexBuffer.hx

+ 5 - 3
hxd/FloatBuffer.hx

@@ -30,6 +30,7 @@ abstract FloatBuffer(InnerData) {
 		this = new InnerData(length);
 		this = new InnerData(length);
 		#else
 		#else
 		this = new InnerData();
 		this = new InnerData();
+		if( length > 0 ) grow(length);
 		#end
 		#end
 	}
 	}
 
 
@@ -44,8 +45,10 @@ abstract FloatBuffer(InnerData) {
 	public inline function grow( v : Int ) {
 	public inline function grow( v : Int ) {
 		#if flash
 		#if flash
 		if( v > this.length ) this.length = v;
 		if( v > this.length ) this.length = v;
+		#elseif js
+		while( v < this.length ) this.push(0.);
 		#else
 		#else
-		while( this.length < v ) this.push(0.);
+		if( v > this.length ) this[v - 1] = 0.;
 		#end
 		#end
 	}
 	}
 
 
@@ -53,8 +56,7 @@ abstract FloatBuffer(InnerData) {
 		#if flash
 		#if flash
 		this.length = v;
 		this.length = v;
 		#else
 		#else
-		while( this.length < v ) this.push(0.);
-		if( this.length > v ) this.splice(v, this.length - v);
+		if( this.length > v ) this.splice(v, this.length - v) else grow(v);
 		#end
 		#end
 	}
 	}
 
 

+ 4 - 1
hxd/IndexBuffer.hx

@@ -30,6 +30,7 @@ abstract IndexBuffer(InnerData) {
 		this = new InnerData(length);
 		this = new InnerData(length);
 		#else
 		#else
 		this = new InnerData();
 		this = new InnerData();
+		if( length > 0 ) grow(length);
 		#end
 		#end
 	}
 	}
 
 
@@ -44,8 +45,10 @@ abstract IndexBuffer(InnerData) {
 	public inline function grow( v : Int ) {
 	public inline function grow( v : Int ) {
 		#if flash
 		#if flash
 		if( v > this.length ) this.length = v;
 		if( v > this.length ) this.length = v;
-		#else
+		#elseif js
 		while( this.length < v ) this.push(0);
 		while( this.length < v ) this.push(0);
+		#else
+		if( v > this.length ) this[v - 1] = 0;
 		#end
 		#end
 	}
 	}