Skip to content
项目
群组
代码片段
帮助
正在加载...
帮助
为 GitLab 提交贡献
登录/注册
切换导航
H
h2database
项目
项目
详情
活动
周期分析
仓库
仓库
文件
提交
分支
标签
贡献者
分枝图
比较
统计图
议题
0
议题
0
列表
看板
标记
里程碑
合并请求
0
合并请求
0
CI / CD
CI / CD
流水线
作业
计划
统计图
Wiki
Wiki
代码片段
代码片段
成员
成员
折叠边栏
关闭边栏
活动
分枝图
统计图
创建新议题
作业
提交
议题看板
打开侧边栏
Administrator
h2database
Commits
5a1c0bb5
提交
5a1c0bb5
authored
11月 07, 2018
作者:
Evgenij Ryazanov
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
Reduce memory allocation in Parser.setSQL()
上级
fcd4160d
隐藏空白字符变更
内嵌
并排
正在显示
4 个修改的文件
包含
46 行增加
和
11 行删除
+46
-11
Parser.java
h2/src/main/org/h2/command/Parser.java
+7
-2
JdbcDatabaseMetaData.java
h2/src/main/org/h2/jdbc/JdbcDatabaseMetaData.java
+3
-2
StringUtils.java
h2/src/main/org/h2/util/StringUtils.java
+23
-2
TestStringUtils.java
h2/src/test/org/h2/test/unit/TestStringUtils.java
+13
-5
没有找到文件。
h2/src/main/org/h2/command/Parser.java
浏览文件 @
5a1c0bb5
...
...
@@ -2687,9 +2687,14 @@ public class Parser {
}
private
void
setSQL
(
Prepared
command
,
String
start
,
int
startIndex
)
{
String
sql
=
StringUtils
.
trimSubstring
(
originalSQL
,
startIndex
,
lastParseIndex
);
int
endIndex
=
lastParseIndex
;
String
sql
;
if
(
start
!=
null
)
{
sql
=
start
+
" "
+
sql
;
StringBuilder
builder
=
new
StringBuilder
(
start
.
length
()
+
endIndex
-
startIndex
+
1
)
.
append
(
start
).
append
(
' '
);
sql
=
StringUtils
.
trimSubstring
(
builder
,
originalSQL
,
startIndex
,
endIndex
).
toString
();
}
else
{
sql
=
StringUtils
.
trimSubstring
(
originalSQL
,
startIndex
,
endIndex
);
}
command
.
setSQL
(
sql
);
}
...
...
h2/src/main/org/h2/jdbc/JdbcDatabaseMetaData.java
浏览文件 @
5a1c0bb5
...
...
@@ -1624,9 +1624,10 @@ public class JdbcDatabaseMetaData extends TraceObject implements
int
spaceIndex
=
f
.
indexOf
(
' '
);
if
(
spaceIndex
>=
0
)
{
// remove 'Function' from 'INSERT Function'
f
=
StringUtils
.
trimSubstring
(
f
,
0
,
spaceIndex
);
StringUtils
.
trimSubstring
(
buff
.
builder
(),
f
,
0
,
spaceIndex
);
}
else
{
buff
.
append
(
f
);
}
buff
.
append
(
f
);
}
}
rs
.
close
();
...
...
h2/src/main/org/h2/util/StringUtils.java
浏览文件 @
5a1c0bb5
...
...
@@ -872,7 +872,7 @@ public class StringUtils {
}
/**
* Trim a
character
from a substring. Equivalent of
* Trim a
whitespace
from a substring. Equivalent of
* {@code substring(beginIndex).trim()}.
*
* @param s the string
...
...
@@ -884,7 +884,7 @@ public class StringUtils {
}
/**
* Trim a
character
from a substring. Equivalent of
* Trim a
whitespace
from a substring. Equivalent of
* {@code substring(beginIndex, endIndex).trim()}.
*
* @param s the string
...
...
@@ -902,6 +902,27 @@ public class StringUtils {
return
s
.
substring
(
beginIndex
,
endIndex
);
}
/**
* Trim a whitespace from a substring and append it to a specified string
* builder. Equivalent of
* {@code builder.append(substring(beginIndex, endIndex).trim())}.
*
* @param builder string builder to append to
* @param s the string
* @param beginIndex start index of substring (inclusive)
* @param endIndex end index of substring (exclusive)
* @return the specified builder
*/
public
static
StringBuilder
trimSubstring
(
StringBuilder
builder
,
String
s
,
int
beginIndex
,
int
endIndex
)
{
while
(
beginIndex
<
endIndex
&&
s
.
charAt
(
beginIndex
)
<=
' '
)
{
beginIndex
++;
}
while
(
beginIndex
<
endIndex
&&
s
.
charAt
(
endIndex
-
1
)
<=
' '
)
{
endIndex
--;
}
return
builder
.
append
(
s
,
beginIndex
,
endIndex
);
}
/**
* Get the string from the cache if possible. If the string has not been
* found, it is added to the cache. If there is such a string in the cache,
...
...
h2/src/test/org/h2/test/unit/TestStringUtils.java
浏览文件 @
5a1c0bb5
...
...
@@ -281,14 +281,22 @@ public class TestStringUtils extends TestBase {
}
private
void
testTrimSubstring
()
{
assertEquals
(
""
,
StringUtils
.
trimSubstring
(
""
,
0
,
0
));
assertEquals
(
""
,
StringUtils
.
trimSubstring
(
" "
,
0
,
0
));
assertEquals
(
""
,
StringUtils
.
trimSubstring
(
" "
,
4
,
4
));
assertEquals
(
"select"
,
StringUtils
.
trimSubstring
(
" select from"
,
1
,
7
));
assertEquals
(
"a b"
,
StringUtils
.
trimSubstring
(
" a b "
,
1
,
4
));
testTrimSubstringImpl
(
""
,
""
,
0
,
0
);
testTrimSubstringImpl
(
""
,
" "
,
0
,
0
);
testTrimSubstringImpl
(
""
,
" "
,
4
,
4
);
testTrimSubstringImpl
(
"select"
,
" select from"
,
1
,
7
);
testTrimSubstringImpl
(
"a b"
,
" a b "
,
1
,
4
);
testTrimSubstringImpl
(
"a b"
,
" a b "
,
1
,
5
);
testTrimSubstringImpl
(
"b"
,
" a b "
,
2
,
5
);
new
AssertThrows
(
StringIndexOutOfBoundsException
.
class
)
{
@Override
public
void
test
()
{
StringUtils
.
trimSubstring
(
" with ("
,
1
,
8
);
}
};
}
private
void
testTrimSubstringImpl
(
String
expected
,
String
string
,
int
startIndex
,
int
endIndex
)
{
assertEquals
(
expected
,
StringUtils
.
trimSubstring
(
string
,
startIndex
,
endIndex
));
assertEquals
(
expected
,
StringUtils
.
trimSubstring
(
new
StringBuilder
(
endIndex
-
startIndex
),
string
,
startIndex
,
endIndex
).
toString
());
}
}
编写
预览
Markdown
格式
0%
重试
或
添加新文件
添加附件
取消
您添加了
0
人
到此讨论。请谨慎行事。
请先完成此评论的编辑!
取消
请
注册
或者
登录
后发表评论