changeset 39950:34b025ca0b53

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.
author Paul Eggert <eggert@cs.ucla.edu>
date Thu, 25 Oct 2018 08:25:41 -0700
parents e42f23351bef
children b460856f7515
files ChangeLog lib/backupfile.c
diffstat 2 files changed, 21 insertions(+), 8 deletions(-) [+]
line wrap: on
line diff
--- a/ChangeLog	Wed Oct 24 07:26:20 2018 -0700
+++ b/ChangeLog	Thu Oct 25 08:25:41 2018 -0700
@@ -1,3 +1,13 @@
+2018-10-25  Paul Eggert  <eggert@cs.ucla.edu>
+
+	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  <eggert@cs.ucla.edu>
 
 	backupfile: new dir_fd args
--- a/lib/backupfile.c	Wed Oct 24 07:26:20 2018 -0700
+++ b/lib/backupfile.c	Thu Oct 25 08:25:41 2018 -0700
@@ -23,21 +23,26 @@
 #include "backup-internal.h"
 
 #include "dirname.h"
+#include "opendirat.h"
 #include "renameatu.h"
 #include "xalloc-oversized.h"
 
+#include <errno.h>
 #include <fcntl.h>
-#include <errno.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 @@
                 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;