diff --git a/README.html b/README.html
index efed2652..30d9f83e 100644
--- a/README.html
+++ b/README.html
@@ -821,6 +821,7 @@ and LuaForge:
| 3.0-alpha3 |
- Fix bug 3597515 memory leak due to string caching by simplifying caching logic.
+- Fix bug 3565008 so that short substrings are backed by short arrays.
|
diff --git a/src/core/org/luaj/vm2/LoadState.java b/src/core/org/luaj/vm2/LoadState.java
index f753394a..46c27287 100644
--- a/src/core/org/luaj/vm2/LoadState.java
+++ b/src/core/org/luaj/vm2/LoadState.java
@@ -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
diff --git a/src/core/org/luaj/vm2/LuaString.java b/src/core/org/luaj/vm2/LuaString.java
index db4d4891..b7cc6641 100644
--- a/src/core/org/luaj/vm2/LuaString.java
+++ b/src/core/org/luaj/vm2/LuaString.java
@@ -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() {