[git commit] shuf: do not use strings for -i RANGE case

Denys Vlasenko vda.linux at googlemail.com
Fri Mar 7 13:32:39 UTC 2014


commit: http://git.busybox.net/busybox/commit/?id=102f0d0d073c4781b5a58f679bdfd0999eea5e71
branch: http://git.busybox.net/busybox/commit/?id=refs/heads/master

function                                             old     new   delta
shuf_main                                            482     496     +14

Signed-off-by: Denys Vlasenko <vda.linux at googlemail.com>
---
 coreutils/shuf.c |    8 +++++---
 1 files changed, 5 insertions(+), 3 deletions(-)

diff --git a/coreutils/shuf.c b/coreutils/shuf.c
index e0c2fbf..d1cd39d 100644
--- a/coreutils/shuf.c
+++ b/coreutils/shuf.c
@@ -79,7 +79,6 @@ int shuf_main(int argc, char **argv)
 	/* Prepare lines for shuffling - either: */
 	if (opts & OPT_e) {
 		/* make lines from command-line arguments */
-
 		numlines = argc;
 		lines = argv;
 	} else
@@ -103,7 +102,7 @@ int shuf_main(int argc, char **argv)
 		numlines = (hi+1) - lo;
 		lines = xmalloc(numlines * sizeof(lines[0]));
 		for (i = 0; i < numlines; i++) {
-			lines[i] = xstrdup(utoa(lo));
+			lines[i] = (char*)(uintptr_t)lo;
 			lo++;
 		}
 	} else {
@@ -144,7 +143,10 @@ int shuf_main(int argc, char **argv)
 		eol = '\0';
 
 	for (i = 0; i < numlines; i++) {
-		printf("%s%c", lines[i], eol);
+		if (opts & OPT_i)
+			printf("%u%c", (unsigned)(uintptr_t)lines[i], eol);
+		else
+			printf("%s%c", lines[i], eol);
 	}
 
 	fflush_stdout_and_exit(EXIT_SUCCESS);


More information about the busybox-cvs mailing list