bug-gnulib
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

[PATCH 1/2] backupfile: tweak for better code


From: Paul Eggert
Subject: [PATCH 1/2] backupfile: tweak for better code
Date: Thu, 25 Oct 2018 08:34:49 -0700

* lib/backupfile.c: Sort include directives, and remove
unnecessary <limits.h> include.
(FALLTHROUGH): New macro, copied from other modules.
(backupfile_internal): Use it to avoid code duplication.
This lets GCC 8.2.1 generate better code by inlining the
call to check_extension.
---
 ChangeLog        | 10 ++++++++++
 lib/backupfile.c | 19 +++++++++++--------
 2 files changed, 21 insertions(+), 8 deletions(-)

diff --git a/ChangeLog b/ChangeLog
index c08de2869..38c59c26a 100644
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,3 +1,13 @@
+2018-10-25  Paul Eggert  <address@hidden>
+
+       backupfile: tweak for better code
+       * lib/backupfile.c: Sort include directives, and remove
+       unnecessary <limits.h> include.
+       (FALLTHROUGH): New macro, copied from other modules.
+       (backupfile_internal): Use it to avoid code duplication.
+       This lets GCC 8.2.1 generate better code by inlining the
+       call to check_extension.
+
 2018-10-23  Paul Eggert  <address@hidden>
 
        backupfile: new dir_fd args
diff --git a/lib/backupfile.c b/lib/backupfile.c
index ee12f7124..df7ac3809 100644
--- a/lib/backupfile.c
+++ b/lib/backupfile.c
@@ -23,21 +23,26 @@
 #include "backup-internal.h"
 
 #include "dirname.h"
+#include "opendirat.h"
 #include "renameatu.h"
 #include "xalloc-oversized.h"
 
-#include <fcntl.h>
 #include <errno.h>
+#include <fcntl.h>
 #include <stdbool.h>
 #include <stdint.h>
 #include <stdlib.h>
 #include <string.h>
-
-#include <limits.h>
-
 #include <unistd.h>
 
-#include "opendirat.h"
+#ifndef FALLTHROUGH
+# if __GNUC__ < 7
+#  define FALLTHROUGH ((void) 0)
+# else
+#  define FALLTHROUGH __attribute__ ((__fallthrough__))
+# endif
+#endif
+
 #ifndef _D_EXACT_NAMLEN
 # define _D_EXACT_NAMLEN(dp) strlen ((dp)->d_name)
 #endif
@@ -351,9 +356,7 @@ backupfile_internal (int dir_fd, char const *file,
                 memcpy (s + filelen, simple_backup_suffix,
                         simple_backup_suffix_size);
               }
-            check_extension (s, filelen, '~', sdir, &base_max);
-            break;
-
+            FALLTHROUGH;
           case BACKUP_IS_LONGER:
             check_extension (s, filelen, '~', sdir, &base_max);
             break;
-- 
2.17.2




reply via email to

[Prev in Thread] Current Thread [Next in Thread]