Skip to content
项目
群组
代码片段
帮助
正在加载...
帮助
为 GitLab 提交贡献
登录/注册
切换导航
H
h2database
项目
项目
详情
活动
周期分析
仓库
仓库
文件
提交
分支
标签
贡献者
分枝图
比较
统计图
议题
0
议题
0
列表
看板
标记
里程碑
合并请求
0
合并请求
0
CI / CD
CI / CD
流水线
作业
计划
统计图
Wiki
Wiki
代码片段
代码片段
成员
成员
折叠边栏
关闭边栏
活动
分枝图
统计图
创建新议题
作业
提交
议题看板
打开侧边栏
Administrator
h2database
Commits
65e68391
提交
65e68391
authored
7月 13, 2009
作者:
Thomas Mueller
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
reuse empty arrays
上级
2e2a137a
显示空白字符变更
内嵌
并排
正在显示
14 个修改的文件
包含
72 行增加
和
43 行删除
+72
-43
LZFInputStream.java
h2/src/main/org/h2/compress/LZFInputStream.java
+2
-2
Function.java
h2/src/main/org/h2/expression/Function.java
+1
-2
BtreeNode.java
h2/src/main/org/h2/index/BtreeNode.java
+2
-1
JdbcConnection.java
h2/src/main/org/h2/jdbc/JdbcConnection.java
+4
-3
LogFile.java
h2/src/main/org/h2/log/LogFile.java
+3
-3
PgServerThread.java
h2/src/main/org/h2/server/pg/PgServerThread.java
+3
-3
WebThread.java
h2/src/main/org/h2/server/web/WebThread.java
+1
-2
ByteUtils.java
h2/src/main/org/h2/util/ByteUtils.java
+0
-19
MemoryUtils.java
h2/src/main/org/h2/util/MemoryUtils.java
+45
-0
Resources.java
h2/src/main/org/h2/util/Resources.java
+1
-1
Transfer.java
h2/src/main/org/h2/value/Transfer.java
+2
-2
ValueBytes.java
h2/src/main/org/h2/value/ValueBytes.java
+2
-1
ValueJavaObject.java
h2/src/main/org/h2/value/ValueJavaObject.java
+2
-1
ValueLob.java
h2/src/main/org/h2/value/ValueLob.java
+4
-3
没有找到文件。
h2/src/main/org/h2/compress/LZFInputStream.java
浏览文件 @
65e68391
...
...
@@ -9,7 +9,7 @@ package org.h2.compress;
import
java.io.IOException
;
import
java.io.InputStream
;
import
org.h2.util.
Byte
Utils
;
import
org.h2.util.
Memory
Utils
;
/**
* An input stream to read from an LZF stream.
...
...
@@ -32,7 +32,7 @@ public class LZFInputStream extends InputStream {
}
private
byte
[]
ensureSize
(
byte
[]
buff
,
int
len
)
{
return
buff
==
null
||
buff
.
length
<
len
?
Byte
Utils
.
newBytes
(
len
)
:
buff
;
return
buff
==
null
||
buff
.
length
<
len
?
Memory
Utils
.
newBytes
(
len
)
:
buff
;
}
private
void
fillBuffer
()
throws
IOException
{
...
...
h2/src/main/org/h2/expression/Function.java
浏览文件 @
65e68391
...
...
@@ -41,7 +41,6 @@ import org.h2.table.TableFilter;
import
org.h2.tools.CompressTool
;
import
org.h2.tools.Csv
;
import
org.h2.util.AutoCloseInputStream
;
import
org.h2.util.ByteUtils
;
import
org.h2.util.DateTimeIso8601Utils
;
import
org.h2.util.DateTimeUtils
;
import
org.h2.util.FileUtils
;
...
...
@@ -1172,7 +1171,7 @@ public class Function extends Expression implements FunctionCall {
private
byte
[]
getPaddedArrayCopy
(
byte
[]
data
,
int
blockSize
)
{
int
size
=
MathUtils
.
roundUp
(
data
.
length
,
blockSize
);
byte
[]
newData
=
Byte
Utils
.
newBytes
(
size
);
byte
[]
newData
=
Memory
Utils
.
newBytes
(
size
);
System
.
arraycopy
(
data
,
0
,
newData
,
0
,
data
.
length
);
return
newData
;
}
...
...
h2/src/main/org/h2/index/BtreeNode.java
浏览文件 @
65e68391
...
...
@@ -18,6 +18,7 @@ import org.h2.store.DataPage;
import
org.h2.store.DiskFile
;
import
org.h2.table.Column
;
import
org.h2.util.IntArray
;
import
org.h2.util.MemoryUtils
;
import
org.h2.util.ObjectArray
;
import
org.h2.value.Value
;
...
...
@@ -37,7 +38,7 @@ public class BtreeNode extends BtreePage {
BtreeNode
(
BtreeIndex
index
,
DataPage
s
)
throws
SQLException
{
super
(
index
);
int
len
=
s
.
readInt
();
int
[]
array
=
new
int
[
len
]
;
int
[]
array
=
MemoryUtils
.
newInts
(
len
)
;
for
(
int
i
=
0
;
i
<
array
.
length
;
i
++)
{
array
[
i
]
=
s
.
readInt
();
}
...
...
h2/src/main/org/h2/jdbc/JdbcConnection.java
浏览文件 @
65e68391
...
...
@@ -33,6 +33,7 @@ import org.h2.message.Message;
import
org.h2.message.Trace
;
import
org.h2.message.TraceObject
;
import
org.h2.result.ResultInterface
;
import
org.h2.util.MemoryUtils
;
import
org.h2.util.ObjectUtils
;
import
org.h2.value.Value
;
import
org.h2.value.ValueInt
;
...
...
@@ -1403,7 +1404,7 @@ public class JdbcConnection extends TraceObject implements Connection {
int
id
=
getNextId
(
TraceObject
.
CLOB
);
debugCodeAssign
(
"Clob"
,
TraceObject
.
CLOB
,
id
,
"createClob()"
);
checkClosedForWrite
();
ValueLob
v
=
ValueLob
.
createSmallLob
(
Value
.
CLOB
,
new
byte
[
0
]
);
ValueLob
v
=
ValueLob
.
createSmallLob
(
Value
.
CLOB
,
MemoryUtils
.
EMPTY_BYTES
);
return
new
JdbcClob
(
this
,
v
,
id
);
}
catch
(
Exception
e
)
{
throw
logAndConvert
(
e
);
...
...
@@ -1420,7 +1421,7 @@ public class JdbcConnection extends TraceObject implements Connection {
int
id
=
getNextId
(
TraceObject
.
BLOB
);
debugCodeAssign
(
"Blob"
,
TraceObject
.
BLOB
,
id
,
"createClob()"
);
checkClosedForWrite
();
ValueLob
v
=
ValueLob
.
createSmallLob
(
Value
.
BLOB
,
new
byte
[
0
]
);
ValueLob
v
=
ValueLob
.
createSmallLob
(
Value
.
BLOB
,
MemoryUtils
.
EMPTY_BYTES
);
return
new
JdbcBlob
(
this
,
v
,
id
);
}
catch
(
Exception
e
)
{
throw
logAndConvert
(
e
);
...
...
@@ -1438,7 +1439,7 @@ public class JdbcConnection extends TraceObject implements Connection {
int id = getNextId(TraceObject.CLOB);
debugCodeAssign("NClob", TraceObject.CLOB, id, "createNClob()");
checkClosedForWrite();
ValueLob v = ValueLob.createSmallLob(Value.CLOB,
new byte[0]
);
ValueLob v = ValueLob.createSmallLob(Value.CLOB,
ByteUtils.EMPTY
);
return new JdbcClob(this, v, id);
} catch (Exception e) {
throw logAndConvert(e);
...
...
h2/src/main/org/h2/log/LogFile.java
浏览文件 @
65e68391
...
...
@@ -21,9 +21,9 @@ import org.h2.store.DiskFile;
import
org.h2.store.FileStore
;
import
org.h2.store.Record
;
import
org.h2.store.Storage
;
import
org.h2.util.ByteUtils
;
import
org.h2.util.FileUtils
;
import
org.h2.util.MathUtils
;
import
org.h2.util.MemoryUtils
;
import
org.h2.util.ObjectArray
;
/**
...
...
@@ -220,7 +220,7 @@ public class LogFile {
// Math.abs(Integer.MIN_VALUE) == Integer.MIN_VALUE
s
.
reset
();
}
else
{
byte
[]
b2
=
Byte
Utils
.
newBytes
(
blocks
*
BLOCK_SIZE
);
byte
[]
b2
=
Memory
Utils
.
newBytes
(
blocks
*
BLOCK_SIZE
);
System
.
arraycopy
(
buff
,
0
,
b2
,
0
,
BLOCK_SIZE
);
buff
=
b2
;
file
.
readFully
(
buff
,
BLOCK_SIZE
,
blocks
*
BLOCK_SIZE
-
BLOCK_SIZE
);
...
...
@@ -308,7 +308,7 @@ public class LogFile {
break
;
}
int
sumLength
=
in
.
readInt
();
byte
[]
summary
=
Byte
Utils
.
newBytes
(
sumLength
);
byte
[]
summary
=
Memory
Utils
.
newBytes
(
sumLength
);
if
(
sumLength
>
0
)
{
in
.
read
(
summary
,
0
,
sumLength
);
}
...
...
h2/src/main/org/h2/server/pg/PgServerThread.java
浏览文件 @
65e68391
...
...
@@ -34,9 +34,9 @@ import org.h2.constant.SysProperties;
import
org.h2.engine.ConnectionInfo
;
import
org.h2.jdbc.JdbcConnection
;
import
org.h2.message.Message
;
import
org.h2.util.ByteUtils
;
import
org.h2.util.IOUtils
;
import
org.h2.util.JdbcUtils
;
import
org.h2.util.MemoryUtils
;
import
org.h2.util.New
;
import
org.h2.util.Resources
;
import
org.h2.util.ScriptReader
;
...
...
@@ -133,7 +133,7 @@ public class PgServerThread implements Runnable {
}
int
len
=
dataInRaw
.
readInt
();
len
-=
4
;
byte
[]
data
=
Byte
Utils
.
newBytes
(
len
);
byte
[]
data
=
Memory
Utils
.
newBytes
(
len
);
dataInRaw
.
readFully
(
data
,
0
,
len
);
dataIn
=
new
DataInputStream
(
new
ByteArrayInputStream
(
data
,
0
,
len
));
switch
(
x
)
{
...
...
@@ -245,7 +245,7 @@ public class PgServerThread implements Runnable {
int
paramCount
=
readShort
();
for
(
int
i
=
0
;
i
<
paramCount
;
i
++)
{
int
paramLen
=
readInt
();
byte
[]
d2
=
Byte
Utils
.
newBytes
(
paramLen
);
byte
[]
d2
=
Memory
Utils
.
newBytes
(
paramLen
);
readFully
(
d2
);
try
{
setParameter
(
portal
.
prep
,
i
,
d2
,
formatCodes
);
...
...
h2/src/main/org/h2/server/web/WebThread.java
浏览文件 @
65e68391
...
...
@@ -62,7 +62,6 @@ import org.h2.tools.Restore;
import
org.h2.tools.RunScript
;
import
org.h2.tools.Script
;
import
org.h2.tools.SimpleResultSet
;
import
org.h2.util.ByteUtils
;
import
org.h2.util.IOUtils
;
import
org.h2.util.JdbcUtils
;
import
org.h2.util.MathUtils
;
...
...
@@ -408,7 +407,7 @@ class WebThread extends Thread implements DatabaseEventListener {
}
}
if
(
session
!=
null
&&
len
>
0
)
{
byte
[]
bytes
=
Byte
Utils
.
newBytes
(
len
);
byte
[]
bytes
=
Memory
Utils
.
newBytes
(
len
);
for
(
int
pos
=
0
;
pos
<
len
;)
{
pos
+=
input
.
read
(
bytes
,
pos
,
len
-
pos
);
}
...
...
h2/src/main/org/h2/util/ByteUtils.java
浏览文件 @
65e68391
...
...
@@ -253,23 +253,4 @@ public class ByteUtils {
return
copy
;
}
/**
* Create an array of bytes with the given size. If this is not possible
* because not enough memory is available, an OutOfMemoryError with the
* requested size in the message is thrown.
*
* @param len the number of bytes requested
* @return the byte array
* @throws OutOfMemoryError
*/
public
static
byte
[]
newBytes
(
int
len
)
{
try
{
return
new
byte
[
len
];
}
catch
(
OutOfMemoryError
e
)
{
Error
e2
=
new
OutOfMemoryError
(
"Requested memory: "
+
len
);
e2
.
initCause
(
e
);
throw
e2
;
}
}
}
h2/src/main/org/h2/util/MemoryUtils.java
浏览文件 @
65e68391
...
...
@@ -13,6 +13,16 @@ import org.h2.constant.SysProperties;
*/
public
class
MemoryUtils
{
/**
* An 0-size byte array.
*/
public
static
final
byte
[]
EMPTY_BYTES
=
new
byte
[
0
];
/**
* An 0-size int array.
*/
public
static
final
int
[]
EMPTY_INTS
=
new
int
[
0
];
private
static
long
lastGC
;
private
static
final
int
GC_DELAY
=
50
;
private
static
final
int
MAX_GC
=
8
;
...
...
@@ -80,4 +90,39 @@ public class MemoryUtils {
reserveMemory
=
null
;
}
/**
* Create an array of bytes with the given size. If this is not possible
* because not enough memory is available, an OutOfMemoryError with the
* requested size in the message is thrown.
*
* @param len the number of bytes requested
* @return the byte array
* @throws OutOfMemoryError
*/
public
static
byte
[]
newBytes
(
int
len
)
{
try
{
if
(
len
==
0
)
{
return
EMPTY_BYTES
;
}
return
new
byte
[
len
];
}
catch
(
OutOfMemoryError
e
)
{
Error
e2
=
new
OutOfMemoryError
(
"Requested memory: "
+
len
);
e2
.
initCause
(
e
);
throw
e2
;
}
}
/**
* Create an array of ints with the given size.
*
* @param len the number of bytes requested
* @return the int array
*/
public
static
int
[]
newInts
(
int
len
)
{
if
(
len
==
0
)
{
return
EMPTY_INTS
;
}
return
new
int
[
len
];
}
}
h2/src/main/org/h2/util/Resources.java
浏览文件 @
65e68391
...
...
@@ -76,7 +76,7 @@ public class Resources {
}
else
{
data
=
FILES
.
get
(
name
);
}
return
data
==
null
?
new
byte
[
0
]
:
data
;
return
data
==
null
?
MemoryUtils
.
EMPTY_BYTES
:
data
;
}
}
h2/src/main/org/h2/value/Transfer.java
浏览文件 @
65e68391
...
...
@@ -33,9 +33,9 @@ import org.h2.engine.SessionInterface;
import
org.h2.message.Message
;
import
org.h2.message.TraceSystem
;
import
org.h2.tools.SimpleResultSet
;
import
org.h2.util.ByteUtils
;
import
org.h2.util.ExactUTF8InputStreamReader
;
import
org.h2.util.IOUtils
;
import
org.h2.util.MemoryUtils
;
import
org.h2.util.NetUtils
;
import
org.h2.util.StringCache
;
...
...
@@ -274,7 +274,7 @@ public class Transfer {
if
(
len
==
-
1
)
{
return
null
;
}
byte
[]
b
=
Byte
Utils
.
newBytes
(
len
);
byte
[]
b
=
Memory
Utils
.
newBytes
(
len
);
in
.
readFully
(
b
);
return
b
;
}
...
...
h2/src/main/org/h2/value/ValueBytes.java
浏览文件 @
65e68391
...
...
@@ -8,13 +8,14 @@ package org.h2.value;
import
org.h2.constant.SysProperties
;
import
org.h2.util.ByteUtils
;
import
org.h2.util.MemoryUtils
;
/**
* Implementation of the BINARY data type.
*/
public
class
ValueBytes
extends
ValueBytesBase
{
private
static
final
ValueBytes
EMPTY
=
new
ValueBytes
(
new
byte
[
0
]
);
private
static
final
ValueBytes
EMPTY
=
new
ValueBytes
(
MemoryUtils
.
EMPTY_BYTES
);
protected
ValueBytes
(
byte
[]
v
)
{
super
(
v
);
...
...
h2/src/main/org/h2/value/ValueJavaObject.java
浏览文件 @
65e68391
...
...
@@ -11,6 +11,7 @@ import java.sql.SQLException;
import
java.sql.Types
;
import
org.h2.constant.SysProperties
;
import
org.h2.util.MemoryUtils
;
import
org.h2.util.ObjectUtils
;
/**
...
...
@@ -18,7 +19,7 @@ import org.h2.util.ObjectUtils;
*/
public
class
ValueJavaObject
extends
ValueBytesBase
{
private
static
final
ValueJavaObject
EMPTY
=
new
ValueJavaObject
(
new
byte
[
0
]
);
private
static
final
ValueJavaObject
EMPTY
=
new
ValueJavaObject
(
MemoryUtils
.
EMPTY_BYTES
);
protected
ValueJavaObject
(
byte
[]
v
)
{
super
(
v
);
...
...
h2/src/main/org/h2/value/ValueLob.java
浏览文件 @
65e68391
...
...
@@ -27,6 +27,7 @@ import org.h2.util.ByteUtils;
import
org.h2.util.FileUtils
;
import
org.h2.util.IOUtils
;
import
org.h2.util.MathUtils
;
import
org.h2.util.MemoryUtils
;
import
org.h2.util.SmallLRUCache
;
import
org.h2.util.StringUtils
;
...
...
@@ -353,11 +354,11 @@ public class ValueLob extends Value {
buff
=
IOUtils
.
readBytesAndClose
(
in
,
-
1
);
len
=
buff
.
length
;
}
else
{
buff
=
Byte
Utils
.
newBytes
(
len
);
buff
=
Memory
Utils
.
newBytes
(
len
);
len
=
IOUtils
.
readFully
(
in
,
buff
,
0
,
len
);
}
if
(
len
<=
handler
.
getMaxLengthInplaceLob
())
{
byte
[]
small
=
Byte
Utils
.
newBytes
(
len
);
byte
[]
small
=
Memory
Utils
.
newBytes
(
len
);
System
.
arraycopy
(
buff
,
0
,
small
,
0
,
len
);
return
ValueLob
.
createSmallLob
(
Value
.
BLOB
,
small
);
}
...
...
@@ -723,7 +724,7 @@ public class ValueLob extends Value {
int
len
=
getBufferSize
(
handler
,
compress
,
Long
.
MAX_VALUE
);
int
tabId
=
tableId
;
if
(
type
==
Value
.
BLOB
)
{
createFromStream
(
Byte
Utils
.
newBytes
(
len
),
0
,
getInputStream
(),
Long
.
MAX_VALUE
,
handler
);
createFromStream
(
Memory
Utils
.
newBytes
(
len
),
0
,
getInputStream
(),
Long
.
MAX_VALUE
,
handler
);
}
else
{
createFromReader
(
new
char
[
len
],
0
,
getReader
(),
Long
.
MAX_VALUE
,
handler
);
}
...
...
编写
预览
Markdown
格式
0%
重试
或
添加新文件
添加附件
取消
您添加了
0
人
到此讨论。请谨慎行事。
请先完成此评论的编辑!
取消
请
注册
或者
登录
后发表评论