]> git.ipfire.org Git - thirdparty/coreutils.git/commitdiff
ls -U1 now uses constant memory
authorKamil Dudka <kdudka@redhat.com>
Wed, 30 Jul 2008 12:31:50 +0000 (14:31 +0200)
committerJim Meyering <meyering@redhat.com>
Fri, 1 Aug 2008 06:36:38 +0000 (08:36 +0200)
When printing one name per line and not sorting, ls now uses
constant memory per directory, no matter how many files are in
the directory.
* ls.c (print_dir): Print each file name immediately, when possible.
* NEWS: Mention the improvement.

NEWS
src/ls.c

diff --git a/NEWS b/NEWS
index 5796dfa63979baa41df4f606892d8acf2083a213..4637ebad93deeca27a2ebf6904748c93be57b9be 100644 (file)
--- a/NEWS
+++ b/NEWS
@@ -51,6 +51,9 @@ GNU coreutils NEWS                                    -*- outline -*-
 
   join has significantly better performance due to better memory management
 
+  ls now uses constant memory when not sorting and using one_per_line format,
+  no matter how many files are in a given directory
+
   od now aligns fields across lines when printing multiple -t
   specifiers, and no longer prints fields that resulted entirely from
   padding the input out to the least common multiple width.
index 4b69f7d22a88dff1bad9918481de56f625669be4..a661c063f24a2c9d66aabdec2a896d7b81b0ec04 100644 (file)
--- a/src/ls.c
+++ b/src/ls.c
@@ -2402,6 +2402,20 @@ print_dir (char const *name, char const *realname, bool command_line_arg)
 #endif
              total_blocks += gobble_file (next->d_name, type, D_INO (next),
                                           false, name);
+
+             /* In this narrow case, print out each name right away, so
+                ls uses constant memory while processing the entries of
+                this directory.  Useful when there are many (millions)
+                of entries in a directory.  */
+             if (format == one_per_line && sort_type == sort_none)
+               {
+                 /* We must call sort_files in spite of
+                    "sort_type == sort_none" for its initialization
+                    of the sorted_file vector.  */
+                 sort_files ();
+                 print_current_files ();
+                 clear_files ();
+               }
            }
        }
       else if (errno != 0)