@@ -752,14 +752,16 @@ fn display_item_name(
752752 let escaped_target = escape_name_with_locale ( target_path. as_os_str ( ) , config) ;
753753 // We get the absolute path to be able to construct PathData with valid Metadata.
754754 // This is because relative symlinks will fail to get_metadata.
755- let mut absolute_target = target_path. clone ( ) ;
756- if target_path . is_relative ( ) {
757- if let Some ( parent ) = path . path ( ) . parent ( ) {
758- absolute_target = parent . join ( absolute_target ) ;
755+ let absolute_target = if target_path. is_relative ( ) {
756+ match path . path ( ) . parent ( ) {
757+ Some ( p ) => & p . join ( & target_path ) ,
758+ None => & target_path ,
759759 }
760- }
760+ } else {
761+ & target_path
762+ } ;
761763
762- match fs:: canonicalize ( & absolute_target) {
764+ match fs:: canonicalize ( absolute_target) {
763765 Ok ( resolved_target) => {
764766 let target_data = PathData :: new (
765767 resolved_target. as_path ( ) . into ( ) ,
@@ -822,15 +824,15 @@ fn display_item_name(
822824 // to get correct alignment from later calls to`display_grid()`.
823825 if config. context {
824826 if let Some ( pad_count) = prefix_context {
825- let security_context = if matches ! ( config. format, Format :: Commas ) {
826- path. security_context ( config) . to_string ( )
827+ let security_context: Cow < ' _ , str > = if matches ! ( config. format, Format :: Commas ) {
828+ path. security_context ( config) . into ( )
827829 } else {
828- pad_left ( path. security_context ( config) , pad_count)
830+ pad_left ( path. security_context ( config) , pad_count) . into ( )
829831 } ;
830832
831833 let old_name = name;
832834 name = OsString :: with_capacity ( security_context. len ( ) + 1 + old_name. len ( ) ) ;
833- name. push ( security_context) ;
835+ name. push ( security_context. as_ref ( ) ) ;
834836 name. push ( " " ) ;
835837 name. push ( old_name) ;
836838 }
0 commit comments