On 06/23/2014 05:36 AM, Torsten Bögershausen wrote:
> If we look at the definition below:
> struct string_list {
>       struct string_list_item *items;
>       unsigned int nr, alloc;
>       unsigned int strdup_strings:1;
>       compare_strings_fn cmp; /* NULL uses strcmp() */
> I think a simple memset() will be easier to read,
> and it will be more future proof:
> In case elements are added, the will have 0 or NULL automatically:

Yes, you are right. After sending the patch I saw that for string_list
initialization the codebase either uses xcalloc or memset and after that
marks the list as DUP or NODUP.

> void string_list_init_nodup(struct string_list *list)
> {
>       memset (list, 0, sizeof(*list));
> }
> (But then I wonder if we need the function at all ?)
> Or does it make sense to have a common function similar to this,
> which covers both cases:
> void string_list_init(struct string_list *list, int strdup_strings)
> {
>       memset (list, 0, sizeof(*list));
>       list->strdup_strings = strdup_strings;
> }

A common function would be much better as other API constructs as strbuf
have runtime init functions like the version you have shown above.

Thanks for the review.

To unsubscribe from this list: send the line "unsubscribe git" in
the body of a message to majord...@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html

Reply via email to