Skip to content

Commit 7a9f8ca

Browse files
rscharfegitster
authored andcommitted
parse-options: simplify parse_options_dup()
Simplify parse_options_dup() by making it a trivial wrapper of parse_options_concat() by making use of the facts that the latter duplicates its input as well and that appending an empty set is a no-op. Signed-off-by: René Scharfe <[email protected]> Signed-off-by: Junio C Hamano <[email protected]>
1 parent c840785 commit 7a9f8ca

File tree

1 file changed

+3
-9
lines changed

1 file changed

+3
-9
lines changed

parse-options-cb.c

Lines changed: 3 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -170,15 +170,9 @@ static size_t parse_options_count(const struct option *opt)
170170

171171
struct option *parse_options_dup(const struct option *o)
172172
{
173-
const struct option *orig = o;
174-
struct option *opts;
175-
size_t nr = parse_options_count(o);
176-
177-
ALLOC_ARRAY(opts, nr + 1);
178-
COPY_ARRAY(opts, orig, nr);
179-
memset(opts + nr, 0, sizeof(*opts));
180-
opts[nr].type = OPTION_END;
181-
return opts;
173+
struct option no_options[] = { OPT_END() };
174+
175+
return parse_options_concat(o, no_options);
182176
}
183177

184178
struct option *parse_options_concat(const struct option *a,

0 commit comments

Comments
 (0)