From: Junio C Hamano Date: Fri, 01 Feb 2019 22:31:32 GMT Subject: Re: [PATCH v7 1/3] ref-filter: add worktreepath atom Message-ID: In-Reply-To: <20190201220420.36216-2-nbelakovski@gmail.com> nbelakovski@gmail.com writes: > +static void lazy_init_worktree_map(void) > +{ > + if (ref_to_worktree_map.worktrees) > + return; > + > + ref_to_worktree_map.worktrees = get_worktrees(0); > + hashmap_init(&(ref_to_worktree_map.map), ref_to_worktree_map_cmpfnc, NULL, 0); > + populate_worktree_map(&(ref_to_worktree_map.map), ref_to_worktree_map.worktrees); > +} > + > +static char *get_worktree_path(const struct used_atom *atom, const struct ref_array_item *ref) > +{ > + struct hashmap_entry entry; > + struct ref_to_worktree_entry *lookup_result; > + > + lazy_init_worktree_map(); > + > + hashmap_entry_init(&entry, strhash(ref->refname)); > + lookup_result = hashmap_get(&(ref_to_worktree_map.map), &entry, ref->refname); > + > + if (lookup_result) > + return xstrdup(lookup_result->wt->path); > + else > + return xstrdup(""); > +} Makes more sense than the previous round; much simpler to have lazy-init in this function. Thanks.