提交 aec2077b authored 作者: Thomas Mueller's avatar Thomas Mueller

reuse empty arrays

上级 65e68391
...@@ -19,6 +19,7 @@ import org.h2.result.SearchRow; ...@@ -19,6 +19,7 @@ import org.h2.result.SearchRow;
import org.h2.table.Column; import org.h2.table.Column;
import org.h2.table.TableView; import org.h2.table.TableView;
import org.h2.util.IntArray; import org.h2.util.IntArray;
import org.h2.util.MemoryUtils;
import org.h2.util.ObjectArray; import org.h2.util.ObjectArray;
import org.h2.util.SmallLRUCache; import org.h2.util.SmallLRUCache;
import org.h2.value.Value; import org.h2.value.Value;
...@@ -98,7 +99,7 @@ public class ViewIndex extends BaseIndex { ...@@ -98,7 +99,7 @@ public class ViewIndex extends BaseIndex {
} }
public double getCost(Session session, int[] masks) throws SQLException { public double getCost(Session session, int[] masks) throws SQLException {
IntArray masksArray = new IntArray(masks == null ? new int[0] : masks); IntArray masksArray = new IntArray(masks == null ? MemoryUtils.EMPTY_INTS : masks);
CostElement cachedCost = costCache.get(masksArray); CostElement cachedCost = costCache.get(masksArray);
if (cachedCost != null) { if (cachedCost != null) {
long time = System.currentTimeMillis(); long time = System.currentTimeMillis();
......
...@@ -26,7 +26,7 @@ import org.h2.compress.LZFInputStream; ...@@ -26,7 +26,7 @@ import org.h2.compress.LZFInputStream;
import org.h2.compress.LZFOutputStream; import org.h2.compress.LZFOutputStream;
import org.h2.constant.ErrorCode; import org.h2.constant.ErrorCode;
import org.h2.message.Message; import org.h2.message.Message;
import org.h2.util.ByteUtils; import org.h2.util.MemoryUtils;
import org.h2.util.StringUtils; import org.h2.util.StringUtils;
/** /**
...@@ -44,10 +44,10 @@ public class CompressTool { ...@@ -44,10 +44,10 @@ public class CompressTool {
private byte[] getBuffer(int min) { private byte[] getBuffer(int min) {
if (min > MAX_BUFFER_SIZE) { if (min > MAX_BUFFER_SIZE) {
return ByteUtils.newBytes(min); return MemoryUtils.newBytes(min);
} }
if (cachedBuffer == null || cachedBuffer.length < min) { if (cachedBuffer == null || cachedBuffer.length < min) {
cachedBuffer = ByteUtils.newBytes(min); cachedBuffer = MemoryUtils.newBytes(min);
} }
return cachedBuffer; return cachedBuffer;
} }
...@@ -78,7 +78,7 @@ public class CompressTool { ...@@ -78,7 +78,7 @@ public class CompressTool {
Compressor compress = getCompressor(algorithm); Compressor compress = getCompressor(algorithm);
byte[] buff = getBuffer((len < 100 ? len + 100 : len) * 2); byte[] buff = getBuffer((len < 100 ? len + 100 : len) * 2);
int newLen = compress(in, in.length, compress, buff); int newLen = compress(in, in.length, compress, buff);
byte[] out = ByteUtils.newBytes(newLen); byte[] out = MemoryUtils.newBytes(newLen);
System.arraycopy(buff, 0, out, 0, newLen); System.arraycopy(buff, 0, out, 0, newLen);
return out; return out;
} }
...@@ -112,7 +112,7 @@ public class CompressTool { ...@@ -112,7 +112,7 @@ public class CompressTool {
try { try {
int len = readInt(in, 1); int len = readInt(in, 1);
int start = 1 + getLength(len); int start = 1 + getLength(len);
byte[] buff = ByteUtils.newBytes(len); byte[] buff = MemoryUtils.newBytes(len);
compress.expand(in, start, in.length - start, buff, 0, len); compress.expand(in, start, in.length - start, buff, 0, len);
return buff; return buff;
} catch (Exception e) { } catch (Exception e) {
......
Markdown 格式
0%
您添加了 0 到此讨论。请谨慎行事。
请先完成此评论的编辑!
注册 或者 后发表评论