Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
FIY695
jenkins
提交
7c101d1e
J
jenkins
项目概览
FIY695
/
jenkins
与 Fork 源项目一致
从无法访问的项目Fork
通知
1
Star
0
Fork
0
代码
文件
提交
分支
Tags
贡献者
分支图
Diff
Issue
0
列表
看板
标记
里程碑
合并请求
0
Wiki
0
Wiki
分析
仓库
DevOps
项目成员
Pages
J
jenkins
项目概览
项目概览
详情
发布
仓库
仓库
文件
提交
分支
标签
贡献者
分支图
比较
Issue
0
Issue
0
列表
看板
标记
里程碑
合并请求
0
合并请求
0
Pages
分析
分析
仓库分析
DevOps
Wiki
0
Wiki
成员
成员
收起侧边栏
关闭侧边栏
动态
分支图
创建新Issue
提交
Issue看板
体验新版 GitCode,发现更多精彩内容 >>
提交
7c101d1e
编写于
1月 13, 2011
作者:
K
Kohsuke Kawaguchi
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
Reduced the memory footprint used by fingerprints.
上级
8e607cc9
变更
4
隐藏空白更改
内联
并排
Showing
4 changed file
with
237 addition
and
4 deletion
+237
-4
changelog.html
changelog.html
+2
-0
core/src/main/java/hudson/tasks/Fingerprinter.java
core/src/main/java/hudson/tasks/Fingerprinter.java
+5
-4
core/src/main/java/hudson/util/PackedMap.java
core/src/main/java/hudson/util/PackedMap.java
+178
-0
core/src/test/java/hudson/util/PackedMapTest.java
core/src/test/java/hudson/util/PackedMapTest.java
+52
-0
未找到文件。
changelog.html
浏览文件 @
7c101d1e
...
...
@@ -48,6 +48,8 @@ Upcoming changes</a>
(
<a
href=
"http://issues.hudson-ci.org/browse/HUDSON-8415"
>
issue 8415
</a>
)
<li
class=
rfe
>
Startup performance improvement
<li
class=
rfe
>
Reduced the memory footprint used by fingerprints.
<li
class=
rfe
>
Added a new extension point to support external login mechanisms.
<li
class=
rfe
>
...
...
core/src/main/java/hudson/tasks/Fingerprinter.java
浏览文件 @
7c101d1e
...
...
@@ -43,6 +43,7 @@ import hudson.model.RunAction;
import
hudson.remoting.VirtualChannel
;
import
hudson.util.FormValidation
;
import
hudson.util.IOException2
;
import
hudson.util.PackedMap
;
import
net.sf.json.JSONObject
;
import
org.apache.tools.ant.DirectoryScanner
;
import
org.apache.tools.ant.types.FileSet
;
...
...
@@ -239,20 +240,20 @@ public class Fingerprinter extends Recorder implements Serializable {
/**
* From file name to the digest.
*/
private
/*almost final*/
Immutable
Map
<
String
,
String
>
record
;
private
/*almost final*/
Packed
Map
<
String
,
String
>
record
;
private
transient
WeakReference
<
Map
<
String
,
Fingerprint
>>
ref
;
public
FingerprintAction
(
AbstractBuild
build
,
Map
<
String
,
String
>
record
)
{
this
.
build
=
build
;
this
.
record
=
ImmutableMap
.
copyO
f
(
record
);
this
.
record
=
PackedMap
.
o
f
(
record
);
onLoad
();
// make compact
}
public
void
add
(
Map
<
String
,
String
>
moreRecords
)
{
Map
<
String
,
String
>
r
=
new
HashMap
<
String
,
String
>(
record
);
r
.
putAll
(
moreRecords
);
record
=
ImmutableMap
.
copyO
f
(
r
);
record
=
PackedMap
.
o
f
(
r
);
ref
=
null
;
onLoad
();
}
...
...
@@ -316,7 +317,7 @@ public class Fingerprinter extends Recorder implements Serializable {
b
.
put
(
k
,
v
);
}
record
=
ImmutableMap
.
copyO
f
(
b
);
record
=
PackedMap
.
o
f
(
b
);
}
/**
...
...
core/src/main/java/hudson/util/PackedMap.java
0 → 100644
浏览文件 @
7c101d1e
/*
* The MIT License
*
* Copyright (c) 2010, CloudBees, Inc.
*
* Permission is hereby granted, free of charge, to any person obtaining a copy
* of this software and associated documentation files (the "Software"), to deal
* in the Software without restriction, including without limitation the rights
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
* copies of the Software, and to permit persons to whom the Software is
* furnished to do so, subject to the following conditions:
*
* The above copyright notice and this permission notice shall be included in
* all copies or substantial portions of the Software.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
* THE SOFTWARE.
*/
package
hudson.util
;
import
com.thoughtworks.xstream.converters.UnmarshallingContext
;
import
com.thoughtworks.xstream.converters.collections.MapConverter
;
import
com.thoughtworks.xstream.io.HierarchicalStreamReader
;
import
com.thoughtworks.xstream.mapper.Mapper
;
import
java.util.AbstractList
;
import
java.util.AbstractMap
;
import
java.util.AbstractSet
;
import
java.util.Collection
;
import
java.util.HashMap
;
import
java.util.Iterator
;
import
java.util.LinkedHashMap
;
import
java.util.Map
;
import
java.util.Set
;
import
java.util.TreeMap
;
/**
* Read-only map implementation that uses less memory than {@link HashMap}/{@link TreeMap}.
*
* <p>
* The implementation is backed by a single exact-length array, so this implementation has the following
* performance characteristics.
*
* <ul>
* <li>iteration is fast (but creates a lot of short-lived objects.)
* <li>lookup is O(N)
* <li>memory consumption is low
* </ul>
*
* @author Kohsuke Kawaguchi
*/
@SuppressWarnings
({
"unchecked"
})
public
final
class
PackedMap
<
K
,
V
>
extends
AbstractMap
<
K
,
V
>
{
private
Object
[]
kvpairs
;
/**
*
* @param src
* Map to copy contents from. Iteration order is preserved.
*/
public
static
<
K
,
V
>
PackedMap
<
K
,
V
>
of
(
Map
<?
extends
K
,?
extends
V
>
src
)
{
return
new
PackedMap
<
K
,
V
>(
src
);
}
private
PackedMap
(
Map
<?
extends
K
,?
extends
V
>
src
)
{
kvpairs
=
new
Object
[
src
.
size
()*
2
];
int
i
=
0
;
for
(
Entry
<?
extends
K
,
?
extends
V
>
e
:
src
.
entrySet
())
{
kvpairs
[
i
++]
=
e
.
getKey
();
kvpairs
[
i
++]
=
e
.
getValue
();
}
}
private
final
Set
<
Entry
<
K
,
V
>>
entrySet
=
new
AbstractSet
<
Entry
<
K
,
V
>>()
{
@Override
public
Iterator
<
Entry
<
K
,
V
>>
iterator
()
{
return
new
Iterator
<
Entry
<
K
,
V
>>()
{
int
index
=
0
;
public
boolean
hasNext
()
{
return
index
<
kvpairs
.
length
;
}
@SuppressWarnings
({
"unchecked"
})
public
Entry
<
K
,
V
>
next
()
{
final
K
k
=
(
K
)
kvpairs
[
index
++];
final
V
v
=
(
V
)
kvpairs
[
index
++];
return
new
Entry
<
K
,
V
>()
{
public
K
getKey
()
{
return
k
;
}
public
V
getValue
()
{
return
v
;
}
public
V
setValue
(
V
value
)
{
throw
new
UnsupportedOperationException
();
}
};
}
public
void
remove
()
{
throw
new
UnsupportedOperationException
();
}
};
}
@Override
public
int
size
()
{
return
kvpairs
.
length
/
2
;
}
};
@Override
public
Set
<
Entry
<
K
,
V
>>
entrySet
()
{
return
entrySet
;
}
@Override
public
boolean
containsKey
(
Object
key
)
{
for
(
int
i
=
0
;
i
<
kvpairs
.
length
;
i
+=
2
)
if
(
key
.
equals
(
kvpairs
[
i
]))
return
true
;
return
false
;
}
@Override
public
V
get
(
Object
key
)
{
for
(
int
i
=
0
;
i
<
kvpairs
.
length
;
i
+=
2
)
if
(
key
.
equals
(
kvpairs
[
i
]))
return
(
V
)
kvpairs
[
i
+
1
];
return
null
;
}
@Override
public
Collection
<
V
>
values
()
{
return
new
AbstractList
<
V
>()
{
@Override
public
V
get
(
int
index
)
{
return
(
V
)
kvpairs
[
index
*
2
];
}
@Override
public
int
size
()
{
return
PackedMap
.
this
.
size
();
}
};
}
/**
* Should persist like a regular map.
*/
public
static
class
ConverterImpl
extends
MapConverter
{
public
ConverterImpl
(
Mapper
mapper
)
{
super
(
mapper
);
}
@Override
public
boolean
canConvert
(
Class
type
)
{
return
type
==
PackedMap
.
class
;
}
@Override
protected
Object
createCollection
(
Class
type
)
{
return
new
LinkedHashMap
<
String
,
String
>();
}
@Override
public
Object
unmarshal
(
HierarchicalStreamReader
reader
,
UnmarshallingContext
context
)
{
return
PackedMap
.
of
((
Map
)
super
.
unmarshal
(
reader
,
context
));
}
}
}
core/src/test/java/hudson/util/PackedMapTest.java
0 → 100644
浏览文件 @
7c101d1e
package
hudson.util
;
import
junit.framework.TestCase
;
import
java.util.Map
;
import
java.util.Map.Entry
;
import
java.util.TreeMap
;
/**
* @author Kohsuke Kawaguchi
*/
public
class
PackedMapTest
extends
TestCase
{
static
class
Holder
{
PackedMap
pm
;
}
private
XStream2
xs
=
new
XStream2
();
public
void
testBasic
()
throws
Exception
{
Map
<
String
,
String
>
o
=
new
TreeMap
<
String
,
String
>();
o
.
put
(
"a"
,
"b"
);
o
.
put
(
"c"
,
"d"
);
PackedMap
<
String
,
String
>
p
=
PackedMap
.
of
(
o
);
assertEquals
(
"b"
,
p
.
get
(
"a"
));
assertEquals
(
"d"
,
p
.
get
(
"c"
));
assertEquals
(
p
.
size
(),
2
);
for
(
Entry
<
String
,
String
>
e
:
p
.
entrySet
())
{
System
.
out
.
println
(
e
.
getKey
()+
'='
+
e
.
getValue
());
}
Holder
h
=
new
Holder
();
h
.
pm
=
p
;
String
xml
=
xs
.
toXML
(
h
);
assertEquals
(
"<hudson.util.PackedMapTest_-Holder>\n"
+
" <pm>\n"
+
" <entry>\n"
+
" <string>a</string>\n"
+
" <string>b</string>\n"
+
" </entry>\n"
+
" <entry>\n"
+
" <string>c</string>\n"
+
" <string>d</string>\n"
+
" </entry>\n"
+
" </pm>\n"
+
"</hudson.util.PackedMapTest_-Holder>"
,
xml
);
xs
.
fromXML
(
xml
);
}
}
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录