Skip to content
项目
群组
代码片段
帮助
正在加载...
帮助
为 GitLab 提交贡献
登录/注册
切换导航
H
h2database
项目
项目
详情
活动
周期分析
仓库
仓库
文件
提交
分支
标签
贡献者
分枝图
比较
统计图
议题
0
议题
0
列表
看板
标记
里程碑
合并请求
0
合并请求
0
CI / CD
CI / CD
流水线
作业
计划
统计图
Wiki
Wiki
代码片段
代码片段
成员
成员
折叠边栏
关闭边栏
活动
分枝图
统计图
创建新议题
作业
提交
议题看板
打开侧边栏
Administrator
h2database
Commits
ca14d3bc
Unverified
提交
ca14d3bc
authored
7 年前
作者:
Noel Grandin
提交者:
GitHub
7 年前
浏览文件
操作
浏览文件
下载
差异文件
Merge pull request #1040 from turbanoff/master
generate less garbage for String substring+trim
上级
781f90d6
abbcc8fe
隐藏空白字符变更
内嵌
并排
正在显示
7 个修改的文件
包含
39 行增加
和
8 行删除
+39
-8
DbContextRule.java
h2/src/main/org/h2/bnf/context/DbContextRule.java
+3
-3
Parser.java
h2/src/main/org/h2/command/Parser.java
+1
-1
JdbcDatabaseMetaData.java
h2/src/main/org/h2/jdbc/JdbcDatabaseMetaData.java
+3
-2
PageParser.java
h2/src/main/org/h2/server/web/PageParser.java
+2
-1
WebThread.java
h2/src/main/org/h2/server/web/WebThread.java
+1
-1
StringUtils.java
h2/src/main/org/h2/util/StringUtils.java
+18
-0
TestStringUtils.java
h2/src/test/org/h2/test/unit/TestStringUtils.java
+11
-0
没有找到文件。
h2/src/main/org/h2/bnf/context/DbContextRule.java
浏览文件 @
ca14d3bc
...
@@ -244,9 +244,9 @@ public class DbContextRule implements Rule {
...
@@ -244,9 +244,9 @@ public class DbContextRule implements Rule {
}
}
String
incompleteSentence
=
sentence
.
getQueryUpper
();
String
incompleteSentence
=
sentence
.
getQueryUpper
();
String
incompleteFunctionName
=
incompleteSentence
;
String
incompleteFunctionName
=
incompleteSentence
;
i
f
(
incompleteSentence
.
contains
(
"("
))
{
i
nt
bracketIndex
=
incompleteSentence
.
indexOf
(
'('
);
incompleteFunctionName
=
incompleteSentence
.
substring
(
0
,
if
(
bracketIndex
!=
-
1
)
{
incompleteSentence
.
indexOf
(
'('
)).
trim
(
);
incompleteFunctionName
=
StringUtils
.
trimSubstring
(
incompleteSentence
,
0
,
bracketIndex
);
}
}
// Common elements
// Common elements
...
...
This diff is collapsed.
Click to expand it.
h2/src/main/org/h2/command/Parser.java
浏览文件 @
ca14d3bc
...
@@ -2343,7 +2343,7 @@ public class Parser {
...
@@ -2343,7 +2343,7 @@ public class Parser {
}
}
private
void
setSQL
(
Prepared
command
,
String
start
,
int
startIndex
)
{
private
void
setSQL
(
Prepared
command
,
String
start
,
int
startIndex
)
{
String
sql
=
originalSQL
.
substring
(
startIndex
,
lastParseIndex
).
trim
(
);
String
sql
=
StringUtils
.
trimSubstring
(
originalSQL
,
startIndex
,
lastParseIndex
);
if
(
start
!=
null
)
{
if
(
start
!=
null
)
{
sql
=
start
+
" "
+
sql
;
sql
=
start
+
" "
+
sql
;
}
}
...
...
This diff is collapsed.
Click to expand it.
h2/src/main/org/h2/jdbc/JdbcDatabaseMetaData.java
浏览文件 @
ca14d3bc
...
@@ -1644,9 +1644,10 @@ public class JdbcDatabaseMetaData extends TraceObject implements
...
@@ -1644,9 +1644,10 @@ public class JdbcDatabaseMetaData extends TraceObject implements
for
(
String
a
:
array
)
{
for
(
String
a
:
array
)
{
buff
.
appendExceptFirst
(
","
);
buff
.
appendExceptFirst
(
","
);
String
f
=
a
.
trim
();
String
f
=
a
.
trim
();
if
(
f
.
indexOf
(
' '
)
>=
0
)
{
int
spaceIndex
=
f
.
indexOf
(
' '
);
if
(
spaceIndex
>=
0
)
{
// remove 'Function' from 'INSERT Function'
// remove 'Function' from 'INSERT Function'
f
=
f
.
substring
(
0
,
f
.
indexOf
(
' '
)).
trim
(
);
f
=
StringUtils
.
trimSubstring
(
f
,
0
,
spaceIndex
);
}
}
buff
.
append
(
f
);
buff
.
append
(
f
);
}
}
...
...
This diff is collapsed.
Click to expand it.
h2/src/main/org/h2/server/web/PageParser.java
浏览文件 @
ca14d3bc
...
@@ -10,6 +10,7 @@ import java.util.HashMap;
...
@@ -10,6 +10,7 @@ import java.util.HashMap;
import
java.util.List
;
import
java.util.List
;
import
java.util.Map
;
import
java.util.Map
;
import
org.h2.util.New
;
import
org.h2.util.New
;
import
org.h2.util.StringUtils
;
/**
/**
* A page parser can parse an HTML page and replace the tags there.
* A page parser can parse an HTML page and replace the tags there.
...
@@ -141,7 +142,7 @@ public class PageParser {
...
@@ -141,7 +142,7 @@ public class PageParser {
setError
(
i
);
setError
(
i
);
return
;
return
;
}
}
String
item
=
p
.
substring
(
i
,
j
).
trim
(
);
String
item
=
StringUtils
.
trimSubstring
(
p
,
i
,
j
);
i
=
j
;
i
=
j
;
String
s
=
(
String
)
get
(
item
);
String
s
=
(
String
)
get
(
item
);
replaceTags
(
s
);
replaceTags
(
s
);
...
...
This diff is collapsed.
Click to expand it.
h2/src/main/org/h2/server/web/WebThread.java
浏览文件 @
ca14d3bc
...
@@ -115,7 +115,7 @@ class WebThread extends WebApp implements Runnable {
...
@@ -115,7 +115,7 @@ class WebThread extends WebApp implements Runnable {
if
(
begin
<
0
||
end
<
begin
)
{
if
(
begin
<
0
||
end
<
begin
)
{
file
=
""
;
file
=
""
;
}
else
{
}
else
{
file
=
head
.
substring
(
begin
+
1
,
end
).
trim
(
);
file
=
StringUtils
.
trimSubstring
(
head
,
begin
+
1
,
end
);
}
}
trace
(
head
+
": "
+
file
);
trace
(
head
+
": "
+
file
);
file
=
getAllowedFile
(
file
);
file
=
getAllowedFile
(
file
);
...
...
This diff is collapsed.
Click to expand it.
h2/src/main/org/h2/util/StringUtils.java
浏览文件 @
ca14d3bc
...
@@ -862,6 +862,24 @@ public class StringUtils {
...
@@ -862,6 +862,24 @@ public class StringUtils {
return
s
.
substring
(
begin
,
end
);
return
s
.
substring
(
begin
,
end
);
}
}
/**
* Trim a character from a substring. Equivalence of {@code substring(begin, end).trim()}.
*
* @param s the string
* @param beginIndex start index of substring (inclusive)
* @param endIndex end index of substring (exclusive)
* @return trimmed substring
*/
public
static
String
trimSubstring
(
String
s
,
int
beginIndex
,
int
endIndex
)
{
while
(
beginIndex
<
endIndex
&&
s
.
charAt
(
beginIndex
)
<=
' '
)
{
beginIndex
++;
}
while
(
beginIndex
<
endIndex
&&
s
.
charAt
(
endIndex
-
1
)
<=
' '
)
{
endIndex
--;
}
return
s
.
substring
(
beginIndex
,
endIndex
);
}
/**
/**
* Get the string from the cache if possible. If the string has not been
* 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,
* found, it is added to the cache. If there is such a string in the cache,
...
...
This diff is collapsed.
Click to expand it.
h2/src/test/org/h2/test/unit/TestStringUtils.java
浏览文件 @
ca14d3bc
...
@@ -40,6 +40,7 @@ public class TestStringUtils extends TestBase {
...
@@ -40,6 +40,7 @@ public class TestStringUtils extends TestBase {
testPad
();
testPad
();
testReplaceAll
();
testReplaceAll
();
testTrim
();
testTrim
();
testTrimSubstring
();
}
}
private
void
testHex
()
{
private
void
testHex
()
{
...
@@ -252,5 +253,15 @@ public class TestStringUtils extends TestBase {
...
@@ -252,5 +253,15 @@ public class TestStringUtils extends TestBase {
StringUtils
.
trim
(
"zzbbzz"
,
true
,
true
,
"z"
));
StringUtils
.
trim
(
"zzbbzz"
,
true
,
true
,
"z"
));
}
}
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
));
new
AssertThrows
(
StringIndexOutOfBoundsException
.
class
)
{
@Override
public
void
test
()
{
StringUtils
.
trimSubstring
(
" with ("
,
1
,
8
);
}
};
}
}
}
This diff is collapsed.
Click to expand it.
编写
预览
Markdown
格式
0%
重试
或
添加新文件
添加附件
取消
您添加了
0
人
到此讨论。请谨慎行事。
请先完成此评论的编辑!
取消
请
注册
或者
登录
后发表评论