Skip to content

Commit

Permalink
[lua] speed up some array methods
Browse files Browse the repository at this point in the history
  • Loading branch information
jdonaldson committed Aug 23, 2017
1 parent 3764ebc commit f11ed3c
Showing 1 changed file with 10 additions and 12 deletions.
22 changes: 10 additions & 12 deletions std/lua/_std/Array.hx
Original file line number Diff line number Diff line change
Expand Up @@ -42,15 +42,15 @@ class Array<T> {

public function pop() : Null<T> {
if (length == 0 ) return null;
var rawlength = lua.Lua.rawget(cast this, 'length');
var ret = lua.Lua.rawget(cast this, rawlength-1);
lua.Lua.rawset(cast this, 'length', rawlength-1);
var ret = this[length-1];
this[length-1] = null;
length--;
return ret;
}
public function push(x : T) : Int {
lua.Lua.rawset(cast this,length,x);
lua.Lua.rawset(cast this,'length', length + 1);
return lua.Lua.rawget(cast this,'length');
lua.Lua.rawset(untyped this, length,x);
length++;
return length;
}
public function reverse() : Void {
var tmp:T;
Expand All @@ -65,9 +65,8 @@ class Array<T> {
public function shift() : Null<T> {
if (this.length == 0) return null;
var ret = this[0];
for (i in 0...length){
this[i] = this[i+1];
}
this[0] = this[1];
lua.Table.remove(untyped this,1);
this.length-=1;
return ret;
}
Expand Down Expand Up @@ -132,9 +131,8 @@ class Array<T> {
}

public function unshift( x : T ) : Void {
var len = length;
for (i in 0...len) this[len - i] = this[len - i - 1];
this[0] = x;
lua.Table.insert(untyped this, 0, x);
length++;
}

public inline function insert( pos : Int, x : T ) : Void {
Expand Down

0 comments on commit f11ed3c

Please sign in to comment.