Skip to content

Commit ed7eba9

Browse files
peffgitster
authored andcommitted
shortlog: optimize out useless "<none>" normalization
If we are in --summary mode, we will always pass <none> to insert_one_record, which will then do some normalization (e.g., cutting out "[PATCH]"). There's no point in doing so if we aren't going to use the result anyway. This drops my best-of-five for "git shortlog -ns HEAD" on linux.git from: real 0m5.257s user 0m5.104s sys 0m0.156s to: real 0m5.194s user 0m5.028s sys 0m0.168s That's only 1%, but arguably the result is clearer to read, as we're able to group our variable declarations inside the conditional block. It also opens up further optimization possibilities for future patches. Signed-off-by: Jeff King <[email protected]> Signed-off-by: Junio C Hamano <[email protected]>
1 parent 4e1d1a2 commit ed7eba9

File tree

1 file changed

+34
-29
lines changed

1 file changed

+34
-29
lines changed

builtin/shortlog.c

Lines changed: 34 additions & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -31,13 +31,9 @@ static void insert_one_record(struct shortlog *log,
3131
const char *author,
3232
const char *oneline)
3333
{
34-
const char *dot3 = log->common_repo_prefix;
35-
char *buffer, *p;
3634
struct string_list_item *item;
3735
const char *mailbuf, *namebuf;
3836
size_t namelen, maillen;
39-
const char *eol;
40-
struct strbuf subject = STRBUF_INIT;
4137
struct strbuf namemailbuf = STRBUF_INIT;
4238
struct ident_split ident;
4339

@@ -59,34 +55,43 @@ static void insert_one_record(struct shortlog *log,
5955
if (item->util == NULL)
6056
item->util = xcalloc(1, sizeof(struct string_list));
6157

62-
/* Skip any leading whitespace, including any blank lines. */
63-
while (*oneline && isspace(*oneline))
64-
oneline++;
65-
eol = strchr(oneline, '\n');
66-
if (!eol)
67-
eol = oneline + strlen(oneline);
68-
if (starts_with(oneline, "[PATCH")) {
69-
char *eob = strchr(oneline, ']');
70-
if (eob && (!eol || eob < eol))
71-
oneline = eob + 1;
72-
}
73-
while (*oneline && isspace(*oneline) && *oneline != '\n')
74-
oneline++;
75-
format_subject(&subject, oneline, " ");
76-
buffer = strbuf_detach(&subject, NULL);
77-
78-
if (dot3) {
79-
int dot3len = strlen(dot3);
80-
if (dot3len > 5) {
81-
while ((p = strstr(buffer, dot3)) != NULL) {
82-
int taillen = strlen(p) - dot3len;
83-
memcpy(p, "/.../", 5);
84-
memmove(p + 5, p + dot3len, taillen + 1);
58+
if (log->summary)
59+
string_list_append(item->util, xstrdup(""));
60+
else {
61+
const char *dot3 = log->common_repo_prefix;
62+
char *buffer, *p;
63+
struct strbuf subject = STRBUF_INIT;
64+
const char *eol;
65+
66+
/* Skip any leading whitespace, including any blank lines. */
67+
while (*oneline && isspace(*oneline))
68+
oneline++;
69+
eol = strchr(oneline, '\n');
70+
if (!eol)
71+
eol = oneline + strlen(oneline);
72+
if (starts_with(oneline, "[PATCH")) {
73+
char *eob = strchr(oneline, ']');
74+
if (eob && (!eol || eob < eol))
75+
oneline = eob + 1;
76+
}
77+
while (*oneline && isspace(*oneline) && *oneline != '\n')
78+
oneline++;
79+
format_subject(&subject, oneline, " ");
80+
buffer = strbuf_detach(&subject, NULL);
81+
82+
if (dot3) {
83+
int dot3len = strlen(dot3);
84+
if (dot3len > 5) {
85+
while ((p = strstr(buffer, dot3)) != NULL) {
86+
int taillen = strlen(p) - dot3len;
87+
memcpy(p, "/.../", 5);
88+
memmove(p + 5, p + dot3len, taillen + 1);
89+
}
8590
}
8691
}
87-
}
8892

89-
string_list_append(item->util, buffer);
93+
string_list_append(item->util, buffer);
94+
}
9095
}
9196

9297
static void read_from_stdin(struct shortlog *log)

0 commit comments

Comments
 (0)