Thread (12 messages) flat view 12 messages, 5 authors, 2016-06-15

Re: [PATCH v3 1/3] string-list: add string_list initialiser helper functions

From: Tanay Abhra <hidden>
Date: 2016-06-15 23:01:43

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.
Keyboard shortcuts
hback out one level
jnext message in thread
kprevious message in thread
ldrill in
Escclose help / fold thread tree
?toggle this help