Skip to content

Commit a46baac

Browse files
pcloudsgitster
authored andcommitted
fsck: factor out msg_id_info[] lazy initialization code
This array will be used by some other function than parse_msg_id() in the following commit. Factor out this prep code so it could be called from that one. Signed-off-by: Nguyễn Thái Ngọc Duy <[email protected]> Signed-off-by: Junio C Hamano <[email protected]>
1 parent fa151dc commit a46baac

File tree

1 file changed

+24
-16
lines changed

1 file changed

+24
-16
lines changed

fsck.c

Lines changed: 24 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -84,26 +84,34 @@ static struct {
8484
};
8585
#undef MSG_ID
8686

87-
static int parse_msg_id(const char *text)
87+
static void prepare_msg_ids(void)
8888
{
8989
int i;
9090

91-
if (!msg_id_info[0].downcased) {
92-
/* convert id_string to lower case, without underscores. */
93-
for (i = 0; i < FSCK_MSG_MAX; i++) {
94-
const char *p = msg_id_info[i].id_string;
95-
int len = strlen(p);
96-
char *q = xmalloc(len);
97-
98-
msg_id_info[i].downcased = q;
99-
while (*p)
100-
if (*p == '_')
101-
p++;
102-
else
103-
*(q)++ = tolower(*(p)++);
104-
*q = '\0';
105-
}
91+
if (msg_id_info[0].downcased)
92+
return;
93+
94+
/* convert id_string to lower case, without underscores. */
95+
for (i = 0; i < FSCK_MSG_MAX; i++) {
96+
const char *p = msg_id_info[i].id_string;
97+
int len = strlen(p);
98+
char *q = xmalloc(len);
99+
100+
msg_id_info[i].downcased = q;
101+
while (*p)
102+
if (*p == '_')
103+
p++;
104+
else
105+
*(q)++ = tolower(*(p)++);
106+
*q = '\0';
106107
}
108+
}
109+
110+
static int parse_msg_id(const char *text)
111+
{
112+
int i;
113+
114+
prepare_msg_ids();
107115

108116
for (i = 0; i < FSCK_MSG_MAX; i++)
109117
if (!strcmp(text, msg_id_info[i].downcased))

0 commit comments

Comments
 (0)