aboutsummaryrefslogtreecommitdiff
path: root/miscutils
diff options
context:
space:
mode:
authorDenys Vlasenko <vda.linux@googlemail.com>2017-09-14 00:04:16 +0200
committerDenys Vlasenko <vda.linux@googlemail.com>2017-09-14 00:04:16 +0200
commitd72e804e6db1bd6eb2417961004b4fe33aba9384 (patch)
tree72873b67871e955c0519a1d03045328153957549 /miscutils
parent62643017c3d5bc1bb9fff91553e52a47e7730a01 (diff)
downloadbusybox-w32-d72e804e6db1bd6eb2417961004b4fe33aba9384.tar.gz
busybox-w32-d72e804e6db1bd6eb2417961004b4fe33aba9384.tar.bz2
busybox-w32-d72e804e6db1bd6eb2417961004b4fe33aba9384.zip
hexedit: optimize output buffering
function old new delta hexedit_main 970 998 +28 Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
Diffstat (limited to 'miscutils')
-rw-r--r--miscutils/hexedit.c19
1 files changed, 12 insertions, 7 deletions
diff --git a/miscutils/hexedit.c b/miscutils/hexedit.c
index a99569706..e8bc73b7e 100644
--- a/miscutils/hexedit.c
+++ b/miscutils/hexedit.c
@@ -38,8 +38,8 @@ struct globals {
38/* Hopefully there aren't arches with PAGE_SIZE > 64k */ 38/* Hopefully there aren't arches with PAGE_SIZE > 64k */
39#define G_mapsize (64*1024) 39#define G_mapsize (64*1024)
40 40
41/* "12ef5670 (nn )*16 abcdef_1_3_5_7_9\n" */ 41/* "12ef5670 (xx )*16 _1_3_5_7_9abcdef\n"NUL */
42#define LINEBUF_SIZE (8 + 1 + 3*16 + 16 + 1 /*paranoia:*/ + 14) 42#define LINEBUF_SIZE (8 + 1 + 3*16 + 16 + 1 + 1 /*paranoia:*/ + 13)
43 43
44static int format_line(char *hex, uint8_t *data, off_t offset) 44static int format_line(char *hex, uint8_t *data, off_t offset)
45{ 45{
@@ -165,7 +165,7 @@ static void move_mapping_further(void)
165 pagesize = getpagesize(); /* constant on most arches */ 165 pagesize = getpagesize(); /* constant on most arches */
166 pos = G.current_byte - G.addr; 166 pos = G.current_byte - G.addr;
167 if (pos >= pagesize) { 167 if (pos >= pagesize) {
168 /* Move offset up until current position is in 1st page */ 168 /* move offset up until current position is in 1st page */
169 do { 169 do {
170 G.offset += pagesize; 170 G.offset += pagesize;
171 if (G.offset == 0) { /* whoops */ 171 if (G.offset == 0) { /* whoops */
@@ -188,7 +188,7 @@ static void move_mapping_lower(void)
188 pagesize = getpagesize(); /* constant on most arches */ 188 pagesize = getpagesize(); /* constant on most arches */
189 pos = G.current_byte - G.addr; 189 pos = G.current_byte - G.addr;
190 190
191 /* Move offset down until current position is in last page */ 191 /* move offset down until current position is in last page */
192 pos += pagesize; 192 pos += pagesize;
193 while (pos < G_mapsize) { 193 while (pos < G_mapsize) {
194 pos += pagesize; 194 pos += pagesize;
@@ -218,10 +218,15 @@ int hexedit_main(int argc UNUSED_PARAM, char **argv)
218 218
219 INIT_G(); 219 INIT_G();
220 220
221 getopt32(argv, "");
222 argv += optind;
223
224 get_terminal_width_height(-1, NULL, &G.height); 221 get_terminal_width_height(-1, NULL, &G.height);
222 if (1) {
223 /* reduce number of write() syscalls while PgUp/Down: fully buffered output */
224 unsigned sz = (G.height | 0xf) * LINEBUF_SIZE;
225 setvbuf(stdout, xmalloc(sz), _IOFBF, sz);
226 }
227
228 getopt32(argv, "^" "" "\0" "=1"/*one arg*/);
229 argv += optind;
225 230
226 G.fd = xopen(*argv, O_RDWR); 231 G.fd = xopen(*argv, O_RDWR);
227 G.size = xlseek(G.fd, 0, SEEK_END); 232 G.size = xlseek(G.fd, 0, SEEK_END);