Re: [PATCH v5 12/15] strmap: enable allocations to come from a mem_pool
- From
Elijah Newren <newren@gmail.com>
- Date
- Nov 11, 2020, 18:49 UTC
- Message-ID
- <CABPp-BGTS+qe1V7=ie7PjbRmKwwF=c54uOm43R1dnv7MgBJfyA@mail.gmail.com>
- In-Reply-To
- <fbaa60c4-ee6b-02b7-68b5-e5873f8ec713@gmail.com>
On Wed, Nov 11, 2020 at 9:33 AM Phillip Wood <phillip.wood123@gmail.com> wrote:
Show 27 quoted lines
> > Hi Elijah > > On 06/11/2020 00:24, Elijah Newren via GitGitGadget wrote: > > From: Elijah Newren <newren@gmail.com> > > > > For heavy users of strmaps, allowing the keys and entries to be > > allocated from a memory pool can provide significant overhead savings. > > Add an option to strmap_init_with_options() to specify a memory pool. > > [...] > > diff --git a/strmap.h b/strmap.h > > index c8c4d7c932..dda928703d 100644 > > --- a/strmap.h > > +++ b/strmap.h > > @@ -3,8 +3,10 @@ > > > > #include "hashmap.h" > > > > +struct mempool; > > I think this is a typo - I assume you wanted to declare `struct > mem_pool` but it's not strictly necessary as you're only adding a > pointer to the struct below. > > Best Wishes > > Phillip
Indeed, thanks.
Show 44 quoted lines
>
> > struct strmap {
> > struct hashmap map;
> > + struct mem_pool *pool;
> > unsigned int strdup_strings:1;
> > };
> >
> > @@ -37,9 +39,10 @@ void strmap_init(struct strmap *map);
> >
> > /*
> > * Same as strmap_init, but for those who want to control the memory management
> > - * carefully instead of using the default of strdup_strings=1.
> > + * carefully instead of using the default of strdup_strings=1 and pool=NULL.
> > */
> > void strmap_init_with_options(struct strmap *map,
> > + struct mem_pool *pool,
> > int strdup_strings);
> >
> > /*
> > @@ -137,9 +140,10 @@ static inline void strintmap_init(struct strintmap *map, int default_value)
> >
> > static inline void strintmap_init_with_options(struct strintmap *map,
> > int default_value,
> > + struct mem_pool *pool,
> > int strdup_strings)
> > {
> > - strmap_init_with_options(&map->map, strdup_strings);
> > + strmap_init_with_options(&map->map, pool, strdup_strings);
> > map->default_value = default_value;
> > }
> >
> > @@ -221,9 +225,10 @@ static inline void strset_init(struct strset *set)
> > }
> >
> > static inline void strset_init_with_options(struct strset *set,
> > + struct mem_pool *pool,
> > int strdup_strings)
> > {
> > - strmap_init_with_options(&set->map, strdup_strings);
> > + strmap_init_with_options(&set->map, pool, strdup_strings);
> > }
> >
> > static inline void strset_clear(struct strset *set)
> >