[git commit] cut: code shrink
Denys Vlasenko
vda.linux at googlemail.com
Fri Dec 20 23:43:45 UTC 2024
commit: https://git.busybox.net/busybox/commit/?id=14f57f5357cb674b88e7cdaff6267bf9d84c6b80
branch: https://git.busybox.net/busybox/commit/?id=refs/heads/master
move "linenum" manipulations to the one place where it is used.
function old new delta
cut_main 1373 1360 -13
Signed-off-by: Denys Vlasenko <vda.linux at googlemail.com>
---
coreutils/cut.c | 11 +++++------
1 file changed, 5 insertions(+), 6 deletions(-)
diff --git a/coreutils/cut.c b/coreutils/cut.c
index 93b58b493..d81f36bcd 100644
--- a/coreutils/cut.c
+++ b/coreutils/cut.c
@@ -143,15 +143,15 @@ static void cut_file(FILE *file, const char *delim, const char *odelim,
} else if (!opt_REGEX && *delim == '\n') {
unsigned spos = cut_list[cl_pos].startpos;
+ linenum++;
/* get out if we have no more ranges to process or if the lines
* are lower than what we're interested in */
- if ((linenum < spos) || END_OF_LIST(cut_list[cl_pos]))
+ if (linenum <= spos || END_OF_LIST(cut_list[cl_pos]))
goto next_line;
/* if the line we're looking for is lower than the one we were
* passed, it means we displayed it already, so move on */
- while (spos < linenum) {
- spos++;
+ while (++spos < linenum) {
/* go to the next list if we're at the end of this one */
if (spos > cut_list[cl_pos].endpos) {
cl_pos++;
@@ -161,7 +161,7 @@ static void cut_file(FILE *file, const char *delim, const char *odelim,
spos = cut_list[cl_pos].startpos;
/* get out if the current line is lower than the one
* we just became interested in */
- if (linenum < spos)
+ if (linenum <= spos)
goto next_line;
}
}
@@ -280,7 +280,6 @@ static void cut_file(FILE *file, const char *delim, const char *odelim,
/* if we printed anything, finish with newline */
putchar('\n');
next_line:
- linenum++;
free(line);
} /* while (got line) */
@@ -399,7 +398,7 @@ int cut_main(int argc UNUSED_PARAM, char **argv)
//if (nranges == 0)
// bb_simple_error_msg_and_die("missing list of positions");
//^^^ this is impossible since one of -bcfF is required,
- // they populate LIST with non-empty string and when it is parsed,
+ // they populate LIST with non-NULL string and when it is parsed,
// cut_list[] gets at least one element.
/* now that the lists are parsed, we need to sort them to make life
More information about the busybox-cvs
mailing list