diff options
author | Jim Meyering <jim@meyering.net> | 2004-04-15 10:52:04 +0000 |
---|---|---|
committer | Jim Meyering <jim@meyering.net> | 2004-04-15 10:52:04 +0000 |
commit | 65816f395e95deff747081248e10b440541e6595 (patch) | |
tree | 1cbaf9f042eb2537819c53a0a21fc03642dc313f /src | |
parent | 0adee504ff956edb14905374208e722ca93ecd38 (diff) | |
download | coreutils-65816f395e95deff747081248e10b440541e6595.tar.xz |
Include getpagesize.h.
(main): Align I/O buffers to page boundaries.
Diffstat (limited to 'src')
-rw-r--r-- | src/cat.c | 24 |
1 files changed, 17 insertions, 7 deletions
@@ -33,6 +33,7 @@ #include "system.h" #include "error.h" #include "full-write.h" +#include "getpagesize.h" #include "safe-read.h" /* The official name of this program (e.g., no `g' prefix). */ @@ -504,6 +505,8 @@ main (int argc, char **argv) /* Optimal size of i/o operations of input. */ size_t insize; + size_t page_size = getpagesize (); + /* Pointer to the input buffer. */ char *inbuf; @@ -806,15 +809,16 @@ main (int argc, char **argv) if (options == 0) { insize = max (insize, outsize); - inbuf = xmalloc (insize); + inbuf = xmalloc (insize + page_size - 1); - simple_cat (inbuf, insize); + simple_cat (ptr_align (inbuf, page_size), insize); } else { - inbuf = xmalloc (insize + 1); + inbuf = xmalloc (insize + 1 + page_size - 1); - /* Why are (OUTSIZE - 1 + INSIZE * 4 + LINE_COUNTER_BUF_LEN) + /* Why are + (OUTSIZE - 1 + INSIZE * 4 + LINE_COUNTER_BUF_LEN + PAGE_SIZE - 1) bytes allocated for the output buffer? A test whether output needs to be written is done when the input @@ -829,11 +833,17 @@ main (int argc, char **argv) options) as the first thing in the output buffer. (Done after the new input is read, but before processing of the input begins.) A line number requires seldom more than LINE_COUNTER_BUF_LEN - positions. */ + positions. + + Align the output buffer to a page size boundary, for efficency on + some paging implementations, so add PAGE_SIZE - 1 bytes to the + request to make room for the alignment. */ - outbuf = xmalloc (outsize - 1 + insize * 4 + LINE_COUNTER_BUF_LEN); + outbuf = xmalloc (outsize - 1 + insize * 4 + LINE_COUNTER_BUF_LEN + + page_size - 1); - cat (inbuf, insize, outbuf, outsize, quote, + cat (ptr_align (inbuf, page_size), insize, + ptr_align (outbuf, page_size), outsize, quote, output_tabs, numbers, numbers_at_empty_lines, mark_line_ends, squeeze_empty_lines); |