summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorPádraig Brady <P@draigBrady.com>2008-11-20 22:49:02 +0000
committerPádraig Brady <P@draigBrady.com>2008-11-21 11:50:59 +0000
commitfbd87029cfc494a72bb73ade27ef46382c5bc832 (patch)
tree60566457d68ce76d1d98a8eb07fc99660d1ed9ea
parent3ece0355d52e41a1b079c0c46477a32250278c11 (diff)
downloadcoreutils-fbd87029cfc494a72bb73ade27ef46382c5bc832.tar.xz
dd: avoid unnecessary memory copies
* src/dd.c (scanargs): When not otherwise required (e.g. for conversion), use two-buffer mode only when the input and output buffer sizes differ. Before, some of the most basic invocations of dd, e.g., dd < in > out, would unnecessarily use separate buffers and perform memory copies between them.
-rw-r--r--src/dd.c9
1 files changed, 2 insertions, 7 deletions
diff --git a/src/dd.c b/src/dd.c
index f598e44cd..e1e38e954 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);