Author: sobomax
Date: Mon Dec 17 15:19:48 2018
New Revision: 342167
URL: https://svnweb.freebsd.org/changeset/base/342167

Log:
  MFC r341257: improve speed of empty block detection.

Modified:
  stable/11/bin/dd/dd.c
  stable/11/bin/dd/dd.h
Directory Properties:
  stable/11/   (props changed)

Modified: stable/11/bin/dd/dd.c
==============================================================================
--- stable/11/bin/dd/dd.c       Mon Dec 17 15:17:09 2018        (r342166)
+++ stable/11/bin/dd/dd.c       Mon Dec 17 15:19:48 2018        (r342167)
@@ -474,7 +474,7 @@ void
 dd_out(int force)
 {
        u_char *outp;
-       size_t cnt, i, n;
+       size_t cnt, n;
        ssize_t nw;
        static int warned;
        int sparse;
@@ -507,12 +507,8 @@ dd_out(int force)
                do {
                        sparse = 0;
                        if (ddflags & C_SPARSE) {
-                               sparse = 1;     /* Is buffer sparse? */
-                               for (i = 0; i < cnt; i++)
-                                       if (outp[i] != 0) {
-                                               sparse = 0;
-                                               break;
-                                       }
+                               /* Is buffer sparse? */
+                               sparse = BISZERO(outp, cnt);
                        }
                        if (sparse && !force) {
                                pending += cnt;

Modified: stable/11/bin/dd/dd.h
==============================================================================
--- stable/11/bin/dd/dd.h       Mon Dec 17 15:17:09 2018        (r342166)
+++ stable/11/bin/dd/dd.h       Mon Dec 17 15:19:48 2018        (r342167)
@@ -102,3 +102,7 @@ typedef struct {
 #define        C_PROGRESS      0x40000000
 
 #define        C_PARITY        (C_PAREVEN | C_PARODD | C_PARNONE | C_PARSET)
+
+#define        BISZERO(p, s)   ((s) > 0 && *((const char *)p) == 0 && !memcmp( 
\
+                           (const void *)(p), (const void *) \
+                           ((const char *)p + 1), (s) - 1))
_______________________________________________
svn-src-all@freebsd.org mailing list
https://lists.freebsd.org/mailman/listinfo/svn-src-all
To unsubscribe, send any mail to "svn-src-all-unsubscr...@freebsd.org"

Reply via email to