Thread (34 messages) 34 messages, 4 authors, 2018-05-29

Re: [PATCH 3/9] fsck: factor out msg_id_info[] lazy initialization code

From: Eric Sunshine <hidden>
Date: 2018-05-11 22:23:42

On Thu, May 10, 2018 at 10:19 AM Nguyễn Thái Ngọc Duy [off-list ref]
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.
quoted hunk ↗ jump to hunk
Signed-off-by: Nguyễn Thái Ngọc Duy <redacted>
---
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.
*/
-               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.
Keyboard shortcuts
hback out one level
jnext message in thread
kprevious message in thread
ldrill in
Escclose help / fold thread tree
?toggle this help