@@ -2999,36 +2999,44 @@ fn render_assoc_item(
2999
2999
href ( did, cx. cache ( ) ) . map ( |p| format ! ( "{}#{}.{}" , p. 0 , ty, name) ) . unwrap_or ( anchor)
3000
3000
}
3001
3001
} ;
3002
- let mut header_len = format ! (
3003
- "{}{}{}{}{}{:#}fn {}{:#}" ,
3004
- meth. visibility. print_with_space( cx. tcx( ) , meth. def_id, cx. cache( ) ) ,
3005
- header. constness. print_with_space( ) ,
3006
- header. asyncness. print_with_space( ) ,
3007
- header. unsafety. print_with_space( ) ,
3008
- print_default_space( meth. is_default( ) ) ,
3009
- print_abi_with_space( header. abi) ,
3010
- name,
3011
- g. print( cx. cache( ) )
3012
- )
3013
- . len ( ) ;
3002
+ let tcx = cx. tcx ( ) ;
3003
+ let vis = meth. visibility . print_with_space ( tcx, meth. def_id , cx. cache ( ) ) . to_string ( ) ;
3004
+ let constness = header. constness . print_with_space ( ) ;
3005
+ let asyncness = header. asyncness . print_with_space ( ) ;
3006
+ let unsafety = header. unsafety . print_with_space ( ) ;
3007
+ let defaultness = print_default_space ( meth. is_default ( ) ) ;
3008
+ let abi = print_abi_with_space ( header. abi ) . to_string ( ) ;
3009
+ // NOTE: `{:#}` does not print HTML formatting, `{}` does. So `g.print` can't be reused between the length calculation and `write!`.
3010
+ let generics_len = format ! ( "{:#}" , g. print( cx. cache( ) ) ) . len ( ) ;
3011
+ let mut header_len = "fn " . len ( )
3012
+ + vis. len ( )
3013
+ + constness. len ( )
3014
+ + asyncness. len ( )
3015
+ + unsafety. len ( )
3016
+ + defaultness. len ( )
3017
+ + abi. len ( )
3018
+ + name. as_str ( ) . len ( )
3019
+ + generics_len;
3020
+
3014
3021
let ( indent, end_newline) = if parent == ItemType :: Trait {
3015
3022
header_len += 4 ;
3016
3023
( 4 , false )
3017
3024
} else {
3018
3025
( 0 , true )
3019
3026
} ;
3020
3027
render_attributes ( w, meth, false ) ;
3028
+ w. reserve ( header_len + "<a href=\" \" class=\" fnname\" >{" . len ( ) + "</a>" . len ( ) ) ;
3021
3029
write ! (
3022
3030
w,
3023
3031
"{}{}{}{}{}{}{}fn <a href=\" {href}\" class=\" fnname\" >{name}</a>\
3024
3032
{generics}{decl}{spotlight}{where_clause}",
3025
3033
if parent == ItemType :: Trait { " " } else { "" } ,
3026
- meth . visibility . print_with_space ( cx . tcx ( ) , meth . def_id , cx . cache ( ) ) ,
3027
- header . constness. print_with_space ( ) ,
3028
- header . asyncness. print_with_space ( ) ,
3029
- header . unsafety. print_with_space ( ) ,
3030
- print_default_space ( meth . is_default ( ) ) ,
3031
- print_abi_with_space ( header . abi) ,
3034
+ vis ,
3035
+ constness,
3036
+ asyncness,
3037
+ unsafety,
3038
+ defaultness ,
3039
+ abi,
3032
3040
href = href,
3033
3041
name = name,
3034
3042
generics = g. print( cx. cache( ) ) ,
0 commit comments