aboutsummaryrefslogtreecommitdiff
path: root/bin
diff options
context:
space:
mode:
authorMaxim Sobolev <sobomax@FreeBSD.org>2018-12-17 15:19:48 +0000
committerMaxim Sobolev <sobomax@FreeBSD.org>2018-12-17 15:19:48 +0000
commitcb0eeacd5cae048caf284a9072b8575eff536c40 (patch)
tree0bc099094b91b705f5ae9837ea5a83a7fc42fede /bin
parent8bc9303fd848d28d8a65449c918e7068def9026d (diff)
downloadsrc-cb0eeacd5cae048caf284a9072b8575eff536c40.tar.gz
src-cb0eeacd5cae048caf284a9072b8575eff536c40.zip
MFC r341257: improve speed of empty block detection.
Notes
Notes: svn path=/stable/11/; revision=342167
Diffstat (limited to 'bin')
-rw-r--r--bin/dd/dd.c10
-rw-r--r--bin/dd/dd.h4
2 files changed, 7 insertions, 7 deletions
diff --git a/bin/dd/dd.c b/bin/dd/dd.c
index c3392b695088..6443c9168ef4 100644
--- a/bin/dd/dd.c
+++ b/bin/dd/dd.c
@@ -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;
diff --git a/bin/dd/dd.h b/bin/dd/dd.h
index 7054d9cd0df9..796b2acf35cf 100644
--- a/bin/dd/dd.h
+++ b/bin/dd/dd.h
@@ -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))