Przeglądaj źródła

perf: do not pre-compute MountInfo to reduce readlink calls

Terts Diepraam 2 lat temu
rodzic
commit
defe8c9f8c
1 zmienionych plików z 9 dodań i 15 usunięć
  1. 9 15
      src/output/file_name.rs

+ 9 - 15
src/output/file_name.rs

@@ -4,7 +4,6 @@ use std::path::Path;
 use ansiterm::{ANSIString, Style};
 use ansiterm::{ANSIString, Style};
 use unicode_width::UnicodeWidthStr;
 use unicode_width::UnicodeWidthStr;
 
 
-use crate::fs::mounts::MountedFs;
 use crate::fs::{File, FileTarget};
 use crate::fs::{File, FileTarget};
 use crate::output::cell::TextCellContents;
 use crate::output::cell::TextCellContents;
 use crate::output::escape;
 use crate::output::escape;
@@ -49,7 +48,6 @@ impl Options {
                 None
                 None
             },
             },
             mount_style: MountStyle::JustDirectoryNames,
             mount_style: MountStyle::JustDirectoryNames,
-            mounted_fs: file.mount_point_info(),
         }
         }
     }
     }
 }
 }
@@ -144,9 +142,6 @@ pub struct FileName<'a, 'dir, C> {
 
 
     pub options: Options,
     pub options: Options,
 
 
-    /// The filesystem details for a mounted filesystem.
-    mounted_fs: Option<&'a MountedFs>,
-
     /// How to handle displaying a mounted filesystem.
     /// How to handle displaying a mounted filesystem.
     mount_style: MountStyle,
     mount_style: MountStyle,
 }
 }
@@ -244,7 +239,6 @@ impl<'a, 'dir, C: Colours> FileName<'a, 'dir, C> {
                             target: None,
                             target: None,
                             link_style: LinkStyle::FullLinkPaths,
                             link_style: LinkStyle::FullLinkPaths,
                             options: target_options,
                             options: target_options,
-                            mounted_fs: None,
                             mount_style: MountStyle::JustDirectoryNames,
                             mount_style: MountStyle::JustDirectoryNames,
                         };
                         };
 
 
@@ -284,15 +278,15 @@ impl<'a, 'dir, C: Colours> FileName<'a, 'dir, C> {
             }
             }
         }
         }
 
 
-        if let (MountStyle::MountInfo, Some(mount_details)) =
-            (self.mount_style, self.mounted_fs.as_ref())
-        {
-            // This is a filesystem mounted on the directory, output its details
-            bits.push(Style::default().paint(" ["));
-            bits.push(Style::default().paint(mount_details.source.clone()));
-            bits.push(Style::default().paint(" ("));
-            bits.push(Style::default().paint(mount_details.fstype.clone()));
-            bits.push(Style::default().paint(")]"));
+        if self.mount_style == MountStyle::MountInfo {
+            if let Some(mount_details) = self.file.mount_point_info() {
+                // This is a filesystem mounted on the directory, output its details
+                bits.push(Style::default().paint(" ["));
+                bits.push(Style::default().paint(mount_details.source.clone()));
+                bits.push(Style::default().paint(" ("));
+                bits.push(Style::default().paint(mount_details.fstype.clone()));
+                bits.push(Style::default().paint(")]"));
+            }
         }
         }
 
 
         bits.into()
         bits.into()