File tree Expand file tree Collapse file tree
Expand file tree Collapse file tree Original file line number Diff line number Diff line change @@ -80,15 +80,6 @@ static bool string_list_capacity(struct string_list *list, size_t cap)
8080 return true;
8181}
8282
83- static bool string_list_initialize_internal (struct string_list * list )
84- {
85- list -> elems = NULL ;
86- list -> size = 0 ;
87- list -> cap = 0 ;
88-
89- return string_list_capacity (list , 32 );
90- }
91-
9283/**
9384 * string_list_free
9485 * @list : pointer to string list object
@@ -126,30 +117,42 @@ bool string_list_deinitialize(struct string_list *list)
126117 */
127118struct string_list * string_list_new (void )
128119{
120+ struct string_list_elem *
121+ elems = NULL ;
129122 struct string_list * list = (struct string_list * )
130123 malloc (sizeof (* list ));
131-
132124 if (!list )
133125 return NULL ;
134126
135- if (!string_list_initialize_internal (list ))
127+ if (!(elems = (struct string_list_elem * )
128+ calloc (32 , sizeof (* elems ))))
136129 {
137130 string_list_free (list );
138131 return NULL ;
139132 }
140133
134+ list -> elems = elems ;
135+ list -> size = 0 ;
136+ list -> cap = 32 ;
137+
141138 return list ;
142139}
143140
144141bool string_list_initialize (struct string_list * list )
145142{
143+ struct string_list_elem *
144+ elems = NULL ;
146145 if (!list )
147146 return false;
148- if (!string_list_initialize_internal (list ))
147+ if (!(elems = (struct string_list_elem * )
148+ calloc (32 , sizeof (* elems ))))
149149 {
150150 string_list_deinitialize (list );
151151 return false;
152152 }
153+ list -> elems = elems ;
154+ list -> size = 0 ;
155+ list -> cap = 32 ;
153156 return true;
154157}
155158
You can’t perform that action at this time.
0 commit comments