Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
openanolis
dragonwell8_jdk
提交
d94bcee3
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看板
提交
d94bcee3
编写于
10月 30, 2011
作者:
A
alanb
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
7103889: (fs) Reduce String concatenation when iterating over directory
Reviewed-by: alanb Contributed-by: mike.skells@talk21.com
上级
1d489b23
变更
3
隐藏空白更改
内联
并排
Showing
3 changed file
with
38 addition
and
21 deletion
+38
-21
src/share/classes/java/nio/file/Files.java
src/share/classes/java/nio/file/Files.java
+12
-6
src/windows/classes/sun/nio/fs/WindowsDirectoryStream.java
src/windows/classes/sun/nio/fs/WindowsDirectoryStream.java
+17
-12
src/windows/classes/sun/nio/fs/WindowsPathParser.java
src/windows/classes/sun/nio/fs/WindowsPathParser.java
+9
-3
未找到文件。
src/share/classes/java/nio/file/Files.java
浏览文件 @
d94bcee3
...
...
@@ -363,6 +363,17 @@ public final class Files {
// -- Directories --
private
static
class
AcceptAllFilter
implements
DirectoryStream
.
Filter
<
Path
>
{
private
AcceptAllFilter
()
{
}
@Override
public
boolean
accept
(
Path
entry
)
{
return
true
;
}
static
final
AcceptAllFilter
FILTER
=
new
AcceptAllFilter
();
}
/**
* Opens a directory, returning a {@link DirectoryStream} to iterate over
* all entries in the directory. The elements returned by the directory
...
...
@@ -397,12 +408,7 @@ public final class Files {
public
static
DirectoryStream
<
Path
>
newDirectoryStream
(
Path
dir
)
throws
IOException
{
return
provider
(
dir
).
newDirectoryStream
(
dir
,
new
DirectoryStream
.
Filter
<
Path
>()
{
@Override
public
boolean
accept
(
Path
entry
)
{
return
true
;
}
});
return
provider
(
dir
).
newDirectoryStream
(
dir
,
AcceptAllFilter
.
FILTER
);
}
/**
...
...
src/windows/classes/sun/nio/fs/WindowsDirectoryStream.java
浏览文件 @
d94bcee3
...
...
@@ -124,26 +124,27 @@ class WindowsDirectoryStream
private
boolean
atEof
;
private
String
first
;
private
Path
nextEntry
;
private
String
prefix
;
WindowsDirectoryIterator
(
String
first
)
{
atEof
=
false
;
this
.
first
=
first
;
if
(
dir
.
needsSlashWhenResolving
())
{
prefix
=
dir
.
toString
()
+
"\\"
;
}
else
{
prefix
=
dir
.
toString
();
}
}
// links to self and parent directories are ignored
private
boolean
isSelfOrParent
(
String
name
)
{
return
name
.
equals
(
"."
)
||
name
.
equals
(
".."
);
}
// applies filter and also ignores "." and ".."
private
Path
acceptEntry
(
String
s
,
BasicFileAttributes
attrs
)
{
if
(
s
.
equals
(
"."
)
||
s
.
equals
(
".."
))
return
null
;
if
(
dir
.
needsSlashWhenResolving
())
{
StringBuilder
sb
=
new
StringBuilder
(
dir
.
toString
());
sb
.
append
(
'\\'
);
sb
.
append
(
s
);
s
=
sb
.
toString
();
}
else
{
s
=
dir
+
s
;
}
Path
entry
=
WindowsPath
.
createFromNormalizedPath
(
dir
.
getFileSystem
(),
s
,
attrs
);
.
createFromNormalizedPath
(
dir
.
getFileSystem
(),
prefix
+
s
,
attrs
);
try
{
if
(
filter
.
accept
(
entry
))
return
entry
;
...
...
@@ -157,7 +158,7 @@ class WindowsDirectoryStream
private
Path
readNextEntry
()
{
// handle first element returned by search
if
(
first
!=
null
)
{
nextEntry
=
acceptEntry
(
first
,
null
);
nextEntry
=
isSelfOrParent
(
first
)
?
null
:
acceptEntry
(
first
,
null
);
first
=
null
;
if
(
nextEntry
!=
null
)
return
nextEntry
;
...
...
@@ -184,6 +185,10 @@ class WindowsDirectoryStream
return
null
;
}
// ignore link to self and parent directories
if
(
isSelfOrParent
(
name
))
continue
;
// grab the attributes from the WIN32_FIND_DATA structure
// (needs to be done while holding closeLock because close
// will release the buffer)
...
...
src/windows/classes/sun/nio/fs/WindowsPathParser.java
浏览文件 @
d94bcee3
...
...
@@ -120,12 +120,18 @@ class WindowsPathParser {
off
=
next
;
}
else
{
if
(
isLetter
(
c0
)
&&
c1
==
':'
)
{
root
=
input
.
substring
(
0
,
2
);
if
(
len
>
2
&&
isSlash
(
input
.
charAt
(
2
)))
{
char
c2
;
if
(
len
>
2
&&
isSlash
(
c2
=
input
.
charAt
(
2
)))
{
// avoid concatenation when root is "D:\"
if
(
c2
==
'\\'
)
{
root
=
input
.
substring
(
0
,
3
);
}
else
{
root
=
input
.
substring
(
0
,
2
)
+
'\\'
;
}
off
=
3
;
root
+=
"\\"
;
type
=
WindowsPathType
.
ABSOLUTE
;
}
else
{
root
=
input
.
substring
(
0
,
2
);
off
=
2
;
type
=
WindowsPathType
.
DRIVE_RELATIVE
;
}
...
...
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录