Skip to content
项目
群组
代码片段
帮助
正在加载...
帮助
为 GitLab 提交贡献
登录/注册
切换导航
H
h2database
项目
项目
详情
活动
周期分析
仓库
仓库
文件
提交
分支
标签
贡献者
分枝图
比较
统计图
议题
0
议题
0
列表
看板
标记
里程碑
合并请求
0
合并请求
0
CI / CD
CI / CD
流水线
作业
计划
统计图
Wiki
Wiki
代码片段
代码片段
成员
成员
折叠边栏
关闭边栏
活动
分枝图
统计图
创建新议题
作业
提交
议题看板
打开侧边栏
Administrator
h2database
Commits
7ca819d6
提交
7ca819d6
authored
12月 21, 2016
作者:
Noel Grandin
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
remove StringUtils.fromCacheOrNew
since we require Java7, this is no longer necessary
上级
723cd75d
显示空白字符变更
内嵌
并排
正在显示
3 个修改的文件
包含
20 行增加
和
82 行删除
+20
-82
Parser.java
h2/src/main/org/h2/command/Parser.java
+6
-6
StringUtils.java
h2/src/main/org/h2/util/StringUtils.java
+0
-42
TestStringCache.java
h2/src/test/org/h2/test/unit/TestStringCache.java
+14
-34
没有找到文件。
h2/src/main/org/h2/command/Parser.java
浏览文件 @
7ca819d6
...
...
@@ -3267,7 +3267,7 @@ public class Parser {
}
i
++;
}
currentToken
=
StringUtils
.
fromCacheOrNew
(
sqlCommand
.
substring
(
currentToken
=
StringUtils
.
cache
(
sqlCommand
.
substring
(
start
,
i
));
currentTokenType
=
getTokenType
(
currentToken
);
parseIndex
=
i
;
...
...
@@ -3290,7 +3290,7 @@ public class Parser {
}
i
++;
}
currentToken
=
StringUtils
.
fromCacheOrNew
(
result
);
currentToken
=
StringUtils
.
cache
(
result
);
parseIndex
=
i
;
currentTokenQuoted
=
true
;
currentTokenType
=
IDENTIFIER
;
...
...
@@ -3386,7 +3386,7 @@ public class Parser {
}
currentToken
=
"'"
;
checkLiterals
(
true
);
currentValue
=
ValueString
.
get
(
StringUtils
.
fromCacheOrNew
(
result
),
currentValue
=
ValueString
.
get
(
StringUtils
.
cache
(
result
),
database
.
getMode
().
treatEmptyStringsAsNull
);
parseIndex
=
i
;
currentTokenType
=
VALUE
;
...
...
@@ -3401,7 +3401,7 @@ public class Parser {
result
=
sqlCommand
.
substring
(
begin
,
i
);
currentToken
=
"'"
;
checkLiterals
(
true
);
currentValue
=
ValueString
.
get
(
StringUtils
.
fromCacheOrNew
(
result
),
currentValue
=
ValueString
.
get
(
StringUtils
.
cache
(
result
),
database
.
getMode
().
treatEmptyStringsAsNull
);
parseIndex
=
i
;
currentTokenType
=
VALUE
;
...
...
@@ -4785,7 +4785,7 @@ public class Parser {
Query
withQuery
=
parseSelect
();
read
(
")"
);
withQuery
.
prepare
();
querySQL
=
StringUtils
.
fromCacheOrNew
(
withQuery
.
getPlanSQL
());
querySQL
=
StringUtils
.
cache
(
withQuery
.
getPlanSQL
());
ArrayList
<
Expression
>
withExpressions
=
withQuery
.
getExpressions
();
for
(
int
i
=
0
;
i
<
cols
.
length
;
++
i
)
{
columnTemplates
[
i
]
=
new
Column
(
cols
[
i
],
withExpressions
.
get
(
i
).
getType
());
...
...
@@ -4819,7 +4819,7 @@ public class Parser {
String
[]
cols
=
parseColumnList
();
command
.
setColumnNames
(
cols
);
}
String
select
=
StringUtils
.
fromCacheOrNew
(
sqlCommand
String
select
=
StringUtils
.
cache
(
sqlCommand
.
substring
(
parseIndex
));
read
(
"AS"
);
try
{
...
...
h2/src/main/org/h2/util/StringUtils.java
浏览文件 @
7ca819d6
...
...
@@ -9,7 +9,6 @@ import java.lang.ref.SoftReference;
import
java.net.URLEncoder
;
import
java.util.ArrayList
;
import
java.util.Locale
;
import
org.h2.api.ErrorCode
;
import
org.h2.engine.Constants
;
import
org.h2.engine.SysProperties
;
...
...
@@ -910,47 +909,6 @@ public class StringUtils {
return
s
;
}
/**
* Get a string from the cache, and if no such string has been found, create
* a new one with only this content. This solves out of memory problems if
* the string is a substring of another, large string. In Java, strings are
* shared, which could lead to memory problems. This avoid such problems.
*
* @param s the string
* @return a string that is guaranteed not be a substring of a large string
*/
public
static
String
fromCacheOrNew
(
String
s
)
{
if
(!
SysProperties
.
OBJECT_CACHE
)
{
return
s
;
}
if
(
s
==
null
)
{
return
s
;
}
else
if
(
s
.
length
()
==
0
)
{
return
""
;
}
int
hash
=
s
.
hashCode
();
String
[]
cache
=
getCache
();
int
index
=
hash
&
(
SysProperties
.
OBJECT_CACHE_SIZE
-
1
);
if
(
cache
==
null
)
{
return
s
;
}
String
cached
=
cache
[
index
];
if
(
cached
!=
null
)
{
if
(
s
.
equals
(
cached
))
{
return
cached
;
}
}
// create a new object that is not shared
// (to avoid out of memory if it is a substring of a big String)
// (not longer needed for Java 7 update 6 and newer,
// but the performance overhead is very small for those
// versions where it is not needed)
// NOPMD
s
=
new
String
(
s
);
cache
[
index
]
=
s
;
return
s
;
}
/**
* Clear the cache. This method is used for testing.
*/
...
...
h2/src/test/org/h2/test/unit/TestStringCache.java
浏览文件 @
7ca819d6
/*
* Copyright 2004-2014 H2 Group. Multiple-Licensed under the MPL 2.0,
*
and the EPL 1.0 (http://h2database.com/html/license.html).
*
Initial Developer: H2
Group
* Copyright 2004-2014 H2 Group. Multiple-Licensed under the MPL 2.0,
and the
*
EPL 1.0 (http://h2database.com/html/license.html). Initial Developer: H2
* Group
*/
package
org
.
h2
.
test
.
unit
;
import
java.util.Locale
;
import
java.util.Random
;
import
org.h2.test.TestBase
;
import
org.h2.util.StringUtils
;
...
...
@@ -23,7 +22,6 @@ public class TestStringCache extends TestBase {
private
final
Random
random
=
new
Random
(
1
);
private
final
String
[]
some
=
{
null
,
""
,
"ABC"
,
"this is a medium sized string"
,
"1"
,
"2"
};
private
boolean
returnNew
;
private
boolean
useIntern
;
/**
...
...
@@ -40,11 +38,6 @@ public class TestStringCache extends TestBase {
@Override
public
void
test
()
throws
InterruptedException
{
testToUpperToLower
();
returnNew
=
true
;
StringUtils
.
clearCache
();
testSingleThread
(
getSize
(
5000
,
20000
));
testMultiThreads
();
returnNew
=
false
;
StringUtils
.
clearCache
();
testSingleThread
(
getSize
(
5000
,
20000
));
testMultiThreads
();
...
...
@@ -105,7 +98,6 @@ public class TestStringCache extends TestBase {
testToUpperCache
();
testToUpperCache
();
testToUpperCache
();
returnNew
=
false
;
for
(
int
i
=
0
;
i
<
6
;
i
++)
{
useIntern
=
(
i
%
2
)
==
0
;
long
time
=
System
.
currentTimeMillis
();
...
...
@@ -124,7 +116,8 @@ public class TestStringCache extends TestBase {
}
return
s
;
}
int
len
=
random
.
nextBoolean
()
?
random
.
nextInt
(
1000
)
:
random
.
nextInt
(
10
);
int
len
=
random
.
nextBoolean
()
?
random
.
nextInt
(
1000
)
:
random
.
nextInt
(
10
);
StringBuilder
buff
=
new
StringBuilder
(
len
);
for
(
int
i
=
0
;
i
<
len
;
i
++)
{
buff
.
append
(
random
.
nextInt
(
0xfff
));
...
...
@@ -137,18 +130,6 @@ public class TestStringCache extends TestBase {
*/
void
testString
()
{
String
a
=
randomString
();
if
(
returnNew
)
{
String
b
=
StringUtils
.
fromCacheOrNew
(
a
);
try
{
assertEquals
(
a
,
b
);
}
catch
(
Exception
e
)
{
TestBase
.
logError
(
"error"
,
e
);
}
if
(
a
!=
null
&&
a
==
b
&&
a
.
length
()
>
0
)
{
throw
new
AssertionError
(
"a="
+
System
.
identityHashCode
(
a
)
+
" b="
+
System
.
identityHashCode
(
b
));
}
}
else
{
String
b
;
if
(
useIntern
)
{
b
=
a
==
null
?
null
:
a
.
intern
();
...
...
@@ -161,7 +142,6 @@ public class TestStringCache extends TestBase {
TestBase
.
logError
(
"error"
,
e
);
}
}
}
private
void
testSingleThread
(
int
len
)
{
for
(
int
i
=
0
;
i
<
len
;
i
++)
{
...
...
编写
预览
Markdown
格式
0%
重试
或
添加新文件
添加附件
取消
您添加了
0
人
到此讨论。请谨慎行事。
请先完成此评论的编辑!
取消
请
注册
或者
登录
后发表评论