Improve __concat
This commit is contained in:
@@ -236,14 +236,14 @@ public class LuaClosure extends LuaFunction {
|
||||
b = i>>>23;
|
||||
c = (i>>14)&0x1ff;
|
||||
{
|
||||
LuaValue r = stack[c-1].concat(stack[c]);
|
||||
if ( (c-=2) >= b ) {
|
||||
Buffer sb = r.buffer();
|
||||
while ( c>=b )
|
||||
sb = stack[c--].concat(sb);
|
||||
r = sb.value();
|
||||
if ( c > b+1 ) {
|
||||
Buffer sb = stack[c].buffer();
|
||||
while ( --c>=b )
|
||||
sb = stack[c].concat(sb);
|
||||
stack[a] = sb.value();
|
||||
} else {
|
||||
stack[a] = stack[c-1].concat(stack[c]);
|
||||
}
|
||||
stack[a] = r;
|
||||
}
|
||||
continue;
|
||||
|
||||
|
||||
@@ -64,6 +64,7 @@ public class LuaNumber extends LuaValue {
|
||||
|
||||
public LuaValue concat(LuaValue rhs) { return rhs.concatTo(this); }
|
||||
public Buffer concat(Buffer rhs) { return rhs.prepend(this.strvalue()); }
|
||||
public LuaValue concatTo(LuaValue lhs) { return lhs.concaterror(); }
|
||||
public LuaValue concatTo(LuaNumber lhs) { return strvalue().concatTo(lhs.strvalue()); }
|
||||
public LuaValue concatTo(LuaString lhs) { return strvalue().concatTo(lhs); }
|
||||
|
||||
|
||||
@@ -157,6 +157,7 @@ public class LuaString extends LuaValue {
|
||||
// concatenation
|
||||
public LuaValue concat(LuaValue rhs) { return rhs.concatTo(this); }
|
||||
public Buffer concat(Buffer rhs) { return rhs.prepend(this); }
|
||||
public LuaValue concatTo(LuaValue lhs) { return lhs.concaterror(); }
|
||||
public LuaValue concatTo(LuaNumber lhs) { return concatTo(lhs.strvalue()); }
|
||||
public LuaValue concatTo(LuaString lhs) {
|
||||
byte[] b = new byte[lhs.m_length+this.m_length];
|
||||
|
||||
@@ -179,6 +179,7 @@ public class LuaValue extends Varargs {
|
||||
protected LuaValue aritherror(String fun) { throw new LuaError("attempt to perform arithmetic '"+fun+"' on "+typename()); }
|
||||
protected LuaValue compareerror(String rhs) { throw new LuaError("attempt to compare "+typename()+" with "+rhs); }
|
||||
protected LuaValue compareerror(LuaValue rhs) { throw new LuaError("attempt to compare "+typename()+" with "+rhs.typename()); }
|
||||
protected LuaValue concaterror() { throw new LuaError("attempt to concatenate "+typename()); }
|
||||
|
||||
// table operations
|
||||
public LuaValue get( LuaValue key ) { return gettable(this,key); }
|
||||
@@ -344,18 +345,17 @@ public class LuaValue extends Varargs {
|
||||
public int strcmp( LuaString rhs ) { error("attempt to compare "+typename()); return 0; }
|
||||
|
||||
// concatenation
|
||||
public LuaValue concat(LuaValue rhs) { return this.concatmt(rhs); }
|
||||
public LuaValue concatTo(LuaNumber lhs) { return lhs.concatmt(this); }
|
||||
public LuaValue concatTo(LuaString lhs) { return lhs.concatmt(this); }
|
||||
public LuaValue concat(LuaValue rhs) { return rhs.concatTo(this); }
|
||||
public LuaValue concatTo(LuaValue lhs) { return lhs.concatmt(this); }
|
||||
public LuaValue concatTo(LuaNumber lhs) { return concaterror(); }
|
||||
public LuaValue concatTo(LuaString lhs) { return concaterror(); }
|
||||
public Buffer buffer() { return new Buffer(this); }
|
||||
public Buffer concat(Buffer rhs) {
|
||||
return rhs.setvalue(checkmetatag(CONCAT,"attempt to concatenate ").call(this, rhs.value()));
|
||||
}
|
||||
public Buffer concat(Buffer rhs) { return rhs.setvalue(concat(rhs.value())); }
|
||||
public LuaValue concatmt(LuaValue rhs) {
|
||||
LuaValue h=metatag(CONCAT);
|
||||
LuaValue v=this;
|
||||
if ( h.isnil() || (h=(v=rhs).metatag(CONCAT)).isnil())
|
||||
v.typerror("attempt to concatenate ");
|
||||
if ( h.isnil() && (h=(v=rhs).metatag(CONCAT)).isnil())
|
||||
return v.concaterror();
|
||||
return h.call(this,rhs);
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user