Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
int
Rust
提交
e25e15ce
R
Rust
项目概览
int
/
Rust
接近 1 年 前同步成功
通知
1
Star
0
Fork
0
代码
文件
提交
分支
Tags
贡献者
分支图
Diff
Issue
0
列表
看板
标记
里程碑
合并请求
0
DevOps
流水线
流水线任务
计划
Wiki
0
Wiki
分析
仓库
DevOps
项目成员
Pages
R
Rust
项目概览
项目概览
详情
发布
仓库
仓库
文件
提交
分支
标签
贡献者
分支图
比较
Issue
0
Issue
0
列表
看板
标记
里程碑
合并请求
0
合并请求
0
Pages
DevOps
DevOps
流水线
流水线任务
计划
分析
分析
仓库分析
DevOps
Wiki
0
Wiki
成员
成员
收起侧边栏
关闭侧边栏
动态
分支图
创建新Issue
流水线任务
提交
Issue看板
体验新版 GitCode,发现更多精彩内容 >>
提交
e25e15ce
编写于
3月 07, 2021
作者:
G
Guillaume Gomez
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
Store tcx and cache when they are used multiple times instead of calling functions every time
上级
0cde8552
变更
1
隐藏空白更改
内联
并排
Showing
1 changed file
with
66 addition
and
58 deletion
+66
-58
src/librustdoc/html/render/mod.rs
src/librustdoc/html/render/mod.rs
+66
-58
未找到文件。
src/librustdoc/html/render/mod.rs
浏览文件 @
e25e15ce
...
...
@@ -855,10 +855,12 @@ fn render_impls(
traits
:
&
[
&&
Impl
],
containing_item
:
&
clean
::
Item
,
)
{
let
cache
=
cx
.cache
();
let
tcx
=
cx
.tcx
();
let
mut
impls
=
traits
.iter
()
.map
(|
i
|
{
let
did
=
i
.trait_did_full
(
c
x
.cache
()
)
.unwrap
();
let
did
=
i
.trait_did_full
(
c
ache
)
.unwrap
();
let
assoc_link
=
AssocItemLink
::
GotoSource
(
did
,
&
i
.inner_impl
()
.provided_trait_methods
);
let
mut
buffer
=
if
w
.is_for_html
()
{
Buffer
::
html
()
}
else
{
Buffer
::
new
()
};
render_impl
(
...
...
@@ -868,8 +870,8 @@ fn render_impls(
containing_item
,
assoc_link
,
RenderMode
::
Normal
,
containing_item
.stable_since
(
cx
.tcx
()
)
.as_deref
(),
containing_item
.const_stable_since
(
cx
.tcx
()
)
.as_deref
(),
containing_item
.stable_since
(
tcx
)
.as_deref
(),
containing_item
.const_stable_since
(
tcx
)
.as_deref
(),
true
,
None
,
false
,
...
...
@@ -911,14 +913,16 @@ fn assoc_const(
extra
:
&
str
,
cx
:
&
Context
<
'_
>
,
)
{
let
cache
=
cx
.cache
();
let
tcx
=
cx
.tcx
();
write!
(
w
,
"{}{}const <a href=
\"
{}
\"
class=
\"
constant
\"
><b>{}</b></a>: {}"
,
extra
,
it
.visibility
.print_with_space
(
cx
.tcx
(),
it
.def_id
,
cx
.cache
()
),
naive_assoc_href
(
it
,
link
,
c
x
.cache
()
),
it
.visibility
.print_with_space
(
tcx
,
it
.def_id
,
cache
),
naive_assoc_href
(
it
,
link
,
c
ache
),
it
.name
.as_ref
()
.unwrap
(),
ty
.print
(
c
x
.cache
(),
cx
.tcx
()
)
ty
.print
(
c
ache
,
tcx
)
);
}
...
...
@@ -993,6 +997,8 @@ fn method(
parent
:
ItemType
,
cx
:
&
Context
<
'_
>
,
)
{
let
cache
=
cx
.cache
();
let
tcx
=
cx
.tcx
();
let
name
=
meth
.name
.as_ref
()
.unwrap
();
let
anchor
=
format!
(
"#{}.{}"
,
meth
.type_
(),
name
);
let
href
=
match
link
{
...
...
@@ -1007,18 +1013,17 @@ fn method(
ItemType
::
TyMethod
};
href
(
did
,
c
x
.cache
()
)
.map
(|
p
|
format!
(
"{}#{}.{}"
,
p
.0
,
ty
,
name
))
.unwrap_or
(
anchor
)
href
(
did
,
c
ache
)
.map
(|
p
|
format!
(
"{}#{}.{}"
,
p
.0
,
ty
,
name
))
.unwrap_or
(
anchor
)
}
};
let
tcx
=
cx
.tcx
();
let
vis
=
meth
.visibility
.print_with_space
(
tcx
,
meth
.def_id
,
cx
.cache
())
.to_string
();
let
vis
=
meth
.visibility
.print_with_space
(
tcx
,
meth
.def_id
,
cache
)
.to_string
();
let
constness
=
header
.constness
.print_with_space
();
let
asyncness
=
header
.asyncness
.print_with_space
();
let
unsafety
=
header
.unsafety
.print_with_space
();
let
defaultness
=
print_default_space
(
meth
.is_default
());
let
abi
=
print_abi_with_space
(
header
.abi
)
.to_string
();
// NOTE: `{:#}` does not print HTML formatting, `{}` does. So `g.print` can't be reused between the length calculation and `write!`.
let
generics_len
=
format!
(
"{:#}"
,
g
.print
(
c
x
.cache
()
,
tcx
))
.len
();
let
generics_len
=
format!
(
"{:#}"
,
g
.print
(
c
ache
,
tcx
))
.len
();
let
mut
header_len
=
"fn "
.len
()
+
vis
.len
()
+
constness
.len
()
...
...
@@ -1050,10 +1055,10 @@ fn method(
abi
,
href
=
href
,
name
=
name
,
generics
=
g
.print
(
c
x
.cache
(),
cx
.tcx
()
),
decl
=
d
.full_print
(
c
x
.cache
(),
cx
.tcx
()
,
header_len
,
indent
,
header
.asyncness
),
spotlight
=
spotlight_decl
(
&
d
,
c
x
.cache
(),
cx
.tcx
()
),
where_clause
=
print_where_clause
(
g
,
c
x
.cache
(),
cx
.tcx
()
,
indent
,
end_newline
),
generics
=
g
.print
(
c
ache
,
tcx
),
decl
=
d
.full_print
(
c
ache
,
tcx
,
header_len
,
indent
,
header
.asyncness
),
spotlight
=
spotlight_decl
(
&
d
,
c
ache
,
tcx
),
where_clause
=
print_where_clause
(
g
,
c
ache
,
tcx
,
indent
,
end_newline
),
)
}
match
*
item
.kind
{
...
...
@@ -1156,6 +1161,8 @@ fn render_assoc_items(
Some
(
v
)
=>
v
,
None
=>
return
,
};
let
tcx
=
cx
.tcx
();
let
cache
=
cx
.cache
();
let
(
non_trait
,
traits
):
(
Vec
<
_
>
,
_
)
=
v
.iter
()
.partition
(|
i
|
i
.inner_impl
()
.trait_
.is_none
());
if
!
non_trait
.is_empty
()
{
let
render_mode
=
match
what
{
...
...
@@ -1170,12 +1177,10 @@ fn render_assoc_items(
AssocItemRender
::
DerefFor
{
trait_
,
type_
,
deref_mut_
}
=>
{
let
id
=
cx
.derive_id
(
small_url_encode
(
format!
(
"deref-methods-{:#}"
,
type_
.print
(
c
x
.cache
(),
cx
.tcx
()
)
type_
.print
(
c
ache
,
tcx
)
)));
debug!
(
"Adding {} to deref id map"
,
type_
.print
(
cx
.cache
(),
cx
.tcx
()));
cx
.deref_id_map
.borrow_mut
()
.insert
(
type_
.def_id_full
(
cx
.cache
())
.unwrap
(),
id
.clone
());
debug!
(
"Adding {} to deref id map"
,
type_
.print
(
cache
,
tcx
));
cx
.deref_id_map
.borrow_mut
()
.insert
(
type_
.def_id_full
(
cache
)
.unwrap
(),
id
.clone
());
write!
(
w
,
"<h2 id=
\"
{id}
\"
class=
\"
small-section-header
\"
>
\
...
...
@@ -1183,8 +1188,8 @@ fn render_assoc_items(
<a href=
\"
#{id}
\"
class=
\"
anchor
\"
></a>
\
</h2>"
,
id
=
id
,
trait_
=
trait_
.print
(
c
x
.cache
(),
cx
.tcx
()
),
type_
=
type_
.print
(
c
x
.cache
(),
cx
.tcx
()
),
trait_
=
trait_
.print
(
c
ache
,
tcx
),
type_
=
type_
.print
(
c
ache
,
tcx
),
);
RenderMode
::
ForDeref
{
mut_
:
deref_mut_
}
}
...
...
@@ -1197,8 +1202,8 @@ fn render_assoc_items(
containing_item
,
AssocItemLink
::
Anchor
(
None
),
render_mode
,
containing_item
.stable_since
(
cx
.tcx
()
)
.as_deref
(),
containing_item
.const_stable_since
(
cx
.tcx
()
)
.as_deref
(),
containing_item
.stable_since
(
tcx
)
.as_deref
(),
containing_item
.const_stable_since
(
tcx
)
.as_deref
(),
true
,
None
,
false
,
...
...
@@ -1210,11 +1215,11 @@ fn render_assoc_items(
if
!
traits
.is_empty
()
{
let
deref_impl
=
traits
.iter
()
.find
(|
t
|
t
.inner_impl
()
.trait_
.def_id_full
(
c
x
.cache
()
)
==
cx
.cache.deref_trait_did
);
.find
(|
t
|
t
.inner_impl
()
.trait_
.def_id_full
(
c
ache
)
==
cx
.cache.deref_trait_did
);
if
let
Some
(
impl_
)
=
deref_impl
{
let
has_deref_mut
=
traits
.iter
()
.any
(|
t
|
{
t
.inner_impl
()
.trait_
.def_id_full
(
cx
.cache
())
==
cx
.cache.deref_mut_trait_did
}
);
let
has_deref_mut
=
traits
.iter
()
.any
(|
t
|
t
.inner_impl
()
.trait_
.def_id_full
(
cache
)
==
cx
.cache.deref_mut_trait_did
);
render_deref_methods
(
w
,
cx
,
impl_
,
containing_item
,
has_deref_mut
);
}
...
...
@@ -1415,18 +1420,17 @@ fn render_impl(
aliases
:
&
[
String
],
)
{
let
traits
=
&
cx
.cache.traits
;
let
trait_
=
i
.trait_did_full
(
cx
.cache
())
.map
(|
did
|
&
traits
[
&
did
]);
let
tcx
=
cx
.tcx
();
let
cache
=
cx
.cache
();
let
trait_
=
i
.trait_did_full
(
cache
)
.map
(|
did
|
&
traits
[
&
did
]);
if
render_mode
==
RenderMode
::
Normal
{
let
id
=
cx
.derive_id
(
match
i
.inner_impl
()
.trait_
{
Some
(
ref
t
)
=>
{
if
is_on_foreign_type
{
get_id_for_impl_on_foreign_type
(
&
i
.inner_impl
()
.for_
,
t
,
c
x
.cache
(),
cx
.tcx
()
)
get_id_for_impl_on_foreign_type
(
&
i
.inner_impl
()
.for_
,
t
,
c
ache
,
tcx
)
}
else
{
format!
(
"impl-{}"
,
small_url_encode
(
format!
(
"{:#}"
,
t
.print
(
cx
.cache
(),
cx
.tcx
())))
)
format!
(
"impl-{}"
,
small_url_encode
(
format!
(
"{:#}"
,
t
.print
(
cache
,
tcx
))))
}
}
None
=>
"impl"
.to_string
(),
...
...
@@ -1438,7 +1442,7 @@ fn render_impl(
};
if
let
Some
(
use_absolute
)
=
use_absolute
{
write!
(
w
,
"<h3 id=
\"
{}
\"
class=
\"
impl
\"
{}><code class=
\"
in-band
\"
>"
,
id
,
aliases
);
write!
(
w
,
"{}"
,
i
.inner_impl
()
.print
(
c
x
.cache
(),
use_absolute
,
cx
.tcx
()
));
write!
(
w
,
"{}"
,
i
.inner_impl
()
.print
(
c
ache
,
use_absolute
,
tcx
));
if
show_def_docs
{
for
it
in
&
i
.inner_impl
()
.items
{
if
let
clean
::
TypedefItem
(
ref
tydef
,
_
)
=
*
it
.kind
{
...
...
@@ -1450,8 +1454,8 @@ fn render_impl(
Some
(
&
tydef
.type_
),
AssocItemLink
::
Anchor
(
None
),
""
,
c
x
.cache
()
,
cx
.tcx
()
,
c
ache
,
tcx
,
);
w
.write_str
(
";</span>"
);
}
...
...
@@ -1464,14 +1468,14 @@ fn render_impl(
"<h3 id=
\"
{}
\"
class=
\"
impl
\"
{}><code class=
\"
in-band
\"
>{}</code>"
,
id
,
aliases
,
i
.inner_impl
()
.print
(
c
x
.cache
(),
false
,
cx
.tcx
()
)
i
.inner_impl
()
.print
(
c
ache
,
false
,
tcx
)
);
}
write!
(
w
,
"<a href=
\"
#{}
\"
class=
\"
anchor
\"
></a>"
,
id
);
render_stability_since_raw
(
w
,
i
.impl_item
.stable_since
(
cx
.tcx
()
)
.as_deref
(),
i
.impl_item
.const_stable_since
(
cx
.tcx
()
)
.as_deref
(),
i
.impl_item
.stable_since
(
tcx
)
.as_deref
(),
i
.impl_item
.const_stable_since
(
tcx
)
.as_deref
(),
outer_version
,
outer_const_version
,
);
...
...
@@ -1517,6 +1521,7 @@ fn doc_impl_item(
)
{
let
item_type
=
item
.type_
();
let
name
=
item
.name
.as_ref
()
.unwrap
();
let
tcx
=
cx
.tcx
();
let
render_method_item
=
match
render_mode
{
RenderMode
::
Normal
=>
true
,
...
...
@@ -1544,8 +1549,8 @@ fn doc_impl_item(
w
.write_str
(
"</code>"
);
render_stability_since_raw
(
w
,
item
.stable_since
(
cx
.tcx
()
)
.as_deref
(),
item
.const_stable_since
(
cx
.tcx
()
)
.as_deref
(),
item
.stable_since
(
tcx
)
.as_deref
(),
item
.const_stable_since
(
tcx
)
.as_deref
(),
outer_version
,
outer_const_version
,
);
...
...
@@ -1564,7 +1569,7 @@ fn doc_impl_item(
link
.anchor
(
&
id
),
""
,
cx
.cache
(),
cx
.tcx
()
,
tcx
,
);
w
.write_str
(
"</code></h4>"
);
}
...
...
@@ -1575,8 +1580,8 @@ fn doc_impl_item(
w
.write_str
(
"</code>"
);
render_stability_since_raw
(
w
,
item
.stable_since
(
cx
.tcx
()
)
.as_deref
(),
item
.const_stable_since
(
cx
.tcx
()
)
.as_deref
(),
item
.stable_since
(
tcx
)
.as_deref
(),
item
.const_stable_since
(
tcx
)
.as_deref
(),
outer_version
,
outer_const_version
,
);
...
...
@@ -1594,7 +1599,7 @@ fn doc_impl_item(
link
.anchor
(
&
id
),
""
,
cx
.cache
(),
cx
.tcx
()
,
tcx
,
);
w
.write_str
(
"</code></h4>"
);
}
...
...
@@ -1898,6 +1903,8 @@ fn small_url_encode(s: String) -> String {
fn
sidebar_assoc_items
(
cx
:
&
Context
<
'_
>
,
out
:
&
mut
Buffer
,
it
:
&
clean
::
Item
)
{
if
let
Some
(
v
)
=
cx
.cache.impls
.get
(
&
it
.def_id
)
{
let
mut
used_links
=
FxHashSet
::
default
();
let
tcx
=
cx
.tcx
();
let
cache
=
cx
.cache
();
{
let
used_links_bor
=
&
mut
used_links
;
...
...
@@ -1927,7 +1934,7 @@ fn sidebar_assoc_items(cx: &Context<'_>, out: &mut Buffer, it: &clean::Item) {
if
let
Some
(
impl_
)
=
v
.iter
()
.filter
(|
i
|
i
.inner_impl
()
.trait_
.is_some
())
.find
(|
i
|
i
.inner_impl
()
.trait_
.def_id_full
(
c
x
.cache
()
)
==
cx
.cache.deref_trait_did
)
.find
(|
i
|
i
.inner_impl
()
.trait_
.def_id_full
(
c
ache
)
==
cx
.cache.deref_trait_did
)
{
sidebar_deref_methods
(
cx
,
out
,
impl_
,
v
);
}
...
...
@@ -1938,10 +1945,9 @@ fn sidebar_assoc_items(cx: &Context<'_>, out: &mut Buffer, it: &clean::Item) {
.iter
()
.filter_map
(|
it
|
{
if
let
Some
(
ref
i
)
=
it
.inner_impl
()
.trait_
{
let
i_display
=
format!
(
"{:#}"
,
i
.print
(
c
x
.cache
(),
cx
.tcx
()
));
let
i_display
=
format!
(
"{:#}"
,
i
.print
(
c
ache
,
tcx
));
let
out
=
Escape
(
&
i_display
);
let
encoded
=
small_url_encode
(
format!
(
"{:#}"
,
i
.print
(
cx
.cache
(),
cx
.tcx
())));
let
encoded
=
small_url_encode
(
format!
(
"{:#}"
,
i
.print
(
cache
,
tcx
)));
let
generated
=
format!
(
"<a href=
\"
#impl-{}
\"
>{}{}</a>"
,
encoded
,
...
...
@@ -2018,8 +2024,8 @@ fn sidebar_deref_methods(cx: &Context<'_>, out: &mut Buffer, impl_: &Impl, v: &V
})
{
debug!
(
"found target, real_target: {:?} {:?}"
,
target
,
real_target
);
if
let
Some
(
did
)
=
target
.def_id_full
(
c
x
.cache
()
)
{
if
let
Some
(
type_did
)
=
impl_
.inner_impl
()
.for_
.def_id_full
(
c
x
.cache
()
)
{
if
let
Some
(
did
)
=
target
.def_id_full
(
c
)
{
if
let
Some
(
type_did
)
=
impl_
.inner_impl
()
.for_
.def_id_full
(
c
)
{
// `impl Deref<Target = S> for S`
if
did
==
type_did
{
// Avoid infinite cycles
...
...
@@ -2030,9 +2036,9 @@ fn sidebar_deref_methods(cx: &Context<'_>, out: &mut Buffer, impl_: &Impl, v: &V
let
deref_mut
=
v
.iter
()
.filter
(|
i
|
i
.inner_impl
()
.trait_
.is_some
())
.any
(|
i
|
i
.inner_impl
()
.trait_
.def_id_full
(
c
x
.cache
()
)
==
c
.deref_mut_trait_did
);
.any
(|
i
|
i
.inner_impl
()
.trait_
.def_id_full
(
c
)
==
c
.deref_mut_trait_did
);
let
inner_impl
=
target
.def_id_full
(
c
x
.cache
()
)
.def_id_full
(
c
)
.or_else
(||
{
target
.primitive_type
()
.and_then
(|
prim
|
c
.primitive_locations
.get
(
&
prim
)
.cloned
())
})
...
...
@@ -2048,7 +2054,7 @@ fn sidebar_deref_methods(cx: &Context<'_>, out: &mut Buffer, impl_: &Impl, v: &V
if
!
ret
.is_empty
()
{
let
deref_id_map
=
cx
.deref_id_map
.borrow
();
let
id
=
deref_id_map
.get
(
&
real_target
.def_id_full
(
c
x
.cache
()
)
.unwrap
())
.get
(
&
real_target
.def_id_full
(
c
)
.unwrap
())
.expect
(
"Deref section without derived id"
);
write!
(
out
,
...
...
@@ -2071,12 +2077,12 @@ fn sidebar_deref_methods(cx: &Context<'_>, out: &mut Buffer, impl_: &Impl, v: &V
}
// Recurse into any further impls that might exist for `target`
if
let
Some
(
target_did
)
=
target
.def_id_full
(
c
x
.cache
()
)
{
if
let
Some
(
target_did
)
=
target
.def_id_full
(
c
)
{
if
let
Some
(
target_impls
)
=
c
.impls
.get
(
&
target_did
)
{
if
let
Some
(
target_deref_impl
)
=
target_impls
.iter
()
.filter
(|
i
|
i
.inner_impl
()
.trait_
.is_some
())
.find
(|
i
|
i
.inner_impl
()
.trait_
.def_id_full
(
c
x
.cache
()
)
==
c
.deref_trait_did
)
.find
(|
i
|
i
.inner_impl
()
.trait_
.def_id_full
(
c
)
==
c
.deref_trait_did
)
{
sidebar_deref_methods
(
cx
,
out
,
target_deref_impl
,
target_impls
);
}
...
...
@@ -2214,15 +2220,17 @@ fn print_sidebar_section(
);
if
let
Some
(
implementors
)
=
cx
.cache.implementors
.get
(
&
it
.def_id
)
{
let
cache
=
cx
.cache
();
let
tcx
=
cx
.tcx
();
let
mut
res
=
implementors
.iter
()
.filter
(|
i
|
{
i
.inner_impl
()
.for_
.def_id_full
(
c
x
.cache
()
)
.def_id_full
(
c
ache
)
.map_or
(
false
,
|
d
|
!
cx
.cache.paths
.contains_key
(
&
d
))
})
.filter_map
(|
i
|
extract_for_impl_name
(
&
i
.impl_item
,
c
x
.cache
(),
cx
.tcx
()
))
.filter_map
(|
i
|
extract_for_impl_name
(
&
i
.impl_item
,
c
ache
,
tcx
))
.collect
::
<
Vec
<
_
>>
();
if
!
res
.is_empty
()
{
...
...
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录