Skip to content

Commit 29aa0b2

Browse files
rscharfegitster
authored andcommitted
blame: factor out get_next_line()
Move the code for finding the start of the next line into a helper function in order to reduce duplication. Signed-off-by: Rene Scharfe <[email protected]> Signed-off-by: Junio C Hamano <[email protected]>
1 parent e156455 commit 29aa0b2

File tree

1 file changed

+10
-18
lines changed

1 file changed

+10
-18
lines changed

builtin/blame.c

Lines changed: 10 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -1741,6 +1741,12 @@ static void output(struct scoreboard *sb, int option)
17411741
}
17421742
}
17431743

1744+
static const char *get_next_line(const char *start, const char *end)
1745+
{
1746+
const char *nl = memchr(start, '\n', end - start);
1747+
return nl ? nl + 1 : NULL;
1748+
}
1749+
17441750
/*
17451751
* To allow quick access to the contents of nth line in the
17461752
* final image, prepare an index in the scoreboard.
@@ -1754,15 +1760,8 @@ static int prepare_lines(struct scoreboard *sb)
17541760
int *lineno;
17551761
int num = 0, incomplete = 0;
17561762

1757-
for (p = buf;;) {
1758-
p = memchr(p, '\n', end - p);
1759-
if (p) {
1760-
p++;
1761-
num++;
1762-
continue;
1763-
}
1764-
break;
1765-
}
1763+
for (p = get_next_line(buf, end); p; p = get_next_line(p, end))
1764+
num++;
17661765

17671766
if (len && end[-1] != '\n')
17681767
incomplete++; /* incomplete line at the end */
@@ -1771,15 +1770,8 @@ static int prepare_lines(struct scoreboard *sb)
17711770
lineno = sb->lineno;
17721771

17731772
*lineno++ = 0;
1774-
for (p = buf;;) {
1775-
p = memchr(p, '\n', end - p);
1776-
if (p) {
1777-
p++;
1778-
*lineno++ = p - buf;
1779-
continue;
1780-
}
1781-
break;
1782-
}
1773+
for (p = get_next_line(buf, end); p; p = get_next_line(p, end))
1774+
*lineno++ = p - buf;
17831775

17841776
if (incomplete)
17851777
*lineno++ = len;

0 commit comments

Comments
 (0)