Re: [PATCH 3/9] fsck: factor out msg_id_info[] lazy initialization code
- From
Eric Sunshine <sunshine@sunshineco.com>
- Date
- May 11, 2018, 22:23 UTC
- Message-ID
- <CAPig+cQYaabk+XibOMUGa5b4y2D8AhjNBjujgNE7ctLCdFpdCQ@mail.gmail.com>
- In-Reply-To
- <20180510141927.23590-4-pclouds@gmail.com>
On Thu, May 10, 2018 at 10:19 AM Nguyễn Thái Ngọc Duy <pclouds@gmail.com> wrote:
> 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.
Show 9 quoted lines
> Signed-off-by: Nguyễn Thái Ngọc Duy <pclouds@gmail.com>
> ---
> diff --git a/fsck.c b/fsck.c
> @@ -84,26 +84,32 @@ static struct {
> -static int parse_msg_id(const char *text)
> +static void prepare_msg_ids(void)
> {
> - if (!msg_id_info[0].downcased) {
> - /* convert id_string to lower case, without underscores.*/
Show 13 quoted lines
> - for (i = 0; i < FSCK_MSG_MAX; i++) {
> - [...]
> - }
> + /* convert id_string to lower case, without underscores. */
> + for (i = 0; i < FSCK_MSG_MAX; i++) {
> + [...]
> }
> +}
> +
> +static int parse_msg_id(const char *text)
> +{
> + if (!msg_id_info[0].downcased)
> + prepare_msg_ids();If you move the "if (!msg_id_info...)" conditional into the new parpare_msg_ids() function, then it becomes self-contained; it takes care of avoiding double-initialization so callers don't have to worry or know about it. (Doing so would also make the diff less noisy.)
Not at all worth a re-roll.