diff options
author | Pádraig Brady <P@draigBrady.com> | 2012-09-14 14:21:03 +0100 |
---|---|---|
committer | Pádraig Brady <P@draigBrady.com> | 2012-09-14 23:22:55 +0100 |
commit | 3786fb6de3918692675287953825ef623bcff9b6 (patch) | |
tree | 822d3b28b1937a3756bf22395590dc06c41bc678 | |
parent | cb5ff9de6cab8ecc7363b89b34e774e0d5e89abf (diff) | |
download | coreutils-3786fb6de3918692675287953825ef623bcff9b6.tar.xz |
seq: enable the fast integer printing code in more cases
* src/seq.c (main): Adjust the initial arbitrary precision
seq_fast enablement checks to be more maintainable, and
a little more general, by allowing single character
separators to use seq_fast.
Also check again after the number arguments are processed,
to see if we can still use seq_fast, which while not
allowing arbitarly large integers, it will handle
integers of the form 10E10 etc.
(seq_fast): Use a specified separator character,
rather than hardcoding '\n'.
-rw-r--r-- | src/seq.c | 37 |
1 files changed, 30 insertions, 7 deletions
@@ -417,7 +417,7 @@ seq_fast (char const *a, char const *b) { incr (&p, &p_len); z = mempcpy (z, p, p_len); - *z++ = '\n'; + *z++ = *separator; if (buf_end - n - 1 < z) { fwrite (buf, z - buf, 1, stdout); @@ -536,13 +536,13 @@ main (int argc, char **argv) - integer end - increment == 1 or not specified [FIXME: relax this, eventually] then use the much more efficient integer-only code. */ - if (format_str == NULL - && all_digits_p (argv[1]) - && (n_args == 1 || all_digits_p (argv[2])) - && (n_args < 3 || STREQ ("1", argv[3]))) + if (all_digits_p (argv[optind]) + && (n_args == 1 || all_digits_p (argv[optind + 1])) + && (n_args < 3 || STREQ ("1", argv[optind + 2])) + && !equal_width && !format_str && strlen (separator) == 1) { - char const *s1 = n_args == 1 ? "1" : argv[1]; - char const *s2 = n_args == 1 ? argv[1] : argv[2]; + char const *s1 = n_args == 1 ? "1" : argv[optind]; + char const *s2 = n_args == 1 ? argv[optind] : argv[optind + 1]; if (seq_fast (s1, s2)) exit (EXIT_SUCCESS); @@ -563,6 +563,29 @@ main (int argc, char **argv) } } + if (first.precision == 0 && step.precision == 0 && last.precision == 0 + && 0 <= first.value && step.value == 1 && 0 <= last.value + && !equal_width && !format_str && strlen (separator) == 1) + { + char *s1; + char *s2; + if (asprintf (&s1, "%0.Lf", first.value) < 0) + xalloc_die (); + if (asprintf (&s2, "%0.Lf", last.value) < 0) + xalloc_die (); + + if (seq_fast (s1, s2)) + { + IF_LINT (free (s1)); + IF_LINT (free (s2)); + exit (EXIT_SUCCESS); + } + + free (s1); + free (s2); + /* Upon any failure, let the more general code deal with it. */ + } + if (format_str == NULL) format_str = get_default_format (first, step, last); |