Skip to content
项目
群组
代码片段
帮助
正在加载...
帮助
为 GitLab 提交贡献
登录/注册
切换导航
H
h2database
项目
项目
详情
活动
周期分析
仓库
仓库
文件
提交
分支
标签
贡献者
分枝图
比较
统计图
议题
0
议题
0
列表
看板
标记
里程碑
合并请求
0
合并请求
0
CI / CD
CI / CD
流水线
作业
计划
统计图
Wiki
Wiki
代码片段
代码片段
成员
成员
折叠边栏
关闭边栏
活动
分枝图
统计图
创建新议题
作业
提交
议题看板
打开侧边栏
Administrator
h2database
Commits
125671a9
提交
125671a9
authored
1月 22, 2018
作者:
Evgenij Ryazanov
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
Use Arrays.copyOf() and Arrays.copyOfRange()
上级
8a670816
显示空白字符变更
内嵌
并排
正在显示
29 个修改的文件
包含
93 行增加
和
91 行删除
+93
-91
Select.java
h2/src/main/org/h2/command/dml/Select.java
+1
-3
ConnectionInfo.java
h2/src/main/org/h2/engine/ConnectionInfo.java
+2
-4
Function.java
h2/src/main/org/h2/expression/Function.java
+1
-3
JdbcArray.java
h2/src/main/org/h2/jdbc/JdbcArray.java
+3
-3
DataUtils.java
h2/src/main/org/h2/mvstore/DataUtils.java
+31
-0
LocalResult.java
h2/src/main/org/h2/result/LocalResult.java
+3
-3
RowImpl.java
h2/src/main/org/h2/result/RowImpl.java
+3
-2
TriggerObject.java
h2/src/main/org/h2/schema/TriggerObject.java
+2
-2
Data.java
h2/src/main/org/h2/store/Data.java
+4
-5
FileStoreOutputStream.java
h2/src/main/org/h2/store/FileStoreOutputStream.java
+3
-3
LobStorageBackend.java
h2/src/main/org/h2/store/LobStorageBackend.java
+1
-2
FilePathMem.java
h2/src/main/org/h2/store/fs/FilePathMem.java
+2
-4
FilePathRec.java
h2/src/main/org/h2/store/fs/FilePathRec.java
+5
-6
CompressTool.java
h2/src/main/org/h2/tools/CompressTool.java
+1
-3
BitField.java
h2/src/main/org/h2/util/BitField.java
+3
-3
IntArray.java
h2/src/main/org/h2/util/IntArray.java
+3
-3
StringUtils.java
h2/src/main/org/h2/util/StringUtils.java
+2
-3
Utils.java
h2/src/main/org/h2/util/Utils.java
+1
-3
ValueBytes.java
h2/src/main/org/h2/value/ValueBytes.java
+1
-2
ValueLob.java
h2/src/main/org/h2/value/ValueLob.java
+1
-2
ValueLobDb.java
h2/src/main/org/h2/value/ValueLobDb.java
+1
-2
Tokenizer.java
h2/src/test/org/h2/test/coverage/Tokenizer.java
+3
-6
TaskDef.java
h2/src/test/org/h2/test/db/TaskDef.java
+3
-3
TestCompress.java
h2/src/test/org/h2/test/unit/TestCompress.java
+1
-2
XMLParser.java
h2/src/tools/org/h2/build/doc/XMLParser.java
+3
-3
ArchiveTool.java
h2/src/tools/org/h2/dev/fs/ArchiveTool.java
+1
-2
ArchiveToolStore.java
h2/src/tools/org/h2/dev/fs/ArchiveToolStore.java
+5
-5
ImmutableArray.java
h2/src/tools/org/h2/dev/util/ImmutableArray.java
+2
-5
ImmutableArray2.java
h2/src/tools/org/h2/dev/util/ImmutableArray2.java
+1
-4
没有找到文件。
h2/src/main/org/h2/command/dml/Select.java
浏览文件 @
125671a9
...
@@ -188,9 +188,7 @@ public class Select extends Query {
...
@@ -188,9 +188,7 @@ public class Select extends Query {
return
row
;
return
row
;
}
}
// remove columns so that 'distinct' can filter duplicate rows
// remove columns so that 'distinct' can filter duplicate rows
Value
[]
r2
=
new
Value
[
distinctColumnCount
];
return
Arrays
.
copyOf
(
row
,
distinctColumnCount
);
System
.
arraycopy
(
row
,
0
,
r2
,
0
,
distinctColumnCount
);
return
r2
;
}
}
private
boolean
isHavingNullOrFalse
(
Value
[]
row
)
{
private
boolean
isHavingNullOrFalse
(
Value
[]
row
)
{
...
...
h2/src/main/org/h2/engine/ConnectionInfo.java
浏览文件 @
125671a9
...
@@ -305,10 +305,8 @@ public class ConnectionInfo implements Cloneable {
...
@@ -305,10 +305,8 @@ public class ConnectionInfo implements Cloneable {
if
(
space
<
0
)
{
if
(
space
<
0
)
{
throw
DbException
.
get
(
ErrorCode
.
WRONG_PASSWORD_FORMAT
);
throw
DbException
.
get
(
ErrorCode
.
WRONG_PASSWORD_FORMAT
);
}
}
char
[]
np
=
new
char
[
password
.
length
-
space
-
1
];
char
[]
np
=
Arrays
.
copyOfRange
(
password
,
space
+
1
,
password
.
length
);
char
[]
filePassword
=
new
char
[
space
];
char
[]
filePassword
=
Arrays
.
copyOf
(
password
,
space
);
System
.
arraycopy
(
password
,
space
+
1
,
np
,
0
,
np
.
length
);
System
.
arraycopy
(
password
,
0
,
filePassword
,
0
,
space
);
Arrays
.
fill
(
password
,
(
char
)
0
);
Arrays
.
fill
(
password
,
(
char
)
0
);
password
=
np
;
password
=
np
;
fileEncryptionKey
=
FilePathEncrypt
.
getPasswordBytes
(
filePassword
);
fileEncryptionKey
=
FilePathEncrypt
.
getPasswordBytes
(
filePassword
);
...
...
h2/src/main/org/h2/expression/Function.java
浏览文件 @
125671a9
...
@@ -1786,9 +1786,7 @@ public class Function extends Expression implements FunctionCall {
...
@@ -1786,9 +1786,7 @@ public class Function extends Expression implements FunctionCall {
private
static
byte
[]
getPaddedArrayCopy
(
byte
[]
data
,
int
blockSize
)
{
private
static
byte
[]
getPaddedArrayCopy
(
byte
[]
data
,
int
blockSize
)
{
int
size
=
MathUtils
.
roundUpInt
(
data
.
length
,
blockSize
);
int
size
=
MathUtils
.
roundUpInt
(
data
.
length
,
blockSize
);
byte
[]
newData
=
DataUtils
.
newBytes
(
size
);
return
DataUtils
.
copyBytes
(
data
,
size
);
System
.
arraycopy
(
data
,
0
,
newData
,
0
,
data
.
length
);
return
newData
;
}
}
private
static
byte
[]
decrypt
(
String
algorithm
,
byte
[]
key
,
byte
[]
data
)
{
private
static
byte
[]
decrypt
(
String
algorithm
,
byte
[]
key
,
byte
[]
data
)
{
...
...
h2/src/main/org/h2/jdbc/JdbcArray.java
浏览文件 @
125671a9
...
@@ -9,6 +9,7 @@ import java.sql.Array;
...
@@ -9,6 +9,7 @@ import java.sql.Array;
import
java.sql.ResultSet
;
import
java.sql.ResultSet
;
import
java.sql.SQLException
;
import
java.sql.SQLException
;
import
java.sql.Types
;
import
java.sql.Types
;
import
java.util.Arrays
;
import
java.util.Map
;
import
java.util.Map
;
import
org.h2.api.ErrorCode
;
import
org.h2.api.ErrorCode
;
...
@@ -283,9 +284,8 @@ public class JdbcArray extends TraceObject implements Array {
...
@@ -283,9 +284,8 @@ public class JdbcArray extends TraceObject implements Array {
throw
DbException
.
getInvalidValueException
(
"index (1.."
throw
DbException
.
getInvalidValueException
(
"index (1.."
+
array
.
length
+
")"
,
index
);
+
array
.
length
+
")"
,
index
);
}
}
Object
[]
subset
=
new
Object
[
count
];
int
offset
=
(
int
)
(
index
-
1
);
System
.
arraycopy
(
array
,
(
int
)
(
index
-
1
),
subset
,
0
,
count
);
return
Arrays
.
copyOfRange
(
array
,
offset
,
offset
+
count
);
return
subset
;
}
}
/**
/**
...
...
h2/src/main/org/h2/mvstore/DataUtils.java
浏览文件 @
125671a9
...
@@ -13,6 +13,7 @@ import java.nio.channels.FileChannel;
...
@@ -13,6 +13,7 @@ import java.nio.channels.FileChannel;
import
java.nio.charset.StandardCharsets
;
import
java.nio.charset.StandardCharsets
;
import
java.text.MessageFormat
;
import
java.text.MessageFormat
;
import
java.util.ArrayList
;
import
java.util.ArrayList
;
import
java.util.Arrays
;
import
java.util.Collections
;
import
java.util.Collections
;
import
java.util.HashMap
;
import
java.util.HashMap
;
import
java.util.Map
;
import
java.util.Map
;
...
@@ -913,6 +914,7 @@ public final class DataUtils {
...
@@ -913,6 +914,7 @@ public final class DataUtils {
* This method should be used if the size of the array is user defined, or
* This method should be used if the size of the array is user defined, or
* stored in a file, so wrong size data can be distinguished from regular
* stored in a file, so wrong size data can be distinguished from regular
* out-of-memory.
* out-of-memory.
* </p>
*
*
* @param len the number of bytes requested
* @param len the number of bytes requested
* @return the byte array
* @return the byte array
...
@@ -931,6 +933,35 @@ public final class DataUtils {
...
@@ -931,6 +933,35 @@ public final class DataUtils {
}
}
}
}
/**
* Creates a copy of array of bytes with the new size. If this is not possible
* because not enough memory is available, an OutOfMemoryError with the
* requested size in the message is thrown.
* <p>
* This method should be used if the size of the array is user defined, or
* stored in a file, so wrong size data can be distinguished from regular
* out-of-memory.
* </p>
*
* @param bytes source array
* @param len the number of bytes in the new array
* @return the byte array
* @throws OutOfMemoryError if the allocation was too large
* @see Arrays#copyOf(byte[], int)
*/
public
static
byte
[]
copyBytes
(
byte
[]
bytes
,
int
len
)
{
if
(
len
==
0
)
{
return
EMPTY_BYTES
;
}
try
{
return
Arrays
.
copyOf
(
bytes
,
len
);
}
catch
(
OutOfMemoryError
e
)
{
Error
e2
=
new
OutOfMemoryError
(
"Requested memory: "
+
len
);
e2
.
initCause
(
e
);
throw
e2
;
}
}
/**
/**
* Read a hex long value from a map.
* Read a hex long value from a map.
*
*
...
...
h2/src/main/org/h2/result/LocalResult.java
浏览文件 @
125671a9
...
@@ -8,6 +8,8 @@ package org.h2.result;
...
@@ -8,6 +8,8 @@ package org.h2.result;
import
java.sql.ResultSet
;
import
java.sql.ResultSet
;
import
java.sql.SQLException
;
import
java.sql.SQLException
;
import
java.util.ArrayList
;
import
java.util.ArrayList
;
import
java.util.Arrays
;
import
org.h2.engine.Database
;
import
org.h2.engine.Database
;
import
org.h2.engine.Session
;
import
org.h2.engine.Session
;
import
org.h2.expression.Expression
;
import
org.h2.expression.Expression
;
...
@@ -281,9 +283,7 @@ public class LocalResult implements ResultInterface, ResultTarget {
...
@@ -281,9 +283,7 @@ public class LocalResult implements ResultInterface, ResultTarget {
private
ValueArray
getArrayOfVisible
(
Value
[]
values
)
{
private
ValueArray
getArrayOfVisible
(
Value
[]
values
)
{
if
(
values
.
length
>
visibleColumnCount
)
{
if
(
values
.
length
>
visibleColumnCount
)
{
Value
[]
v2
=
new
Value
[
visibleColumnCount
];
values
=
Arrays
.
copyOf
(
values
,
visibleColumnCount
);
System
.
arraycopy
(
values
,
0
,
v2
,
0
,
visibleColumnCount
);
values
=
v2
;
}
}
return
ValueArray
.
get
(
values
);
return
ValueArray
.
get
(
values
);
}
}
...
...
h2/src/main/org/h2/result/RowImpl.java
浏览文件 @
125671a9
...
@@ -5,6 +5,8 @@
...
@@ -5,6 +5,8 @@
*/
*/
package
org
.
h2
.
result
;
package
org
.
h2
.
result
;
import
java.util.Arrays
;
import
org.h2.engine.Constants
;
import
org.h2.engine.Constants
;
import
org.h2.store.Data
;
import
org.h2.store.Data
;
import
org.h2.util.StatementBuilder
;
import
org.h2.util.StatementBuilder
;
...
@@ -35,8 +37,7 @@ public class RowImpl implements Row {
...
@@ -35,8 +37,7 @@ public class RowImpl implements Row {
*/
*/
@Override
@Override
public
Row
getCopy
()
{
public
Row
getCopy
()
{
Value
[]
d2
=
new
Value
[
data
.
length
];
Value
[]
d2
=
Arrays
.
copyOf
(
data
,
data
.
length
);
System
.
arraycopy
(
data
,
0
,
d2
,
0
,
data
.
length
);
RowImpl
r2
=
new
RowImpl
(
d2
,
memory
);
RowImpl
r2
=
new
RowImpl
(
d2
,
memory
);
r2
.
key
=
key
;
r2
.
key
=
key
;
r2
.
version
=
version
+
1
;
r2
.
version
=
version
+
1
;
...
...
h2/src/main/org/h2/schema/TriggerObject.java
浏览文件 @
125671a9
...
@@ -8,6 +8,7 @@ package org.h2.schema;
...
@@ -8,6 +8,7 @@ package org.h2.schema;
import
java.lang.reflect.Method
;
import
java.lang.reflect.Method
;
import
java.sql.Connection
;
import
java.sql.Connection
;
import
java.sql.SQLException
;
import
java.sql.SQLException
;
import
java.util.Arrays
;
import
org.h2.api.ErrorCode
;
import
org.h2.api.ErrorCode
;
import
org.h2.api.Trigger
;
import
org.h2.api.Trigger
;
...
@@ -243,8 +244,7 @@ public class TriggerObject extends SchemaObjectBase {
...
@@ -243,8 +244,7 @@ public class TriggerObject extends SchemaObjectBase {
newList
=
convertToObjectList
(
newRow
);
newList
=
convertToObjectList
(
newRow
);
Object
[]
newListBackup
;
Object
[]
newListBackup
;
if
(
before
&&
newList
!=
null
)
{
if
(
before
&&
newList
!=
null
)
{
newListBackup
=
new
Object
[
newList
.
length
];
newListBackup
=
Arrays
.
copyOf
(
newList
,
newList
.
length
);
System
.
arraycopy
(
newList
,
0
,
newListBackup
,
0
,
newList
.
length
);
}
else
{
}
else
{
newListBackup
=
null
;
newListBackup
=
null
;
}
}
...
...
h2/src/main/org/h2/store/Data.java
浏览文件 @
125671a9
...
@@ -17,6 +17,8 @@ import java.sql.ResultSet;
...
@@ -17,6 +17,8 @@ import java.sql.ResultSet;
import
java.sql.ResultSetMetaData
;
import
java.sql.ResultSetMetaData
;
import
java.sql.SQLException
;
import
java.sql.SQLException
;
import
java.sql.Timestamp
;
import
java.sql.Timestamp
;
import
java.util.Arrays
;
import
org.h2.api.ErrorCode
;
import
org.h2.api.ErrorCode
;
import
org.h2.engine.Constants
;
import
org.h2.engine.Constants
;
import
org.h2.engine.SysProperties
;
import
org.h2.engine.SysProperties
;
...
@@ -1171,8 +1173,7 @@ public class Data {
...
@@ -1171,8 +1173,7 @@ public class Data {
*/
*/
public
void
truncate
(
int
size
)
{
public
void
truncate
(
int
size
)
{
if
(
pos
>
size
)
{
if
(
pos
>
size
)
{
byte
[]
buff
=
new
byte
[
size
];
byte
[]
buff
=
Arrays
.
copyOf
(
data
,
size
);
System
.
arraycopy
(
data
,
0
,
buff
,
0
,
size
);
this
.
pos
=
size
;
this
.
pos
=
size
;
data
=
buff
;
data
=
buff
;
}
}
...
@@ -1313,11 +1314,9 @@ public class Data {
...
@@ -1313,11 +1314,9 @@ public class Data {
}
}
private
void
expand
(
int
plus
)
{
private
void
expand
(
int
plus
)
{
byte
[]
d
=
DataUtils
.
newBytes
((
data
.
length
+
plus
)
*
2
);
// must copy everything, because pos could be 0 and data may be
// must copy everything, because pos could be 0 and data may be
// still required
// still required
System
.
arraycopy
(
data
,
0
,
d
,
0
,
data
.
length
);
data
=
DataUtils
.
copyBytes
(
data
,
(
data
.
length
+
plus
)
*
2
);
data
=
d
;
}
}
/**
/**
...
...
h2/src/main/org/h2/store/FileStoreOutputStream.java
浏览文件 @
125671a9
...
@@ -6,6 +6,8 @@
...
@@ -6,6 +6,8 @@
package
org
.
h2
.
store
;
package
org
.
h2
.
store
;
import
java.io.OutputStream
;
import
java.io.OutputStream
;
import
java.util.Arrays
;
import
org.h2.engine.Constants
;
import
org.h2.engine.Constants
;
import
org.h2.tools.CompressTool
;
import
org.h2.tools.CompressTool
;
...
@@ -49,9 +51,7 @@ public class FileStoreOutputStream extends OutputStream {
...
@@ -49,9 +51,7 @@ public class FileStoreOutputStream extends OutputStream {
page
.
reset
();
page
.
reset
();
if
(
compress
!=
null
)
{
if
(
compress
!=
null
)
{
if
(
off
!=
0
||
len
!=
buff
.
length
)
{
if
(
off
!=
0
||
len
!=
buff
.
length
)
{
byte
[]
b2
=
new
byte
[
len
];
buff
=
Arrays
.
copyOfRange
(
buff
,
off
,
off
+
len
);
System
.
arraycopy
(
buff
,
off
,
b2
,
0
,
len
);
buff
=
b2
;
off
=
0
;
off
=
0
;
}
}
int
uncompressed
=
len
;
int
uncompressed
=
len
;
...
...
h2/src/main/org/h2/store/LobStorageBackend.java
浏览文件 @
125671a9
...
@@ -368,8 +368,7 @@ public class LobStorageBackend implements LobStorageInterface {
...
@@ -368,8 +368,7 @@ public class LobStorageBackend implements LobStorageInterface {
// if we had a short read, trim the buffer
// if we had a short read, trim the buffer
byte
[]
b
;
byte
[]
b
;
if
(
len
!=
buff
.
length
)
{
if
(
len
!=
buff
.
length
)
{
b
=
new
byte
[
len
];
b
=
Arrays
.
copyOf
(
buff
,
len
);
System
.
arraycopy
(
buff
,
0
,
b
,
0
,
len
);
}
else
{
}
else
{
b
=
buff
;
b
=
buff
;
}
}
...
...
h2/src/main/org/h2/store/fs/FilePathMem.java
浏览文件 @
125671a9
...
@@ -444,8 +444,7 @@ class FileMemData {
...
@@ -444,8 +444,7 @@ class FileMemData {
static
{
static
{
byte
[]
n
=
new
byte
[
BLOCK_SIZE
];
byte
[]
n
=
new
byte
[
BLOCK_SIZE
];
int
len
=
LZF
.
compress
(
n
,
BLOCK_SIZE
,
BUFFER
,
0
);
int
len
=
LZF
.
compress
(
n
,
BLOCK_SIZE
,
BUFFER
,
0
);
COMPRESSED_EMPTY_BLOCK
=
new
byte
[
len
];
COMPRESSED_EMPTY_BLOCK
=
Arrays
.
copyOf
(
BUFFER
,
len
);
System
.
arraycopy
(
BUFFER
,
0
,
COMPRESSED_EMPTY_BLOCK
,
0
,
len
);
}
}
@SuppressWarnings
(
"unchecked"
)
@SuppressWarnings
(
"unchecked"
)
...
@@ -631,8 +630,7 @@ class FileMemData {
...
@@ -631,8 +630,7 @@ class FileMemData {
synchronized
(
LZF
)
{
synchronized
(
LZF
)
{
int
len
=
LZF
.
compress
(
old
,
BLOCK_SIZE
,
BUFFER
,
0
);
int
len
=
LZF
.
compress
(
old
,
BLOCK_SIZE
,
BUFFER
,
0
);
if
(
len
<=
BLOCK_SIZE
)
{
if
(
len
<=
BLOCK_SIZE
)
{
byte
[]
d
=
new
byte
[
len
];
byte
[]
d
=
Arrays
.
copyOf
(
BUFFER
,
len
);
System
.
arraycopy
(
BUFFER
,
0
,
d
,
0
,
len
);
// maybe data was changed in the meantime
// maybe data was changed in the meantime
setPage
(
page
,
old
,
d
,
false
);
setPage
(
page
,
old
,
d
,
false
);
}
}
...
...
h2/src/main/org/h2/store/fs/FilePathRec.java
浏览文件 @
125671a9
...
@@ -10,6 +10,7 @@ import java.io.OutputStream;
...
@@ -10,6 +10,7 @@ import java.io.OutputStream;
import
java.nio.ByteBuffer
;
import
java.nio.ByteBuffer
;
import
java.nio.channels.FileChannel
;
import
java.nio.channels.FileChannel
;
import
java.nio.channels.FileLock
;
import
java.nio.channels.FileLock
;
import
java.util.Arrays
;
/**
/**
* A file system that records all write operations and can re-play them.
* A file system that records all write operations and can re-play them.
...
@@ -182,9 +183,8 @@ class FileRec extends FileBase {
...
@@ -182,9 +183,8 @@ class FileRec extends FileBase {
byte
[]
buff
=
src
.
array
();
byte
[]
buff
=
src
.
array
();
int
len
=
src
.
remaining
();
int
len
=
src
.
remaining
();
if
(
src
.
position
()
!=
0
||
len
!=
buff
.
length
)
{
if
(
src
.
position
()
!=
0
||
len
!=
buff
.
length
)
{
byte
[]
b
=
new
byte
[
len
];
int
offset
=
src
.
arrayOffset
()
+
src
.
position
();
System
.
arraycopy
(
buff
,
src
.
arrayOffset
()
+
src
.
position
(),
b
,
0
,
len
);
buff
=
Arrays
.
copyOfRange
(
buff
,
offset
,
offset
+
len
);
buff
=
b
;
}
}
int
result
=
channel
.
write
(
src
);
int
result
=
channel
.
write
(
src
);
rec
.
log
(
Recorder
.
WRITE
,
name
,
buff
,
channel
.
position
());
rec
.
log
(
Recorder
.
WRITE
,
name
,
buff
,
channel
.
position
());
...
@@ -196,9 +196,8 @@ class FileRec extends FileBase {
...
@@ -196,9 +196,8 @@ class FileRec extends FileBase {
byte
[]
buff
=
src
.
array
();
byte
[]
buff
=
src
.
array
();
int
len
=
src
.
remaining
();
int
len
=
src
.
remaining
();
if
(
src
.
position
()
!=
0
||
len
!=
buff
.
length
)
{
if
(
src
.
position
()
!=
0
||
len
!=
buff
.
length
)
{
byte
[]
b
=
new
byte
[
len
];
int
offset
=
src
.
arrayOffset
()
+
src
.
position
();
System
.
arraycopy
(
buff
,
src
.
arrayOffset
()
+
src
.
position
(),
b
,
0
,
len
);
buff
=
Arrays
.
copyOfRange
(
buff
,
offset
,
offset
+
len
);
buff
=
b
;
}
}
int
result
=
channel
.
write
(
src
,
position
);
int
result
=
channel
.
write
(
src
,
position
);
rec
.
log
(
Recorder
.
WRITE
,
name
,
buff
,
position
);
rec
.
log
(
Recorder
.
WRITE
,
name
,
buff
,
position
);
...
...
h2/src/main/org/h2/tools/CompressTool.java
浏览文件 @
125671a9
...
@@ -79,9 +79,7 @@ public class CompressTool {
...
@@ -79,9 +79,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
=
DataUtils
.
newBytes
(
newLen
);
return
DataUtils
.
copyBytes
(
buff
,
newLen
);
System
.
arraycopy
(
buff
,
0
,
out
,
0
,
newLen
);
return
out
;
}
}
private
static
int
compress
(
byte
[]
in
,
int
len
,
Compressor
compress
,
private
static
int
compress
(
byte
[]
in
,
int
len
,
Compressor
compress
,
...
...
h2/src/main/org/h2/util/BitField.java
浏览文件 @
125671a9
...
@@ -5,6 +5,8 @@
...
@@ -5,6 +5,8 @@
*/
*/
package
org
.
h2
.
util
;
package
org
.
h2
.
util
;
import
java.util.Arrays
;
/**
/**
* A list of bits.
* A list of bits.
*/
*/
...
@@ -132,9 +134,7 @@ public final class BitField {
...
@@ -132,9 +134,7 @@ public final class BitField {
private
void
expandCapacity
(
int
size
)
{
private
void
expandCapacity
(
int
size
)
{
while
(
size
>=
data
.
length
)
{
while
(
size
>=
data
.
length
)
{
int
newSize
=
data
.
length
==
0
?
1
:
data
.
length
*
2
;
int
newSize
=
data
.
length
==
0
?
1
:
data
.
length
*
2
;
long
[]
d
=
new
long
[
newSize
];
data
=
Arrays
.
copyOf
(
data
,
newSize
);
System
.
arraycopy
(
data
,
0
,
d
,
0
,
data
.
length
);
data
=
d
;
}
}
}
}
...
...
h2/src/main/org/h2/util/IntArray.java
浏览文件 @
125671a9
...
@@ -5,6 +5,8 @@
...
@@ -5,6 +5,8 @@
*/
*/
package
org
.
h2
.
util
;
package
org
.
h2
.
util
;
import
java.util.Arrays
;
import
org.h2.engine.SysProperties
;
import
org.h2.engine.SysProperties
;
/**
/**
...
@@ -93,9 +95,7 @@ public class IntArray {
...
@@ -93,9 +95,7 @@ public class IntArray {
public
void
ensureCapacity
(
int
minCapacity
)
{
public
void
ensureCapacity
(
int
minCapacity
)
{
minCapacity
=
Math
.
max
(
4
,
minCapacity
);
minCapacity
=
Math
.
max
(
4
,
minCapacity
);
if
(
minCapacity
>=
data
.
length
)
{
if
(
minCapacity
>=
data
.
length
)
{
int
[]
d
=
new
int
[
minCapacity
];
data
=
Arrays
.
copyOf
(
data
,
minCapacity
);
System
.
arraycopy
(
data
,
0
,
d
,
0
,
data
.
length
);
data
=
d
;
}
}
}
}
...
...
h2/src/main/org/h2/util/StringUtils.java
浏览文件 @
125671a9
...
@@ -9,6 +9,7 @@ import java.lang.ref.SoftReference;
...
@@ -9,6 +9,7 @@ import java.lang.ref.SoftReference;
import
java.net.URLEncoder
;
import
java.net.URLEncoder
;
import
java.nio.charset.StandardCharsets
;
import
java.nio.charset.StandardCharsets
;
import
java.util.ArrayList
;
import
java.util.ArrayList
;
import
java.util.Arrays
;
import
java.util.Locale
;
import
java.util.Locale
;
import
java.util.concurrent.TimeUnit
;
import
java.util.concurrent.TimeUnit
;
...
@@ -828,9 +829,7 @@ public class StringUtils {
...
@@ -828,9 +829,7 @@ public class StringUtils {
if
(
len
==
0
)
{
if
(
len
==
0
)
{
return
chars
;
return
chars
;
}
}
char
[]
copy
=
new
char
[
len
];
return
Arrays
.
copyOf
(
chars
,
len
);
System
.
arraycopy
(
chars
,
0
,
copy
,
0
,
len
);
return
copy
;
}
}
/**
/**
...
...
h2/src/main/org/h2/util/Utils.java
浏览文件 @
125671a9
...
@@ -225,9 +225,7 @@ public class Utils {
...
@@ -225,9 +225,7 @@ public class Utils {
if
(
len
==
0
)
{
if
(
len
==
0
)
{
return
EMPTY_BYTES
;
return
EMPTY_BYTES
;
}
}
byte
[]
copy
=
new
byte
[
len
];
return
Arrays
.
copyOf
(
b
,
len
);
System
.
arraycopy
(
b
,
0
,
copy
,
0
,
len
);
return
copy
;
}
}
/**
/**
...
...
h2/src/main/org/h2/value/ValueBytes.java
浏览文件 @
125671a9
...
@@ -149,8 +149,7 @@ public class ValueBytes extends Value {
...
@@ -149,8 +149,7 @@ public class ValueBytes extends Value {
return
this
;
return
this
;
}
}
int
len
=
MathUtils
.
convertLongToInt
(
precision
);
int
len
=
MathUtils
.
convertLongToInt
(
precision
);
byte
[]
buff
=
new
byte
[
len
];
byte
[]
buff
=
Arrays
.
copyOf
(
value
,
len
);
System
.
arraycopy
(
value
,
0
,
buff
,
0
,
len
);
return
get
(
buff
);
return
get
(
buff
);
}
}
...
...
h2/src/main/org/h2/value/ValueLob.java
浏览文件 @
125671a9
...
@@ -416,8 +416,7 @@ public class ValueLob extends Value {
...
@@ -416,8 +416,7 @@ public class ValueLob extends Value {
len
=
IOUtils
.
readFully
(
in
,
buff
,
len
);
len
=
IOUtils
.
readFully
(
in
,
buff
,
len
);
}
}
if
(
len
<=
handler
.
getMaxLengthInplaceLob
())
{
if
(
len
<=
handler
.
getMaxLengthInplaceLob
())
{
byte
[]
small
=
DataUtils
.
newBytes
(
len
);
byte
[]
small
=
DataUtils
.
copyBytes
(
buff
,
len
);
System
.
arraycopy
(
buff
,
0
,
small
,
0
,
len
);
return
ValueLob
.
createSmallLob
(
Value
.
BLOB
,
small
);
return
ValueLob
.
createSmallLob
(
Value
.
BLOB
,
small
);
}
}
ValueLob
lob
=
new
ValueLob
(
Value
.
BLOB
,
null
);
ValueLob
lob
=
new
ValueLob
(
Value
.
BLOB
,
null
);
...
...
h2/src/main/org/h2/value/ValueLobDb.java
浏览文件 @
125671a9
...
@@ -600,8 +600,7 @@ public class ValueLobDb extends Value implements Value.ValueClob,
...
@@ -600,8 +600,7 @@ public class ValueLobDb extends Value implements Value.ValueClob,
len
=
IOUtils
.
readFully
(
in
,
buff
,
len
);
len
=
IOUtils
.
readFully
(
in
,
buff
,
len
);
}
}
if
(
len
<=
handler
.
getMaxLengthInplaceLob
())
{
if
(
len
<=
handler
.
getMaxLengthInplaceLob
())
{
byte
[]
small
=
DataUtils
.
newBytes
(
len
);
byte
[]
small
=
DataUtils
.
copyBytes
(
buff
,
len
);
System
.
arraycopy
(
buff
,
0
,
small
,
0
,
len
);
return
ValueLobDb
.
createSmallLob
(
Value
.
BLOB
,
small
,
small
.
length
);
return
ValueLobDb
.
createSmallLob
(
Value
.
BLOB
,
small
,
small
.
length
);
}
}
ValueLobDb
lob
=
new
ValueLobDb
(
handler
,
buff
,
len
,
in
,
remaining
);
ValueLobDb
lob
=
new
ValueLobDb
(
handler
,
buff
,
len
,
in
,
remaining
);
...
...
h2/src/test/org/h2/test/coverage/Tokenizer.java
浏览文件 @
125671a9
...
@@ -8,6 +8,7 @@ package org.h2.test.coverage;
...
@@ -8,6 +8,7 @@ package org.h2.test.coverage;
import
java.io.EOFException
;
import
java.io.EOFException
;
import
java.io.IOException
;
import
java.io.IOException
;
import
java.io.Reader
;
import
java.io.Reader
;
import
java.util.Arrays
;
/**
/**
* Helper class for the java file parser.
* Helper class for the java file parser.
...
@@ -154,9 +155,7 @@ public class Tokenizer {
...
@@ -154,9 +155,7 @@ public class Tokenizer {
int
i
=
0
;
int
i
=
0
;
do
{
do
{
if
(
i
>=
chars
.
length
)
{
if
(
i
>=
chars
.
length
)
{
char
[]
nb
=
new
char
[
chars
.
length
*
2
];
chars
=
Arrays
.
copyOf
(
chars
,
chars
.
length
*
2
);
System
.
arraycopy
(
chars
,
0
,
nb
,
0
,
chars
.
length
);
chars
=
nb
;
}
}
chars
[
i
++]
=
(
char
)
c
;
chars
[
i
++]
=
(
char
)
c
;
c
=
read
();
c
=
read
();
...
@@ -221,9 +220,7 @@ public class Tokenizer {
...
@@ -221,9 +220,7 @@ public class Tokenizer {
}
}
if
(
i
>=
chars
.
length
)
{
if
(
i
>=
chars
.
length
)
{
char
[]
nb
=
new
char
[
chars
.
length
*
2
];
chars
=
Arrays
.
copyOf
(
chars
,
chars
.
length
*
2
);
System
.
arraycopy
(
chars
,
0
,
nb
,
0
,
chars
.
length
);
chars
=
nb
;
}
}
chars
[
i
++]
=
(
char
)
c
;
chars
[
i
++]
=
(
char
)
c
;
}
}
...
...
h2/src/test/org/h2/test/db/TaskDef.java
浏览文件 @
125671a9
...
@@ -8,6 +8,8 @@ package org.h2.test.db;
...
@@ -8,6 +8,8 @@ package org.h2.test.db;
import
java.io.BufferedReader
;
import
java.io.BufferedReader
;
import
java.io.IOException
;
import
java.io.IOException
;
import
java.io.InputStreamReader
;
import
java.io.InputStreamReader
;
import
java.util.Arrays
;
import
org.h2.test.utils.SelfDestructor
;
import
org.h2.test.utils.SelfDestructor
;
/**
/**
...
@@ -34,9 +36,7 @@ public abstract class TaskDef {
...
@@ -34,9 +36,7 @@ public abstract class TaskDef {
return
;
return
;
}
}
try
{
try
{
String
[]
taskArgs
=
new
String
[
args
.
length
-
1
];
task
.
run
(
Arrays
.
copyOf
(
args
,
args
.
length
-
1
));
System
.
arraycopy
(
args
,
0
,
taskArgs
,
0
,
args
.
length
-
1
);
task
.
run
(
taskArgs
);
}
catch
(
Throwable
t
)
{
}
catch
(
Throwable
t
)
{
System
.
out
.
println
(
"error: "
+
t
);
System
.
out
.
println
(
"error: "
+
t
);
t
.
printStackTrace
();
t
.
printStackTrace
();
...
...
h2/src/test/org/h2/test/unit/TestCompress.java
浏览文件 @
125671a9
...
@@ -187,8 +187,7 @@ public class TestCompress extends TestBase {
...
@@ -187,8 +187,7 @@ public class TestCompress extends TestBase {
break
;
break
;
}
}
int
b
=
compress
.
compress
(
buff2
,
pageSize
,
test
,
0
);
int
b
=
compress
.
compress
(
buff2
,
pageSize
,
test
,
0
);
byte
[]
data
=
new
byte
[
b
];
byte
[]
data
=
Arrays
.
copyOf
(
test
,
b
);
System
.
arraycopy
(
test
,
0
,
data
,
0
,
b
);
comp
.
add
(
data
);
comp
.
add
(
data
);
}
}
in
.
close
();
in
.
close
();
...
...
h2/src/tools/org/h2/build/doc/XMLParser.java
浏览文件 @
125671a9
...
@@ -5,6 +5,8 @@
...
@@ -5,6 +5,8 @@
*/
*/
package
org
.
h2
.
build
.
doc
;
package
org
.
h2
.
build
.
doc
;
import
java.util.Arrays
;
/**
/**
* This class implements a simple XML pull parser.
* This class implements a simple XML pull parser.
* Only a subset of the XML pull parser API is implemented.
* Only a subset of the XML pull parser API is implemented.
...
@@ -94,9 +96,7 @@ public class XMLParser {
...
@@ -94,9 +96,7 @@ public class XMLParser {
private
void
addAttributeName
(
String
pre
,
String
name
)
{
private
void
addAttributeName
(
String
pre
,
String
name
)
{
if
(
attributeValues
.
length
<=
currentAttribute
)
{
if
(
attributeValues
.
length
<=
currentAttribute
)
{
String
[]
temp
=
new
String
[
attributeValues
.
length
*
2
];
attributeValues
=
Arrays
.
copyOf
(
attributeValues
,
attributeValues
.
length
*
2
);
System
.
arraycopy
(
attributeValues
,
0
,
temp
,
0
,
attributeValues
.
length
);
attributeValues
=
temp
;
}
}
attributeValues
[
currentAttribute
++]
=
pre
;
attributeValues
[
currentAttribute
++]
=
pre
;
attributeValues
[
currentAttribute
++]
=
name
;
attributeValues
[
currentAttribute
++]
=
name
;
...
...
h2/src/tools/org/h2/dev/fs/ArchiveTool.java
浏览文件 @
125671a9
...
@@ -426,8 +426,7 @@ public class ArchiveTool {
...
@@ -426,8 +426,7 @@ public class ArchiveTool {
for
(
int
pos
=
0
;
pos
<
len
;)
{
for
(
int
pos
=
0
;
pos
<
len
;)
{
int
[]
key
=
getKey
(
bytes
,
pos
,
len
);
int
[]
key
=
getKey
(
bytes
,
pos
,
len
);
int
l
=
key
[
3
];
int
l
=
key
[
3
];
byte
[]
buff
=
new
byte
[
l
];
byte
[]
buff
=
Arrays
.
copyOfRange
(
bytes
,
pos
,
pos
+
l
);
System
.
arraycopy
(
bytes
,
pos
,
buff
,
0
,
l
);
pos
+=
l
;
pos
+=
l
;
Chunk
c
=
new
Chunk
(
null
,
key
,
buff
);
Chunk
c
=
new
Chunk
(
null
,
key
,
buff
);
Chunk
old
=
map
.
get
(
c
);
Chunk
old
=
map
.
get
(
c
);
...
...
h2/src/tools/org/h2/dev/fs/ArchiveToolStore.java
浏览文件 @
125671a9
...
@@ -117,11 +117,11 @@ public class ArchiveToolStore {
...
@@ -117,11 +117,11 @@ public class ArchiveToolStore {
if
(
buff
.
remaining
()
==
0
)
{
if
(
buff
.
remaining
()
==
0
)
{
break
;
break
;
}
}
int
c
=
getChunkLength
(
buff
.
array
(),
buff
.
position
(),
int
position
=
buff
.
position
();
buff
.
limit
())
-
buff
.
position
();
int
c
=
getChunkLength
(
buff
.
array
(),
position
,
byte
[]
bytes
=
new
byte
[
c
]
;
buff
.
limit
())
-
position
;
System
.
arraycopy
(
buff
.
array
(),
buff
.
position
(),
bytes
,
0
,
c
);
byte
[]
bytes
=
Arrays
.
copyOfRange
(
buff
.
array
(),
position
,
position
+
c
);
buff
.
position
(
buff
.
position
()
+
c
);
buff
.
position
(
position
+
c
);
int
[]
key
=
getKey
(
bucket
,
bytes
);
int
[]
key
=
getKey
(
bucket
,
bytes
);
key
[
3
]
=
segmentId
;
key
[
3
]
=
segmentId
;
while
(
true
)
{
while
(
true
)
{
...
...
h2/src/tools/org/h2/dev/util/ImmutableArray.java
浏览文件 @
125671a9
...
@@ -5,6 +5,7 @@
...
@@ -5,6 +5,7 @@
*/
*/
package
org
.
h2
.
dev
.
util
;
package
org
.
h2
.
dev
.
util
;
import
java.util.Arrays
;
import
java.util.Iterator
;
import
java.util.Iterator
;
import
org.h2.mvstore.DataUtils
;
import
org.h2.mvstore.DataUtils
;
...
@@ -97,11 +98,7 @@ public final class ImmutableArray<K> implements Iterable<K> {
...
@@ -97,11 +98,7 @@ public final class ImmutableArray<K> implements Iterable<K> {
* @return the new immutable array
* @return the new immutable array
*/
*/
public
ImmutableArray
<
K
>
subArray
(
int
fromIndex
,
int
toIndex
)
{
public
ImmutableArray
<
K
>
subArray
(
int
fromIndex
,
int
toIndex
)
{
int
len
=
toIndex
-
fromIndex
;
return
new
ImmutableArray
<>(
Arrays
.
copyOfRange
(
array
,
fromIndex
,
toIndex
));
@SuppressWarnings
(
"unchecked"
)
K
[]
array
=
(
K
[])
new
Object
[
len
];
System
.
arraycopy
(
this
.
array
,
fromIndex
,
array
,
0
,
toIndex
-
fromIndex
);
return
new
ImmutableArray
<>(
array
);
}
}
/**
/**
...
...
h2/src/tools/org/h2/dev/util/ImmutableArray2.java
浏览文件 @
125671a9
...
@@ -138,10 +138,7 @@ public final class ImmutableArray2<K> implements Iterable<K> {
...
@@ -138,10 +138,7 @@ public final class ImmutableArray2<K> implements Iterable<K> {
if
(
fromIndex
==
0
)
{
if
(
fromIndex
==
0
)
{
return
new
ImmutableArray2
<>(
array
,
len
);
return
new
ImmutableArray2
<>(
array
,
len
);
}
}
@SuppressWarnings
(
"unchecked"
)
return
new
ImmutableArray2
<>(
Arrays
.
copyOfRange
(
array
,
fromIndex
,
toIndex
),
len
);
K
[]
a2
=
(
K
[])
new
Object
[
len
];
System
.
arraycopy
(
array
,
fromIndex
,
a2
,
0
,
toIndex
-
fromIndex
);
return
new
ImmutableArray2
<>(
a2
,
len
);
}
}
/**
/**
...
...
编写
预览
Markdown
格式
0%
重试
或
添加新文件
添加附件
取消
您添加了
0
人
到此讨论。请谨慎行事。
请先完成此评论的编辑!
取消
请
注册
或者
登录
后发表评论