* [PATCH 1/3] column: use variable lenght printf field width to wprint blanks
@ 2013-08-03 23:15 Sami Kerola
2013-08-03 23:15 ` [PATCH 2/3] more: make output redirection more efficient Sami Kerola
` (2 more replies)
0 siblings, 3 replies; 6+ messages in thread
From: Sami Kerola @ 2013-08-03 23:15 UTC (permalink / raw)
To: util-linux; +Cc: kerolasa
This makes program to run a little faster. My test input show about 20%
speed improvement.
Signed-off-by: Sami Kerola <kerolasa@iki.fi>
---
text-utils/column.c | 5 ++---
1 file changed, 2 insertions(+), 3 deletions(-)
diff --git a/text-utils/column.c b/text-utils/column.c
index 2084ba6..2430ede 100644
--- a/text-utils/column.c
+++ b/text-utils/column.c
@@ -308,7 +308,7 @@ wchar_t *local_wcstok(wchar_t * p, const wchar_t * separator, int greedy,
static void maketbl(wchar_t **list, int entries, wchar_t *separator, int greedy, wchar_t *colsep)
{
TBL *t;
- int cnt, i;
+ int cnt;
wchar_t *p, **lp;
ssize_t *lens;
ssize_t maxcols = DEFCOLS, coloff;
@@ -347,8 +347,7 @@ static void maketbl(wchar_t **list, int entries, wchar_t *separator, int greedy,
for (t = tbl, cnt = 0; cnt < entries; ++cnt, ++t) {
for (coloff = 0; coloff < t->cols - 1; ++coloff) {
fputws(t->list[coloff], stdout);
- for (i = lens[coloff] - t->len[coloff]; i > 0; i--)
- putwchar(' ');
+ wprintf(L"%*s", lens[coloff] - t->len[coloff], "");
fputws(colsep, stdout);
}
if (coloff < t->cols) {
--
1.8.3.4
^ permalink raw reply related [flat|nested] 6+ messages in thread* [PATCH 2/3] more: make output redirection more efficient 2013-08-03 23:15 [PATCH 1/3] column: use variable lenght printf field width to wprint blanks Sami Kerola @ 2013-08-03 23:15 ` Sami Kerola 2013-08-05 8:48 ` Karel Zak 2013-08-03 23:15 ` [PATCH 3/3] cal: set statically defined data read-only Sami Kerola 2013-08-05 8:48 ` [PATCH 1/3] column: use variable lenght printf field width to wprint blanks Karel Zak 2 siblings, 1 reply; 6+ messages in thread From: Sami Kerola @ 2013-08-03 23:15 UTC (permalink / raw) To: util-linux; +Cc: kerolasa Especially with large inputs the change improves performance considerably. old> time more /boot/vmlinuz >/dev/null real 0m0.224s new> more /boot/vmlinuz >/dev/null real 0m0.009s Signed-off-by: Sami Kerola <kerolasa@iki.fi> --- text-utils/more.c | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) diff --git a/text-utils/more.c b/text-utils/more.c index ac35acc..598e048 100644 --- a/text-utils/more.c +++ b/text-utils/more.c @@ -780,10 +780,11 @@ void __attribute__((__noreturn__)) end_it(int dummy __attribute__((__unused__))) void copy_file(register FILE *f) { - register int c; + char buf[BUFSIZ]; + size_t sz; - while ((c = getc(f)) != EOF) - putchar(c); + while ((sz = fread(&buf, sizeof(char), sizeof(buf), f)) > 0) + fwrite(&buf, sizeof(char), sz, stdout); } #define ringbell() putcerr('\007') -- 1.8.3.4 ^ permalink raw reply related [flat|nested] 6+ messages in thread
* Re: [PATCH 2/3] more: make output redirection more efficient 2013-08-03 23:15 ` [PATCH 2/3] more: make output redirection more efficient Sami Kerola @ 2013-08-05 8:48 ` Karel Zak 0 siblings, 0 replies; 6+ messages in thread From: Karel Zak @ 2013-08-05 8:48 UTC (permalink / raw) To: Sami Kerola; +Cc: util-linux On Sun, Aug 04, 2013 at 12:15:20AM +0100, Sami Kerola wrote: > text-utils/more.c | 7 ++++--- > 1 file changed, 4 insertions(+), 3 deletions(-) Applied, thanks. -- Karel Zak <kzak@redhat.com> http://karelzak.blogspot.com ^ permalink raw reply [flat|nested] 6+ messages in thread
* [PATCH 3/3] cal: set statically defined data read-only 2013-08-03 23:15 [PATCH 1/3] column: use variable lenght printf field width to wprint blanks Sami Kerola 2013-08-03 23:15 ` [PATCH 2/3] more: make output redirection more efficient Sami Kerola @ 2013-08-03 23:15 ` Sami Kerola 2013-08-05 8:49 ` Karel Zak 2013-08-05 8:48 ` [PATCH 1/3] column: use variable lenght printf field width to wprint blanks Karel Zak 2 siblings, 1 reply; 6+ messages in thread From: Sami Kerola @ 2013-08-03 23:15 UTC (permalink / raw) To: util-linux; +Cc: kerolasa Signed-off-by: Sami Kerola <kerolasa@iki.fi> --- misc-utils/cal.c | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/misc-utils/cal.c b/misc-utils/cal.c index c4ed1d1..d31b51d 100644 --- a/misc-utils/cal.c +++ b/misc-utils/cal.c @@ -197,14 +197,14 @@ struct fmt_st char s[FMT_ST_LINES][FMT_ST_CHARS]; }; -static int days_in_month[2][13] = { +static const int days_in_month[2][13] = { {0, 31, 28, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31}, {0, 31, 29, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31}, }; /* September 1752 is special, and has static assignments for both date * and Julian representations. */ -static int d_sep1752[MAXDAYS / 2] = { +static const int d_sep1752[MAXDAYS / 2] = { SPACE, SPACE, 1, 2, 14, 15, 16, 17, 18, 19, 20, 21, 22, 23, 24, 25, 26, 27, 28, 29, 30 @@ -658,7 +658,7 @@ static void yearly(int day, long year, int julian) static void day_array(int day, int month, long year, int *days) { int julday, daynum, dw, dm; - int *sep1752; + const int *sep1752; memcpy(days, empty, MAXDAYS * sizeof(int)); if (year == REFORMATION_YEAR && month == REFORMATION_MONTH) { -- 1.8.3.4 ^ permalink raw reply related [flat|nested] 6+ messages in thread
* Re: [PATCH 3/3] cal: set statically defined data read-only 2013-08-03 23:15 ` [PATCH 3/3] cal: set statically defined data read-only Sami Kerola @ 2013-08-05 8:49 ` Karel Zak 0 siblings, 0 replies; 6+ messages in thread From: Karel Zak @ 2013-08-05 8:49 UTC (permalink / raw) To: Sami Kerola; +Cc: util-linux On Sun, Aug 04, 2013 at 12:15:21AM +0100, Sami Kerola wrote: > misc-utils/cal.c | 6 +++--- > 1 file changed, 3 insertions(+), 3 deletions(-) Applied, thanks. -- Karel Zak <kzak@redhat.com> http://karelzak.blogspot.com ^ permalink raw reply [flat|nested] 6+ messages in thread
* Re: [PATCH 1/3] column: use variable lenght printf field width to wprint blanks 2013-08-03 23:15 [PATCH 1/3] column: use variable lenght printf field width to wprint blanks Sami Kerola 2013-08-03 23:15 ` [PATCH 2/3] more: make output redirection more efficient Sami Kerola 2013-08-03 23:15 ` [PATCH 3/3] cal: set statically defined data read-only Sami Kerola @ 2013-08-05 8:48 ` Karel Zak 2 siblings, 0 replies; 6+ messages in thread From: Karel Zak @ 2013-08-05 8:48 UTC (permalink / raw) To: Sami Kerola; +Cc: util-linux On Sun, Aug 04, 2013 at 12:15:19AM +0100, Sami Kerola wrote: > text-utils/column.c | 5 ++--- > 1 file changed, 2 insertions(+), 3 deletions(-) Applied, thanks. -- Karel Zak <kzak@redhat.com> http://karelzak.blogspot.com ^ permalink raw reply [flat|nested] 6+ messages in thread
end of thread, other threads:[~2013-08-05 8:49 UTC | newest] Thread overview: 6+ messages (download: mbox.gz follow: Atom feed -- links below jump to the message on this page -- 2013-08-03 23:15 [PATCH 1/3] column: use variable lenght printf field width to wprint blanks Sami Kerola 2013-08-03 23:15 ` [PATCH 2/3] more: make output redirection more efficient Sami Kerola 2013-08-05 8:48 ` Karel Zak 2013-08-03 23:15 ` [PATCH 3/3] cal: set statically defined data read-only Sami Kerola 2013-08-05 8:49 ` Karel Zak 2013-08-05 8:48 ` [PATCH 1/3] column: use variable lenght printf field width to wprint blanks Karel Zak
This is a public inbox, see mirroring instructions for how to clone and mirror all data and code used for this inbox