Skip to content
项目
群组
代码片段
帮助
正在加载...
帮助
为 GitLab 提交贡献
登录/注册
切换导航
H
h2database
项目
项目
详情
活动
周期分析
仓库
仓库
文件
提交
分支
标签
贡献者
分枝图
比较
统计图
议题
0
议题
0
列表
看板
标记
里程碑
合并请求
0
合并请求
0
CI / CD
CI / CD
流水线
作业
计划
统计图
Wiki
Wiki
代码片段
代码片段
成员
成员
折叠边栏
关闭边栏
活动
分枝图
统计图
创建新议题
作业
提交
议题看板
打开侧边栏
Administrator
h2database
Commits
1da8c499
提交
1da8c499
authored
15 年前
作者:
Thomas Mueller
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
Use signum and compare methods.
上级
ff4d721e
隐藏空白字符变更
内嵌
并排
正在显示
18 个修改的文件
包含
59 行增加
和
50 行删除
+59
-50
BaseIndex.java
h2/src/main/org/h2/index/BaseIndex.java
+2
-1
MultiVersionCursor.java
h2/src/main/org/h2/index/MultiVersionCursor.java
+2
-1
WebServer.java
h2/src/main/org/h2/server/web/WebServer.java
+1
-2
ConvertTraceFile.java
h2/src/main/org/h2/tools/ConvertTraceFile.java
+3
-2
ByteUtils.java
h2/src/main/org/h2/util/ByteUtils.java
+1
-2
CacheObject.java
h2/src/main/org/h2/util/CacheObject.java
+1
-3
MathUtils.java
h2/src/main/org/h2/util/MathUtils.java
+24
-0
ValueByte.java
h2/src/main/org/h2/value/ValueByte.java
+3
-5
ValueDate.java
h2/src/main/org/h2/value/ValueDate.java
+1
-2
ValueDecimal.java
h2/src/main/org/h2/value/ValueDecimal.java
+1
-2
ValueInt.java
h2/src/main/org/h2/value/ValueInt.java
+3
-5
ValueLob.java
h2/src/main/org/h2/value/ValueLob.java
+1
-2
ValueLong.java
h2/src/main/org/h2/value/ValueLong.java
+8
-10
ValueShort.java
h2/src/main/org/h2/value/ValueShort.java
+3
-5
ValueTime.java
h2/src/main/org/h2/value/ValueTime.java
+1
-2
ValueTimestamp.java
h2/src/main/org/h2/value/ValueTimestamp.java
+1
-2
ValueUuid.java
h2/src/main/org/h2/value/ValueUuid.java
+2
-1
TestAll.java
h2/src/test/org/h2/test/TestAll.java
+1
-3
没有找到文件。
h2/src/main/org/h2/index/BaseIndex.java
浏览文件 @
1da8c499
...
...
@@ -22,6 +22,7 @@ import org.h2.schema.SchemaObjectBase;
import
org.h2.table.Column
;
import
org.h2.table.IndexColumn
;
import
org.h2.table.Table
;
import
org.h2.util.MathUtils
;
import
org.h2.util.StatementBuilder
;
import
org.h2.util.StringUtils
;
import
org.h2.value.Value
;
...
...
@@ -280,7 +281,7 @@ public abstract class BaseIndex extends SchemaObjectBase implements Index {
if
(
isMultiVersion
)
{
int
v1
=
rowData
.
getVersion
();
int
v2
=
compare
.
getVersion
();
return
v1
==
v2
?
0
:
v1
<
v2
?
1
:
-
1
;
return
MathUtils
.
compare
(
v2
,
v1
)
;
}
return
0
;
}
...
...
This diff is collapsed.
Click to expand it.
h2/src/main/org/h2/index/MultiVersionCursor.java
浏览文件 @
1da8c499
...
...
@@ -12,6 +12,7 @@ import org.h2.engine.Session;
import
org.h2.message.Message
;
import
org.h2.result.Row
;
import
org.h2.result.SearchRow
;
import
org.h2.util.MathUtils
;
/**
* The cursor implementation for the multi-version index.
...
...
@@ -149,7 +150,7 @@ public class MultiVersionCursor implements Cursor {
// version would be compared as well
long
k1
=
deltaRow
.
getKey
();
long
k2
=
baseRow
.
getKey
();
compare
=
k1
==
k2
?
0
:
k1
>
k2
?
1
:
-
1
;
compare
=
MathUtils
.
compare
(
k1
,
k2
)
;
}
if
(
compare
==
0
)
{
if
(
isDeleted
)
{
...
...
This diff is collapsed.
Click to expand it.
h2/src/main/org/h2/server/web/WebServer.java
浏览文件 @
1da8c499
...
...
@@ -550,8 +550,7 @@ public class WebServer implements Service {
}
Collections
.
sort
(
settings
,
new
Comparator
<
ConnectionInfo
>()
{
public
int
compare
(
ConnectionInfo
o1
,
ConnectionInfo
o2
)
{
int
c
=
o2
.
lastAccess
-
o1
.
lastAccess
;
return
c
<
0
?
-
1
:
c
>
0
?
1
:
0
;
return
MathUtils
.
compare
(
o2
.
lastAccess
,
o1
.
lastAccess
);
}
}
);
...
...
This diff is collapsed.
Click to expand it.
h2/src/main/org/h2/tools/ConvertTraceFile.java
浏览文件 @
1da8c499
...
...
@@ -17,6 +17,7 @@ import java.util.StringTokenizer;
import
org.h2.message.Message
;
import
org.h2.util.FileUtils
;
import
org.h2.util.IOUtils
;
import
org.h2.util.MathUtils
;
import
org.h2.util.New
;
import
org.h2.util.StringUtils
;
import
org.h2.util.Tool
;
...
...
@@ -45,9 +46,9 @@ public class ConvertTraceFile extends Tool {
if
(
other
==
this
)
{
return
0
;
}
int
c
=
other
.
time
>
time
?
1
:
other
.
time
<
time
?
-
1
:
0
;
int
c
=
MathUtils
.
compare
(
other
.
time
,
time
)
;
if
(
c
==
0
)
{
c
=
other
.
executeCount
>
executeCount
?
1
:
other
.
executeCount
<
executeCount
?
-
1
:
0
;
c
=
MathUtils
.
compare
(
other
.
executeCount
,
executeCount
)
;
if
(
c
==
0
)
{
c
=
sql
.
compareTo
(
other
.
sql
);
}
...
...
This diff is collapsed.
Click to expand it.
h2/src/main/org/h2/util/ByteUtils.java
浏览文件 @
1da8c499
...
...
@@ -212,8 +212,7 @@ public class ByteUtils {
return
b
>
b2
?
1
:
-
1
;
}
}
int
c
=
data1
.
length
-
data2
.
length
;
return
c
==
0
?
0
:
(
c
<
0
?
-
1
:
1
);
return
Integer
.
signum
(
data1
.
length
-
data2
.
length
);
}
/**
...
...
This diff is collapsed.
Click to expand it.
h2/src/main/org/h2/util/CacheObject.java
浏览文件 @
1da8c499
...
...
@@ -22,9 +22,7 @@ public abstract class CacheObject {
*/
static
class
CacheComparator
implements
Comparator
<
CacheObject
>
{
public
int
compare
(
CacheObject
a
,
CacheObject
b
)
{
int
pa
=
a
.
getPos
();
int
pb
=
b
.
getPos
();
return
pa
==
pb
?
0
:
(
pa
<
pb
?
-
1
:
1
);
return
MathUtils
.
compare
(
a
.
getPos
(),
b
.
getPos
());
}
}
...
...
This diff is collapsed.
Click to expand it.
h2/src/main/org/h2/util/MathUtils.java
浏览文件 @
1da8c499
...
...
@@ -205,4 +205,28 @@ public class MathUtils {
return
(
reverse
((
int
)
(
x
>>>
32L
))
&
0xffffffff
L
)
^
(((
long
)
reverse
((
int
)
x
))
<<
32L
);
}
/**
* Compare two values. Returns -1 if the first value is smaller, 1 if bigger,
* and 0 if equal.
*
* @param a the first value
* @param b the second value
* @return the result
*/
public
static
int
compare
(
int
a
,
int
b
)
{
return
a
==
b
?
0
:
a
<
b
?
-
1
:
1
;
}
/**
* Compare two values. Returns -1 if the first value is smaller, 1 if bigger,
* and 0 if equal.
*
* @param a the first value
* @param b the second value
* @return the result
*/
public
static
int
compare
(
long
a
,
long
b
)
{
return
a
==
b
?
0
:
a
<
b
?
-
1
:
1
;
}
}
This diff is collapsed.
Click to expand it.
h2/src/main/org/h2/value/ValueByte.java
浏览文件 @
1da8c499
...
...
@@ -11,6 +11,7 @@ import java.sql.SQLException;
import
org.h2.constant.ErrorCode
;
import
org.h2.constant.SysProperties
;
import
org.h2.message.Message
;
import
org.h2.util.MathUtils
;
/**
* Implementation of the BYTE data type.
...
...
@@ -50,7 +51,7 @@ public class ValueByte extends Value {
}
public
int
getSignum
()
{
return
value
==
0
?
0
:
(
value
<
0
?
-
1
:
1
);
return
Integer
.
signum
(
value
);
}
public
Value
negate
()
throws
SQLException
{
...
...
@@ -98,10 +99,7 @@ public class ValueByte extends Value {
protected
int
compareSecure
(
Value
o
,
CompareMode
mode
)
{
ValueByte
v
=
(
ValueByte
)
o
;
if
(
value
==
v
.
value
)
{
return
0
;
}
return
value
>
v
.
value
?
1
:
-
1
;
return
MathUtils
.
compare
(
value
,
v
.
value
);
}
public
String
getString
()
{
...
...
This diff is collapsed.
Click to expand it.
h2/src/main/org/h2/value/ValueDate.java
浏览文件 @
1da8c499
...
...
@@ -65,8 +65,7 @@ public class ValueDate extends Value {
protected
int
compareSecure
(
Value
o
,
CompareMode
mode
)
{
ValueDate
v
=
(
ValueDate
)
o
;
int
c
=
value
.
compareTo
(
v
.
value
);
return
c
==
0
?
0
:
(
c
<
0
?
-
1
:
1
);
return
Integer
.
signum
(
value
.
compareTo
(
v
.
value
));
}
public
String
getString
()
{
...
...
This diff is collapsed.
Click to expand it.
h2/src/main/org/h2/value/ValueDecimal.java
浏览文件 @
1da8c499
...
...
@@ -115,8 +115,7 @@ public class ValueDecimal extends Value {
protected
int
compareSecure
(
Value
o
,
CompareMode
mode
)
{
ValueDecimal
v
=
(
ValueDecimal
)
o
;
int
c
=
value
.
compareTo
(
v
.
value
);
return
c
==
0
?
0
:
(
c
<
0
?
-
1
:
1
);
return
value
.
compareTo
(
v
.
value
);
}
public
int
getSignum
()
{
...
...
This diff is collapsed.
Click to expand it.
h2/src/main/org/h2/value/ValueInt.java
浏览文件 @
1da8c499
...
...
@@ -11,6 +11,7 @@ import java.sql.SQLException;
import
org.h2.constant.ErrorCode
;
import
org.h2.constant.SysProperties
;
import
org.h2.message.Message
;
import
org.h2.util.MathUtils
;
/**
* Implementation of the INT data type.
...
...
@@ -80,7 +81,7 @@ public class ValueInt extends Value {
}
public
int
getSignum
()
{
return
value
==
0
?
0
:
(
value
<
0
?
-
1
:
1
);
return
Integer
.
signum
(
value
);
}
public
Value
negate
()
throws
SQLException
{
...
...
@@ -132,10 +133,7 @@ public class ValueInt extends Value {
protected
int
compareSecure
(
Value
o
,
CompareMode
mode
)
{
ValueInt
v
=
(
ValueInt
)
o
;
if
(
value
==
v
.
value
)
{
return
0
;
}
return
value
>
v
.
value
?
1
:
-
1
;
return
MathUtils
.
compare
(
value
,
v
.
value
);
}
public
String
getString
()
{
...
...
This diff is collapsed.
Click to expand it.
h2/src/main/org/h2/value/ValueLob.java
浏览文件 @
1da8c499
...
...
@@ -614,8 +614,7 @@ public class ValueLob extends Value {
protected
int
compareSecure
(
Value
v
,
CompareMode
mode
)
throws
SQLException
{
if
(
type
==
Value
.
CLOB
)
{
int
c
=
getString
().
compareTo
(
v
.
getString
());
return
c
==
0
?
0
:
(
c
<
0
?
-
1
:
1
);
return
Integer
.
signum
(
getString
().
compareTo
(
v
.
getString
()));
}
byte
[]
v2
=
v
.
getBytesNoCopy
();
return
ByteUtils
.
compareNotNull
(
getBytes
(),
v2
);
...
...
This diff is collapsed.
Click to expand it.
h2/src/main/org/h2/value/ValueLong.java
浏览文件 @
1da8c499
...
...
@@ -12,6 +12,7 @@ import java.sql.SQLException;
import
org.h2.constant.ErrorCode
;
import
org.h2.constant.SysProperties
;
import
org.h2.message.Message
;
import
org.h2.util.MathUtils
;
/**
* Implementation of the BIGINT data type.
...
...
@@ -51,9 +52,9 @@ public class ValueLong extends Value {
ValueLong
other
=
(
ValueLong
)
v
;
if
(
SysProperties
.
OVERFLOW_EXCEPTIONS
)
{
long
result
=
value
+
other
.
value
;
int
sv
=
value
==
0
?
0
:
(
value
<
0
?
-
1
:
1
);
int
so
=
other
.
value
==
0
?
0
:
(
other
.
value
<
0
?
-
1
:
1
);
int
sr
=
result
==
0
?
0
:
(
result
<
0
?
-
1
:
1
);
int
sv
=
Long
.
signum
(
value
);
int
so
=
Long
.
signum
(
other
.
value
);
int
sr
=
Long
.
signum
(
result
);
// if the operands have different signs overflow can not occur
// if the operands have the same sign,
// and the result has a different sign, then it is an overflow
...
...
@@ -67,7 +68,7 @@ public class ValueLong extends Value {
}
public
int
getSignum
()
{
return
value
==
0
?
0
:
(
value
<
0
?
-
1
:
1
);
return
Long
.
signum
(
value
);
}
public
Value
negate
()
throws
SQLException
{
...
...
@@ -86,8 +87,8 @@ public class ValueLong extends Value {
public
Value
subtract
(
Value
v
)
throws
SQLException
{
ValueLong
other
=
(
ValueLong
)
v
;
if
(
SysProperties
.
OVERFLOW_EXCEPTIONS
)
{
int
sv
=
value
==
0
?
0
:
(
value
<
0
?
-
1
:
1
);
int
so
=
other
.
value
==
0
?
0
:
(
other
.
value
<
0
?
-
1
:
1
);
int
sv
=
Long
.
signum
(
value
);
int
so
=
Long
.
signum
(
other
.
value
);
// if the operands have the same sign, then overflow can not occur
// if the second operand is 0, then overflow can not occur
if
(
sv
==
so
||
so
==
0
)
{
...
...
@@ -152,10 +153,7 @@ public class ValueLong extends Value {
protected
int
compareSecure
(
Value
o
,
CompareMode
mode
)
{
ValueLong
v
=
(
ValueLong
)
o
;
if
(
value
==
v
.
value
)
{
return
0
;
}
return
value
>
v
.
value
?
1
:
-
1
;
return
MathUtils
.
compare
(
value
,
v
.
value
);
}
public
String
getString
()
{
...
...
This diff is collapsed.
Click to expand it.
h2/src/main/org/h2/value/ValueShort.java
浏览文件 @
1da8c499
...
...
@@ -11,6 +11,7 @@ import java.sql.SQLException;
import
org.h2.constant.ErrorCode
;
import
org.h2.constant.SysProperties
;
import
org.h2.message.Message
;
import
org.h2.util.MathUtils
;
/**
* Implementation of the SMALLINT data type.
...
...
@@ -50,7 +51,7 @@ public class ValueShort extends Value {
}
public
int
getSignum
()
{
return
value
==
0
?
0
:
(
value
<
0
?
-
1
:
1
);
return
Integer
.
signum
(
value
);
}
public
Value
negate
()
throws
SQLException
{
...
...
@@ -98,10 +99,7 @@ public class ValueShort extends Value {
protected
int
compareSecure
(
Value
o
,
CompareMode
mode
)
{
ValueShort
v
=
(
ValueShort
)
o
;
if
(
value
==
v
.
value
)
{
return
0
;
}
return
value
>
v
.
value
?
1
:
-
1
;
return
MathUtils
.
compare
(
value
,
v
.
value
);
}
public
String
getString
()
{
...
...
This diff is collapsed.
Click to expand it.
h2/src/main/org/h2/value/ValueTime.java
浏览文件 @
1da8c499
...
...
@@ -63,8 +63,7 @@ public class ValueTime extends Value {
protected
int
compareSecure
(
Value
o
,
CompareMode
mode
)
{
ValueTime
v
=
(
ValueTime
)
o
;
int
c
=
value
.
compareTo
(
v
.
value
);
return
c
==
0
?
0
:
(
c
<
0
?
-
1
:
1
);
return
Integer
.
signum
(
value
.
compareTo
(
v
.
value
));
}
public
String
getString
()
{
...
...
This diff is collapsed.
Click to expand it.
h2/src/main/org/h2/value/ValueTimestamp.java
浏览文件 @
1da8c499
...
...
@@ -79,8 +79,7 @@ public class ValueTimestamp extends Value {
protected
int
compareSecure
(
Value
o
,
CompareMode
mode
)
{
ValueTimestamp
v
=
(
ValueTimestamp
)
o
;
int
c
=
value
.
compareTo
(
v
.
value
);
return
c
==
0
?
0
:
(
c
<
0
?
-
1
:
1
);
return
Integer
.
signum
(
value
.
compareTo
(
v
.
value
));
}
public
String
getString
()
{
...
...
This diff is collapsed.
Click to expand it.
h2/src/main/org/h2/value/ValueUuid.java
浏览文件 @
1da8c499
...
...
@@ -11,6 +11,7 @@ import java.sql.SQLException;
import
java.util.UUID
;
import
org.h2.util.ByteUtils
;
import
org.h2.util.MathUtils
;
import
org.h2.util.RandomUtils
;
import
org.h2.util.StringUtils
;
...
...
@@ -147,7 +148,7 @@ public class ValueUuid extends Value {
}
ValueUuid
v
=
(
ValueUuid
)
o
;
if
(
high
==
v
.
high
)
{
return
(
low
==
v
.
low
)
?
0
:
(
low
>
v
.
low
?
1
:
-
1
);
return
MathUtils
.
compare
(
low
,
v
.
low
);
}
return
high
>
v
.
high
?
1
:
-
1
;
}
...
...
This diff is collapsed.
Click to expand it.
h2/src/test/org/h2/test/TestAll.java
浏览文件 @
1da8c499
...
...
@@ -297,11 +297,9 @@ java org.h2.test.TestAll timer
/*
serialized patches
check if sources.jar is not in installer and zip, but in h2web
documentation: rolling review at history.html
math utils compareTo?
toArray?
mvcc merge problem
...
...
This diff is collapsed.
Click to expand it.
编写
预览
Markdown
格式
0%
重试
或
添加新文件
添加附件
取消
您添加了
0
人
到此讨论。请谨慎行事。
请先完成此评论的编辑!
取消
请
注册
或者
登录
后发表评论