summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorJim Meyering <meyering@redhat.com>2010-06-06 18:51:42 +0200
committerJim Meyering <meyering@redhat.com>2010-06-08 13:16:26 +0200
commitad89ea6a0dc4a404871f87eef6e9727c07f4cfb6 (patch)
tree1da42e1b6f2e5dabd2ece55e7e9e9611cc5b47d9
parent04bed02096fc574476886d6494a6a147b5208f6b (diff)
downloadcoreutils-ad89ea6a0dc4a404871f87eef6e9727c07f4cfb6.tar.gz
sort: avoid unnecessary use of sprintf
sprintf is relatively heavy-weight. * src/sort.c (key_warnings): Use umaxtostr and stpcpy rather than sprintf. Also, replace each INT_BUFSIZE_BOUND "type_name" argument with the equivalent variable name. More maintainable that way.
-rw-r--r--src/sort.c25
1 files changed, 13 insertions, 12 deletions
diff --git a/src/sort.c b/src/sort.c
index 5c3da0c4f..517907086 100644
--- a/src/sort.c
+++ b/src/sort.c
@@ -1260,7 +1260,7 @@ specify_nmerge (int oi, char c, char const *s)
if (e == LONGINT_OVERFLOW)
{
- char max_nmerge_buf[INT_BUFSIZE_BOUND (unsigned int)];
+ char max_nmerge_buf[INT_BUFSIZE_BOUND (max_nmerge)];
error (0, 0, _("--%s argument %s too large"),
long_options[oi].name, quote (s));
error (SORT_FAILURE, 0,
@@ -2230,27 +2230,28 @@ key_warnings (struct keyfield const *gkey, bool gkey_only)
{
if (key->obsolete_used)
{
+ size_t sword = key->sword;
+ size_t eword = key->eword;
+ char tmp[INT_BUFSIZE_BOUND (sword)];
/* obsolescent syntax +A.x -B.y is equivalent to:
-k A+1.x+1,B.y (when y = 0)
-k A+1.x+1,B+1.y (when y > 0) */
- char obuf[INT_BUFSIZE_BOUND (size_t) * 2 + 4]; /* +# -# */
- char nbuf[INT_BUFSIZE_BOUND (size_t) * 2 + 5]; /* -k #,# */
-
+ char obuf[INT_BUFSIZE_BOUND (sword) * 2 + 4]; /* +# -# */
+ char nbuf[INT_BUFSIZE_BOUND (sword) * 2 + 5]; /* -k #,# */
char *po = obuf;
char *pn = nbuf;
- size_t sword = key->sword;
- size_t eword = key->eword;
if (sword == SIZE_MAX)
sword++;
- po += sprintf (po, "+%" PRIuMAX, (uintmax_t) sword);
- pn += sprintf (pn, "-k %" PRIuMAX, (uintmax_t) sword + 1);
+ po = stpcpy (stpcpy (po, "+"), umaxtostr (sword, tmp));
+ pn = stpcpy (stpcpy (pn, "-k "), umaxtostr (sword + 1, tmp));
if (key->eword != SIZE_MAX)
{
- po += sprintf (po, " -%" PRIuMAX, (uintmax_t) eword + 1);
- pn += sprintf (pn, ",%" PRIuMAX,
- (uintmax_t) eword + 1 + (key->echar == SIZE_MAX));
+ po = stpcpy (stpcpy (po, " -"), umaxtostr (eword + 1, tmp));
+ pn = stpcpy (stpcpy (pn, ","),
+ umaxtostr (eword + 1
+ + (key->echar == SIZE_MAX), tmp));
}
error (0, 0, _("obsolescent key `%s' used; consider `%s' instead"),
obuf, nbuf);
@@ -2651,7 +2652,7 @@ check (char const *file_name, char checkonly)
struct line const *disorder_line = line - 1;
uintmax_t disorder_line_number =
buffer_linelim (&buf) - disorder_line + line_number;
- char hr_buf[INT_BUFSIZE_BOUND (uintmax_t)];
+ char hr_buf[INT_BUFSIZE_BOUND (disorder_line_number)];
fprintf (stderr, _("%s: %s:%s: disorder: "),
program_name, file_name,
umaxtostr (disorder_line_number, hr_buf));