svn commit: r342166 - stable/12/bin/dd

Maxim Sobolev sobomax at FreeBSD.org
Mon Dec 17 15:17:11 UTC 2018


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

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

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

Modified: stable/12/bin/dd/dd.c
==============================================================================
--- stable/12/bin/dd/dd.c	Mon Dec 17 15:13:58 2018	(r342165)
+++ stable/12/bin/dd/dd.c	Mon Dec 17 15:17:09 2018	(r342166)
@@ -512,7 +512,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;
@@ -545,12 +545,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/12/bin/dd/dd.h
==============================================================================
--- stable/12/bin/dd/dd.h	Mon Dec 17 15:13:58 2018	(r342165)
+++ stable/12/bin/dd/dd.h	Mon Dec 17 15:17:09 2018	(r342166)
@@ -103,3 +103,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))


More information about the svn-src-stable-12 mailing list