Skip to content
项目
群组
代码片段
帮助
正在加载...
帮助
为 GitLab 提交贡献
登录/注册
切换导航
H
h2database
项目
项目
详情
活动
周期分析
仓库
仓库
文件
提交
分支
标签
贡献者
分枝图
比较
统计图
议题
0
议题
0
列表
看板
标记
里程碑
合并请求
0
合并请求
0
CI / CD
CI / CD
流水线
作业
计划
统计图
Wiki
Wiki
代码片段
代码片段
成员
成员
折叠边栏
关闭边栏
活动
分枝图
统计图
创建新议题
作业
提交
议题看板
打开侧边栏
Administrator
h2database
Commits
34d64980
提交
34d64980
authored
6 年前
作者:
Evgenij Ryazanov
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
Optimize ValueLong.add() and ValueLong.subtract()
上级
0407175b
master
version-1.4.198
无相关合并请求
隐藏空白字符变更
内嵌
并排
正在显示
1 个修改的文件
包含
20 行增加
和
22 行删除
+20
-22
ValueLong.java
h2/src/main/org/h2/value/ValueLong.java
+20
-22
没有找到文件。
h2/src/main/org/h2/value/ValueLong.java
浏览文件 @
34d64980
...
...
@@ -61,19 +61,17 @@ public class ValueLong extends Value {
@Override
public
Value
add
(
Value
v
)
{
ValueLong
other
=
(
ValueLong
)
v
;
long
result
=
value
+
other
.
value
;
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
// it can not be an overflow when one of the operands is 0
if
(
sv
!=
so
||
sr
==
so
||
sv
==
0
||
so
==
0
)
{
return
ValueLong
.
get
(
result
);
long
x
=
value
;
long
y
=
((
ValueLong
)
v
).
value
;
long
result
=
x
+
y
;
/*
* If signs of both summands are different from the sign of the sum there is an
* overflow.
*/
if
(((
x
^
result
)
&
(
y
^
result
))
<
0
)
{
throw
getOverflow
();
}
throw
getOverflow
(
);
return
ValueLong
.
get
(
result
);
}
@Override
...
...
@@ -96,17 +94,17 @@ public class ValueLong extends Value {
@Override
public
Value
subtract
(
Value
v
)
{
ValueLong
other
=
(
ValueLong
)
v
;
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
)
{
return
ValueLong
.
get
(
value
-
other
.
value
);
long
x
=
value
;
long
y
=
((
ValueLong
)
v
).
value
;
long
result
=
x
-
y
;
/*
* If minuend and subtrahend have different signs and minuend and difference
* have different signs there is an overflow.
*/
if
(((
x
^
y
)
&
(
x
^
result
))
<
0
)
{
throw
getOverflow
();
}
// now, if the other value is Long.MIN_VALUE, it must be an overflow
// x - Long.MIN_VALUE overflows for x>=0
return
add
(
other
.
negate
());
return
ValueLong
.
get
(
result
);
}
@Override
...
...
This diff is collapsed.
Click to expand it.
编写
预览
Markdown
格式
0%
重试
或
添加新文件
添加附件
取消
您添加了
0
人
到此讨论。请谨慎行事。
请先完成此评论的编辑!
取消
请
注册
或者
登录
后发表评论