]> git.ipfire.org Git - thirdparty/coreutils.git/commitdiff
ls: avoid redundant processing when already escaping
authorPádraig Brady <P@draigBrady.com>
Tue, 3 Nov 2015 11:07:06 +0000 (11:07 +0000)
committerPádraig Brady <P@draigBrady.com>
Wed, 4 Nov 2015 23:30:15 +0000 (23:30 +0000)
This is mainly noticeable when the multi-byte code
within ls.c is triggered by multi-byte quotes.

$ seq 200000 | xargs touch
$ time ls-old -U --quoting=locale --hide-control-chars >/dev/null
real    0m0.483s
$ time ls-new -U --quoting=locale --hide-control-chars >/dev/null
real    0m0.430s

* src/ls.c (quote_name): Avoid rescanning the output looking for
unprintable chars when we know the quoting mode already escapes them.
* tests/misc/ls-misc.pl: Add tests for all quoting modes, with and
without -q, to verify this assumption.

src/ls.c
tests/misc/ls-misc.pl

index 8d68a03e1173e98e45758d6ac18de467b580d10e..c22c536c04731ff25c9cb265c2e8e7952381f4ad 100644 (file)
--- a/src/ls.c
+++ b/src/ls.c
@@ -4082,7 +4082,11 @@ quote_name (FILE *out, const char *name, struct quoting_options const *options,
       quotearg_buffer (buf, len + 1, name, -1, options);
     }
 
-  if (qmark_funny_chars)
+  enum quoting_style qs = get_quoting_style (options);
+
+  if (qmark_funny_chars
+      && (qs == shell_quoting_style || qs == shell_always_quoting_style
+          || qs == literal_quoting_style))
     {
       if (MB_CUR_MAX > 1)
         {
index 8b97c50f0b61409e4d0dfca402cf7611e9bd9587..d3897737e491cc7c4fa297e765fe15127a9d712b 100755 (executable)
@@ -132,13 +132,25 @@ my @Tests =
      ['q-q', '-q', $q_bell, {OUT => "q?\n"}],
      ['q-Q', '-Q', $q_bell, {OUT => "\"q\\a\"\n"}],
 
-     ['q-lit-q', '--quoting=literal -q',     $q_bell, {OUT => "q?\n"}],
-     ['q-qs-lit', '--quoting=literal',       $q_bell, {OUT => "q\a\n"}],
-     ['q-qs-sh', '--quoting=shell',          $q_bell, {OUT => "q\a\n"}],
-     ['q-qs-sh-a', '--quoting=shell-always', $q_bell, {OUT => "'q\a'\n"}],
-     ['q-qs-sh-e', '--quoting=shell-escape', $q_bell, {OUT => "'q'\$'\\a'\n"}],
-     ['q-qs-c', '--quoting=c',               $q_bell, {OUT => "\"q\\a\"\n"}],
-     ['q-qs-esc', '--quoting=escape',        $q_bell, {OUT => "q\\a\n"}],
+     ['q-qs-lit',    '--quoting=literal',     $q_bell, {OUT => "q\a\n"}],
+     ['q-qs-sh',     '--quoting=shell',       $q_bell, {OUT => "q\a\n"}],
+     ['q-qs-sh-a',   '--quoting=shell-always',$q_bell, {OUT => "'q\a'\n"}],
+     ['q-qs-sh-e',   '--quoting=shell-escape',$q_bell, {OUT => "'q'\$'\\a'\n"}],
+     ['q-qs-c',      '--quoting=c',           $q_bell, {OUT => "\"q\\a\"\n"}],
+     ['q-qs-esc',    '--quoting=escape',      $q_bell, {OUT => "q\\a\n"}],
+     ['q-qs-loc',    '--quoting=locale',      $q_bell, {OUT => "'q\\a'\n"}],
+     ['q-qs-cloc',   '--quoting=clocale',     $q_bell, {OUT => "\"q\\a\"\n"}],
+
+     ['q-qs-lit-q',  '--quoting=literal -q',  $q_bell, {OUT => "q?\n"}],
+     ['q-qs-sh-q',   '--quoting=shell -q',    $q_bell, {OUT => "q?\n"}],
+     ['q-qs-sh-a-q', '--quoting=shell-al -q', $q_bell, {OUT => "'q?'\n"}],
+     ['q-qs-sh-e-q', '--quoting=shell-escape -q',
+                                              $q_bell, {OUT => "'q'\$'\\a'\n"}],
+     ['q-qs-c-q',    '--quoting=c -q',        $q_bell, {OUT => "\"q\\a\"\n"}],
+     ['q-qs-esc-q',  '--quoting=escape -q',   $q_bell, {OUT => "q\\a\n"}],
+     ['q-qs-loc-q',  '--quoting=locale -q',   $q_bell, {OUT => "'q\\a'\n"}],
+     ['q-qs-cloc-q', '--quoting=clocale -q',  $q_bell, {OUT => "\"q\\a\"\n"}],
+
      ['q-qs-c-1', '--quoting=c',
       {IN => {"t\004" => ''}}, {OUT => "\"t\\004\"\n"}],