nbelakov...@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.

Reply via email to