summaryrefslogtreecommitdiff
path: root/src/copy.c
diff options
context:
space:
mode:
authorPádraig Brady <P@draigBrady.com>2015-10-22 14:34:08 +0100
committerPádraig Brady <P@draigBrady.com>2015-10-27 17:25:12 +0000
commit9459d9d8112fe7816022665b5016c2014bb625f3 (patch)
tree80486d9f4331e149f6e7ef7381acbac1613ffb31 /src/copy.c
parent6796698c9945d87236ffcc939137d0919ef04931 (diff)
downloadcoreutils-9459d9d8112fe7816022665b5016c2014bb625f3.tar.xz
copy,dd: simplify and optimize NUL bytes detection
* src/factor.c: Move LIKELY() definition to... * src/system.h: ...here. (is_nul): Reimplement with a version that doesn't require a sentinel after the buffer, and which calls down to (the system optimized) memcmp. Performance analyzed at http://rusty.ozlabs.org/?p=560 * src/dd.c (alloc_obuf): Simplify the is_nul() call by not needing to write the sentinel. * src/copy.c (sparse_copy): Likewise. (copy_reg): Simplify the buffer allocation by avoiding consideration of the sentinel in the buffer size calculation.
Diffstat (limited to 'src/copy.c')
-rw-r--r--src/copy.c22
1 files changed, 4 insertions, 18 deletions
diff --git a/src/copy.c b/src/copy.c
index 5fe69ea3c..edf022ef1 100644
--- a/src/copy.c
+++ b/src/copy.c
@@ -245,17 +245,7 @@ sparse_copy (int src_fd, int dest_fd, char *buf, size_t buf_size,
csize = MIN (csize, n_read);
if (hole_size && csize)
- {
- /* Setup sentinel required by is_nul(). */
- typedef uintptr_t word;
- word isnul_tmp;
- memcpy (&isnul_tmp, cbuf + csize, sizeof (word));
- memset (cbuf + csize, 1, sizeof (word));
-
- make_hole = is_nul (cbuf, csize);
-
- memcpy (cbuf + csize, &isnul_tmp, sizeof (word));
- }
+ make_hole = is_nul (cbuf, csize);
bool transition = (make_hole != prev_hole) && psize;
bool last_chunk = (n_read == csize && ! make_hole) || ! csize;
@@ -1201,11 +1191,8 @@ copy_reg (char const *src_name, char const *dst_name,
if (data_copy_required)
{
- typedef uintptr_t word;
-
/* Choose a suitable buffer size; it may be adjusted later. */
- size_t buf_alignment = lcm (getpagesize (), sizeof (word));
- size_t buf_alignment_slop = sizeof (word) + buf_alignment - 1;
+ size_t buf_alignment = getpagesize ();
size_t buf_size = io_blksize (sb);
size_t hole_size = ST_BLKSIZE (sb);
@@ -1236,7 +1223,7 @@ copy_reg (char const *src_name, char const *dst_name,
{
/* Compute the least common multiple of the input and output
buffer sizes, adjusting for outlandish values. */
- size_t blcm_max = MIN (SIZE_MAX, SSIZE_MAX) - buf_alignment_slop;
+ size_t blcm_max = MIN (SIZE_MAX, SSIZE_MAX) - buf_alignment;
size_t blcm = buffer_lcm (io_blksize (src_open_sb), buf_size,
blcm_max);
@@ -1254,8 +1241,7 @@ copy_reg (char const *src_name, char const *dst_name,
buf_size = blcm;
}
- /* Make a buffer with space for a sentinel at the end. */
- buf_alloc = xmalloc (buf_size + buf_alignment_slop);
+ buf_alloc = xmalloc (buf_size + buf_alignment);
buf = ptr_align (buf_alloc, buf_alignment);
if (sparse_src)