I was surprised that dd did memcpy() by default,
which one can see using:

ltrace -e memcpy dd if=/dev/zero of=/dev/null count=10

Now if you specify bs=512 for example
a memcpy() is not done, which seems inconsistent to me.

What about the attached patch to not do a
memory copy in any of the combinations where
ibs = obs, and conversions are not done?

cheers,
Pádraig.
>From 3bf7a447aa0b2339915cb5abe4d17919224c88dc Mon Sep 17 00:00:00 2001
From: =?utf-8?q?P=C3=A1draig=20Brady?= <[EMAIL PROTECTED]>
Date: Thu, 20 Nov 2008 22:49:02 +0000
Subject: [PATCH] Don't do unneccesary memory copies in dd.

* src/dd.c: If output buffer size would be
the same size as the input buffer, just use
a single buffer to avoid redundant memory copy.
---
 src/dd.c |    9 ++-------
 1 files changed, 2 insertions(+), 7 deletions(-)

diff --git a/src/dd.c b/src/dd.c
index f598e44..e1e38e9 100644
--- a/src/dd.c
+++ b/src/dd.c
@@ -998,13 +998,11 @@ scanargs (int argc, char *const *argv)
 	    {
 	      invalid |= ! (0 < n && n <= MAX_BLOCKSIZE (INPUT_BLOCK_SLOP));
 	      input_blocksize = n;
-	      conversions_mask |= C_TWOBUFS;
 	    }
 	  else if (operand_is (name, "obs"))
 	    {
 	      invalid |= ! (0 < n && n <= MAX_BLOCKSIZE (OUTPUT_BLOCK_SLOP));
 	      output_blocksize = n;
-	      conversions_mask |= C_TWOBUFS;
 	    }
 	  else if (operand_is (name, "bs"))
 	    {
@@ -1036,15 +1034,12 @@ scanargs (int argc, char *const *argv)
   if (blocksize)
     input_blocksize = output_blocksize = blocksize;
 
-  /* If bs= was given, both `input_blocksize' and `output_blocksize' will
-     have been set to positive values.  If either has not been set,
-     bs= was not given, so make sure two buffers are used. */
-  if (input_blocksize == 0 || output_blocksize == 0)
-    conversions_mask |= C_TWOBUFS;
   if (input_blocksize == 0)
     input_blocksize = DEFAULT_BLOCKSIZE;
   if (output_blocksize == 0)
     output_blocksize = DEFAULT_BLOCKSIZE;
+  if (input_blocksize != output_blocksize)
+    conversions_mask |= C_TWOBUFS;
   if (conversion_blocksize == 0)
     conversions_mask &= ~(C_BLOCK | C_UNBLOCK);
 
-- 
1.5.3.6

_______________________________________________
Bug-coreutils mailing list
[email protected]
http://lists.gnu.org/mailman/listinfo/bug-coreutils

Reply via email to