Fix bug 3565008 so that short substrings are backed by short arrays.

This commit is contained in:
James Roseborough
2013-01-26 19:53:50 +00:00
parent fae55ba56a
commit f1b421d25c
3 changed files with 18 additions and 6 deletions

View File

@@ -821,6 +821,7 @@ and LuaForge:
<tr valign="top"><td>&nbsp;&nbsp;<b>3.0-alpha3</b></td><td><ul>
<li>Fix bug 3597515 memory leak due to string caching by simplifying caching logic.</li>
<li>Fix bug 3565008 so that short substrings are backed by short arrays.</li>
</ul></td></tr>
</table></td></tr></table>

View File

@@ -369,7 +369,7 @@ public class LoadState {
}
/**
* Load lua in either binary or text form from an input stream.
* Load lua in either binary or text from an input stream.
* @param firstByte the first byte of the input stream
* @param stream InputStream to read, after having read the first byte already
* @param name Name to apply to the loaded chunk
@@ -390,6 +390,19 @@ public class LoadState {
}
}
/**
* Load lua in the default mode "bt" from an input stream.
* @param firstByte the first byte of the input stream
* @param stream InputStream to read, after having read the first byte already
* @param name Name to apply to the loaded chunk
* @return {@link Prototype} that was loaded
* @throws IllegalArgumentException if the signature is bac
* @throws IOException if an IOException occurs
*/
public static LuaFunction load( InputStream stream, String name, LuaValue env ) throws IOException {
return load(stream, name, "bt", env);
}
/**
* Load lua thought to be a binary chunk from its first byte from an input stream.
* @param firstByte the first byte of the input stream

View File

@@ -26,8 +26,6 @@ import java.io.ByteArrayInputStream;
import java.io.DataOutputStream;
import java.io.IOException;
import java.io.InputStream;
import java.lang.ref.WeakReference;
import java.util.Hashtable;
import org.luaj.vm2.lib.MathLib;
import org.luaj.vm2.lib.StringLib;
@@ -131,7 +129,7 @@ public class LuaString extends LuaValue {
// Short result relative to the source. Copy only the bytes that are actually to be used.
final byte[] b = new byte[len];
System.arraycopy(bytes, off, b, 0, len);
return valueOf(bytes);
return valueOf(b, 0, len); // To possibly use cached version.
}
}
@@ -257,7 +255,7 @@ public class LuaString extends LuaValue {
byte[] b = new byte[lhs.m_length+this.m_length];
System.arraycopy(lhs.m_bytes, lhs.m_offset, b, 0, lhs.m_length);
System.arraycopy(this.m_bytes, this.m_offset, b, lhs.m_length, this.m_length);
return new LuaString(b, 0, b.length);
return valueOf(b, 0, b.length);
}
// string comparison
@@ -370,7 +368,7 @@ public class LuaString extends LuaValue {
}
public LuaString substring( int beginIndex, int endIndex ) {
return new LuaString( m_bytes, m_offset + beginIndex, endIndex - beginIndex );
return valueOf( m_bytes, m_offset + beginIndex, endIndex - beginIndex );
}
public int hashCode() {