Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
openanolis
dragonwell8_jdk
提交
e8cb5ad9
D
dragonwell8_jdk
项目概览
openanolis
/
dragonwell8_jdk
通知
4
Star
2
Fork
0
代码
文件
提交
分支
Tags
贡献者
分支图
Diff
Issue
0
列表
看板
标记
里程碑
合并请求
0
Wiki
0
Wiki
分析
仓库
DevOps
项目成员
Pages
D
dragonwell8_jdk
项目概览
项目概览
详情
发布
仓库
仓库
文件
提交
分支
标签
贡献者
分支图
比较
Issue
0
Issue
0
列表
看板
标记
里程碑
合并请求
0
合并请求
0
Pages
分析
分析
仓库分析
DevOps
Wiki
0
Wiki
成员
成员
收起侧边栏
关闭侧边栏
动态
分支图
创建新Issue
提交
Issue看板
提交
e8cb5ad9
编写于
5月 23, 2013
作者:
D
dl
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
8014076: Arrays parallel and serial sorting improvements
Reviewed-by: chegar, mduigou
上级
a441ff54
变更
6
展开全部
隐藏空白更改
内联
并排
Showing
6 changed file
with
2142 addition
and
2150 deletion
+2142
-2150
src/share/classes/java/util/Arrays.java
src/share/classes/java/util/Arrays.java
+947
-821
src/share/classes/java/util/ArraysParallelSortHelpers.java
src/share/classes/java/util/ArraysParallelSortHelpers.java
+864
-1077
src/share/classes/java/util/ComparableTimSort.java
src/share/classes/java/util/ComparableTimSort.java
+53
-42
src/share/classes/java/util/DualPivotQuicksort.java
src/share/classes/java/util/DualPivotQuicksort.java
+216
-156
src/share/classes/java/util/TimSort.java
src/share/classes/java/util/TimSort.java
+60
-52
test/java/util/Arrays/ParallelSorting.java
test/java/util/Arrays/ParallelSorting.java
+2
-2
未找到文件。
src/share/classes/java/util/Arrays.java
浏览文件 @
e8cb5ad9
此差异已折叠。
点击以展开。
src/share/classes/java/util/ArraysParallelSortHelpers.java
浏览文件 @
e8cb5ad9
此差异已折叠。
点击以展开。
src/share/classes/java/util/ComparableTimSort.java
浏览文件 @
e8cb5ad9
...
...
@@ -86,9 +86,13 @@ class ComparableTimSort {
private
static
final
int
INITIAL_TMP_STORAGE_LENGTH
=
256
;
/**
* Temp storage for merges.
* Temp storage for merges. A workspace array may optionally be
* provided in constructor, and if so will be used as long as it
* is big enough.
*/
private
Object
[]
tmp
;
private
int
tmpBase
;
// base of tmp array slice
private
int
tmpLen
;
// length of tmp array slice
/**
* A stack of pending runs yet to be merged. Run i starts at
...
...
@@ -108,15 +112,27 @@ class ComparableTimSort {
* Creates a TimSort instance to maintain the state of an ongoing sort.
*
* @param a the array to be sorted
* @param work a workspace array (slice)
* @param workBase origin of usable space in work array
* @param workLen usable size of work array
*/
private
ComparableTimSort
(
Object
[]
a
)
{
private
ComparableTimSort
(
Object
[]
a
,
Object
[]
work
,
int
workBase
,
int
workLen
)
{
this
.
a
=
a
;
// Allocate temp storage (which may be increased later if necessary)
int
len
=
a
.
length
;
Object
[]
newArray
=
new
Object
[
len
<
2
*
INITIAL_TMP_STORAGE_LENGTH
?
len
>>>
1
:
INITIAL_TMP_STORAGE_LENGTH
];
tmp
=
newArray
;
int
tlen
=
(
len
<
2
*
INITIAL_TMP_STORAGE_LENGTH
)
?
len
>>>
1
:
INITIAL_TMP_STORAGE_LENGTH
;
if
(
work
==
null
||
workLen
<
tlen
||
workBase
+
tlen
>
work
.
length
)
{
tmp
=
new
Object
[
tlen
];
tmpBase
=
0
;
tmpLen
=
tlen
;
}
else
{
tmp
=
work
;
tmpBase
=
workBase
;
tmpLen
=
workLen
;
}
/*
* Allocate runs-to-be-merged stack (which cannot be expanded). The
...
...
@@ -136,17 +152,28 @@ class ComparableTimSort {
}
/*
* The next two methods (which are package private and static) constitute
* the entire API of this class. Each of these methods obeys the contract
* of the public method with the same signature in java.util.Arrays.
* The next method (package private and static) constitutes the
* entire API of this class.
*/
static
void
sort
(
Object
[]
a
)
{
sort
(
a
,
0
,
a
.
length
);
}
/**
* Sorts the given range, using the given workspace array slice
* for temp storage when possible. This method is designed to be
* invoked from public methods (in class Arrays) after performing
* any necessary array bounds checks and expanding parameters into
* the required forms.
*
* @param a the array to be sorted
* @param lo the index of the first element, inclusive, to be sorted
* @param hi the index of the last element, exclusive, to be sorted
* @param work a workspace array (slice)
* @param workBase origin of usable space in work array
* @param workLen usable size of work array
* @since 1.8
*/
static
void
sort
(
Object
[]
a
,
int
lo
,
int
hi
,
Object
[]
work
,
int
workBase
,
int
workLen
)
{
assert
a
!=
null
&&
lo
>=
0
&&
lo
<=
hi
&&
hi
<=
a
.
length
;
static
void
sort
(
Object
[]
a
,
int
lo
,
int
hi
)
{
rangeCheck
(
a
.
length
,
lo
,
hi
);
int
nRemaining
=
hi
-
lo
;
if
(
nRemaining
<
2
)
return
;
// Arrays of size 0 and 1 are always sorted
...
...
@@ -163,7 +190,7 @@ class ComparableTimSort {
* extending short natural runs to minRun elements, and merging runs
* to maintain stack invariant.
*/
ComparableTimSort
ts
=
new
ComparableTimSort
(
a
);
ComparableTimSort
ts
=
new
ComparableTimSort
(
a
,
work
,
workBase
,
workLen
);
int
minRun
=
minRunLength
(
nRemaining
);
do
{
// Identify next run
...
...
@@ -619,11 +646,11 @@ class ComparableTimSort {
// Copy first run into temp array
Object
[]
a
=
this
.
a
;
// For performance
Object
[]
tmp
=
ensureCapacity
(
len1
);
System
.
arraycopy
(
a
,
base1
,
tmp
,
0
,
len1
);
int
cursor1
=
0
;
// Indexes into tmp array
int
cursor1
=
tmpBase
;
// Indexes into tmp array
int
cursor2
=
base2
;
// Indexes int a
int
dest
=
base1
;
// Indexes int a
System
.
arraycopy
(
a
,
base1
,
tmp
,
cursor1
,
len1
);
// Move first element of second run and deal with degenerate cases
a
[
dest
++]
=
a
[
cursor2
++];
...
...
@@ -736,16 +763,17 @@ class ComparableTimSort {
// Copy second run into temp array
Object
[]
a
=
this
.
a
;
// For performance
Object
[]
tmp
=
ensureCapacity
(
len2
);
System
.
arraycopy
(
a
,
base2
,
tmp
,
0
,
len2
);
int
tmpBase
=
this
.
tmpBase
;
System
.
arraycopy
(
a
,
base2
,
tmp
,
tmpBase
,
len2
);
int
cursor1
=
base1
+
len1
-
1
;
// Indexes into a
int
cursor2
=
len2
-
1
;
// Indexes into tmp array
int
cursor2
=
tmpBase
+
len2
-
1
;
// Indexes into tmp array
int
dest
=
base2
+
len2
-
1
;
// Indexes into a
// Move last element of first run and deal with degenerate cases
a
[
dest
--]
=
a
[
cursor1
--];
if
(--
len1
==
0
)
{
System
.
arraycopy
(
tmp
,
0
,
a
,
dest
-
(
len2
-
1
),
len2
);
System
.
arraycopy
(
tmp
,
tmpBase
,
a
,
dest
-
(
len2
-
1
),
len2
);
return
;
}
if
(
len2
==
1
)
{
...
...
@@ -803,7 +831,7 @@ class ComparableTimSort {
if
(--
len2
==
1
)
break
outer
;
count2
=
len2
-
gallopLeft
((
Comparable
)
a
[
cursor1
],
tmp
,
0
,
len2
,
len2
-
1
);
count2
=
len2
-
gallopLeft
((
Comparable
)
a
[
cursor1
],
tmp
,
tmpBase
,
len2
,
len2
-
1
);
if
(
count2
!=
0
)
{
dest
-=
count2
;
cursor2
-=
count2
;
...
...
@@ -835,7 +863,7 @@ class ComparableTimSort {
}
else
{
assert
len1
==
0
;
assert
len2
>
0
;
System
.
arraycopy
(
tmp
,
0
,
a
,
dest
-
(
len2
-
1
),
len2
);
System
.
arraycopy
(
tmp
,
tmpBase
,
a
,
dest
-
(
len2
-
1
),
len2
);
}
}
...
...
@@ -848,7 +876,7 @@ class ComparableTimSort {
* @return tmp, whether or not it grew
*/
private
Object
[]
ensureCapacity
(
int
minCapacity
)
{
if
(
tmp
.
length
<
minCapacity
)
{
if
(
tmp
Len
<
minCapacity
)
{
// Compute smallest power of 2 > minCapacity
int
newSize
=
minCapacity
;
newSize
|=
newSize
>>
1
;
...
...
@@ -863,30 +891,13 @@ class ComparableTimSort {
else
newSize
=
Math
.
min
(
newSize
,
a
.
length
>>>
1
);
@SuppressWarnings
({
"unchecked"
,
"UnnecessaryLocalVariable"
})
Object
[]
newArray
=
new
Object
[
newSize
];
tmp
=
newArray
;
tmpLen
=
newSize
;
tmpBase
=
0
;
}
return
tmp
;
}
/**
* Checks that fromIndex and toIndex are in range, and throws an
* appropriate exception if they aren't.
*
* @param arrayLen the length of the array
* @param fromIndex the index of the first element of the range
* @param toIndex the index after the last element of the range
* @throws IllegalArgumentException if fromIndex > toIndex
* @throws ArrayIndexOutOfBoundsException if fromIndex < 0
* or toIndex > arrayLen
*/
private
static
void
rangeCheck
(
int
arrayLen
,
int
fromIndex
,
int
toIndex
)
{
if
(
fromIndex
>
toIndex
)
throw
new
IllegalArgumentException
(
"fromIndex("
+
fromIndex
+
") > toIndex("
+
toIndex
+
")"
);
if
(
fromIndex
<
0
)
throw
new
ArrayIndexOutOfBoundsException
(
fromIndex
);
if
(
toIndex
>
arrayLen
)
throw
new
ArrayIndexOutOfBoundsException
(
toIndex
);
}
}
src/share/classes/java/util/DualPivotQuicksort.java
浏览文件 @
e8cb5ad9
此差异已折叠。
点击以展开。
src/share/classes/java/util/TimSort.java
浏览文件 @
e8cb5ad9
此差异已折叠。
点击以展开。
test/java/util/Arrays/ParallelSorting.java
浏览文件 @
e8cb5ad9
此差异已折叠。
点击以展开。
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录