aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorDenys Vlasenko <vda.linux@googlemail.com>2011-02-11 18:56:13 +0100
committerDenys Vlasenko <vda.linux@googlemail.com>2011-02-11 18:56:13 +0100
commitd55e13964916af6a083be881bffdb493af287c1d (patch)
tree399af6f19989d3efedb0a66f0e7b99184b245bb9
parente52e67cb512e775fd83ca399cc807c363ba59dcc (diff)
downloadbusybox-w32-d55e13964916af6a083be881bffdb493af287c1d.tar.gz
busybox-w32-d55e13964916af6a083be881bffdb493af287c1d.tar.bz2
busybox-w32-d55e13964916af6a083be881bffdb493af287c1d.zip
progress meter: move file name to bb_progress_t. +20 bytes
We were doing expensive unicode conversion on every update Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
-rw-r--r--include/libbb.h12
-rw-r--r--libbb/progress.c24
-rw-r--r--networking/tftp.c10
-rw-r--r--networking/wget.c4
4 files changed, 27 insertions, 23 deletions
diff --git a/include/libbb.h b/include/libbb.h
index c0178801f..7581cd4c4 100644
--- a/include/libbb.h
+++ b/include/libbb.h
@@ -1587,15 +1587,21 @@ typedef struct bb_progress_t {
1587 off_t lastsize; 1587 off_t lastsize;
1588 unsigned lastupdate_sec; 1588 unsigned lastupdate_sec;
1589 unsigned start_sec; 1589 unsigned start_sec;
1590 smallint inited; 1590 const char *curfile;
1591} bb_progress_t; 1591} bb_progress_t;
1592 1592
1593void bb_progress_init(bb_progress_t *p) FAST_FUNC; 1593#define is_bb_progress_inited(p) ((p)->curfile != NULL)
1594void bb_progress_update(bb_progress_t *p, const char *curfile, 1594#define bb_progress_free(p) do { \
1595 if (ENABLE_UNICODE_SUPPORT) free((char*)((p)->curfile)); \
1596 (p)->curfile = NULL; \
1597} while (0)
1598void bb_progress_init(bb_progress_t *p, const char *curfile) FAST_FUNC;
1599void bb_progress_update(bb_progress_t *p,
1595 uoff_t beg_range, 1600 uoff_t beg_range,
1596 uoff_t transferred, 1601 uoff_t transferred,
1597 uoff_t totalsize) FAST_FUNC; 1602 uoff_t totalsize) FAST_FUNC;
1598 1603
1604
1599extern const char *applet_name; 1605extern const char *applet_name;
1600 1606
1601/* Some older linkers don't perform string merging, we used to have common strings 1607/* Some older linkers don't perform string merging, we used to have common strings
diff --git a/libbb/progress.c b/libbb/progress.c
index 1062e9a0d..1d260dd08 100644
--- a/libbb/progress.c
+++ b/libbb/progress.c
@@ -52,12 +52,17 @@ static unsigned int get_tty2_width(void)
52 return width; 52 return width;
53} 53}
54 54
55void FAST_FUNC bb_progress_init(bb_progress_t *p) 55void FAST_FUNC bb_progress_init(bb_progress_t *p, const char *curfile)
56{ 56{
57#if ENABLE_UNICODE_SUPPORT
58 init_unicode();
59 p->curfile = unicode_conv_to_printable_fixedwidth(/*NULL,*/ curfile, 20);
60#else
61 p->curfile = curfile;
62#endif
57 p->start_sec = monotonic_sec(); 63 p->start_sec = monotonic_sec();
58 p->lastupdate_sec = p->start_sec; 64 p->lastupdate_sec = p->start_sec;
59 p->lastsize = 0; 65 p->lastsize = 0;
60 p->inited = 1;
61} 66}
62 67
63/* File already had beg_size bytes. 68/* File already had beg_size bytes.
@@ -68,7 +73,6 @@ void FAST_FUNC bb_progress_init(bb_progress_t *p)
68 * If totalsize == 0, then it is unknown. 73 * If totalsize == 0, then it is unknown.
69 */ 74 */
70void FAST_FUNC bb_progress_update(bb_progress_t *p, 75void FAST_FUNC bb_progress_update(bb_progress_t *p,
71 const char *curfile,
72 uoff_t beg_size, 76 uoff_t beg_size,
73 uoff_t transferred, 77 uoff_t transferred,
74 uoff_t totalsize) 78 uoff_t totalsize)
@@ -130,16 +134,10 @@ void FAST_FUNC bb_progress_update(bb_progress_t *p,
130 beg_and_transferred = beg_size + transferred; 134 beg_and_transferred = beg_size + transferred;
131 135
132 ratio = 100 * beg_and_transferred / totalsize; 136 ratio = 100 * beg_and_transferred / totalsize;
133#if ENABLE_UNICODE_SUPPORT 137 if (ENABLE_UNICODE_SUPPORT)
134 init_unicode(); 138 fprintf(stderr, "\r%s%4u%% ", p->curfile, ratio);
135 { 139 else
136 char *buf = unicode_conv_to_printable_fixedwidth(/*NULL,*/ curfile, 20); 140 fprintf(stderr, "\r%-20.20s%4u%% ", p->curfile, ratio);
137 fprintf(stderr, "\r%s%4u%% ", buf, ratio);
138 free(buf);
139 }
140#else
141 fprintf(stderr, "\r%-20.20s%4u%% ", curfile, ratio);
142#endif
143 141
144 barlength = get_tty2_width() - 49; 142 barlength = get_tty2_width() - 49;
145 if (barlength > 0) { 143 if (barlength > 0) {
diff --git a/networking/tftp.c b/networking/tftp.c
index fcd933f6a..2a3991755 100644
--- a/networking/tftp.c
+++ b/networking/tftp.c
@@ -107,19 +107,19 @@ struct BUG_G_too_big {
107#if ENABLE_FEATURE_TFTP_PROGRESS_BAR 107#if ENABLE_FEATURE_TFTP_PROGRESS_BAR
108static void tftp_progress_update(void) 108static void tftp_progress_update(void)
109{ 109{
110 bb_progress_update(&G.pmt, G.file, 0, G.pos, G.size); 110 bb_progress_update(&G.pmt, 0, G.pos, G.size);
111} 111}
112static void tftp_progress_init(void) 112static void tftp_progress_init(void)
113{ 113{
114 bb_progress_init(&G.pmt); 114 bb_progress_init(&G.pmt, G.file);
115 tftp_progress_update(); 115 tftp_progress_update();
116} 116}
117static void tftp_progress_done(void) 117static void tftp_progress_done(void)
118{ 118{
119 if (G.pmt.inited) { 119 if (is_bb_progress_inited(&G.pmt)) {
120 tftp_progress_update(); 120 tftp_progress_update();
121 bb_putchar_stderr('\n'); 121 bb_putchar_stderr('\n');
122 G.pmt.inited = 0; 122 bb_progress_free(p);
123 } 123 }
124} 124}
125#else 125#else
@@ -445,7 +445,7 @@ static int tftp_protocol(
445#if ENABLE_FEATURE_TFTP_PROGRESS_BAR 445#if ENABLE_FEATURE_TFTP_PROGRESS_BAR
446 if (ENABLE_TFTP && remote_file) /* tftp */ 446 if (ENABLE_TFTP && remote_file) /* tftp */
447 G.pos = (block_nr - 1) * (uoff_t)blksize; 447 G.pos = (block_nr - 1) * (uoff_t)blksize;
448 if (G.pmt.inited) 448 if (is_bb_progress_inited(&G.pmt))
449 tftp_progress_update(); 449 tftp_progress_update();
450#endif 450#endif
451 /* Was it final ACK? then exit */ 451 /* Was it final ACK? then exit */
diff --git a/networking/wget.c b/networking/wget.c
index d81426e8d..f2d7daf2f 100644
--- a/networking/wget.c
+++ b/networking/wget.c
@@ -81,9 +81,9 @@ static void progress_meter(int flag)
81 return; 81 return;
82 82
83 if (flag == PROGRESS_START) 83 if (flag == PROGRESS_START)
84 bb_progress_init(&G.pmt); 84 bb_progress_init(&G.pmt, G.curfile);
85 85
86 bb_progress_update(&G.pmt, G.curfile, G.beg_range, G.transferred, 86 bb_progress_update(&G.pmt, G.beg_range, G.transferred,
87 G.chunked ? 0 : G.beg_range + G.transferred + G.content_len); 87 G.chunked ? 0 : G.beg_range + G.transferred + G.content_len);
88 88
89 if (flag == PROGRESS_END) { 89 if (flag == PROGRESS_END) {