git/list[1] front-page[2] threads[3] people[4] search[5] about
 

Re: [PATCH v3 2/5] strvec: add a strvec_pushvec()

From
Junio C Hamano <gitster@pobox.com>
Date
Aug 28, 2021, 01:23 UTC
Message-ID
<xmqq8s0m9xbl.fsf@gitster.g>
In-Reply-To
<patch-v3-2.5-321b8ba3f0e-20210826T140414Z-avarab@gmail.com>
Ævar Arnfjörð Bjarmason  <avarab@gmail.com> writes:
Show 9 quoted lines
> Add a strvec_pushvec() function to concatenate two "struct strvec *"
> together, and modify code added in 50d89ad6542 (submodule: use
> argv_array instead of hand-building arrays, 2012-09-01) to use it. In
> a subsequent commit we'll gain another API user.
>
> This could also have been named strvec_concat()[1], but I opted to
> make its name consistent with the strbuf_addbuf() function instead. We
> only name these sorts of functions *_concat() in one instance:
> parse_options_concat().
FWIW pushvec() is a much better name than concat() for this.

concat(A, B) could be an operation that is non-destructive for both A and B that returns a new vector C. I would imagine that it would be how, if not majority of, but at least a nontrivial percentage of, readers expect a function called concat() to behave. A better name for destructive version would probably be append(), if there is no other constraints on naming.

The name pushvec(A, B) makes it clear, thanks to similarity with other push*(A, ...) variants, that A is mutated using the other arguments. The name is much more clear with less chance of misunderstanding.

Show 7 quoted lines
> +void strvec_pushvec(struct strvec *array, const struct strvec *items)
> +{
> +	int i;
> +
> +	for (i = 0; i < items->nr; i++)
> +		strvec_push(array, items->v[i]);
> +}

This implementation is not wrong per-se, but is somewhat disappointing. When items->nr is large, especially relative to the original array->alloc, it would incur unnecessary reallocations that we can easily avoid by pre-sizing the array before pushing the elements of items from it.

In the original code that became the first user of this helper, it may not have made much difference, but now it is becoming a more generally reusable API function, we should care.

Other than that, looks quite straight-forward.
Thanks.
Previous: Ævar Arnfjörð BjarmasonNext: Junio C Hamano
Message 25 of 42 in “bundle: show progress on "unbundle"”
  1. 0/4 bundle: show progress on "unbundle"Ævar Arnfjörð Bjarmason, Jul 27, 2021
  2. 2/4 bundle API: change "flags" to be "extra_index_pack_args"Ævar Arnfjörð Bjarmason, Jul 27, 2021
  3. 1/4 bundle API: start writing API documentationÆvar Arnfjörð Bjarmason, Jul 27, 2021
  4. 3/4 index-pack: add --progress-title optionÆvar Arnfjörð Bjarmason, Jul 27, 2021
  5. 4/4 bundle: show progress on "unbundle"Ævar Arnfjörð Bjarmason, Jul 27, 2021
  6. 0/4 bundle: show progress on "unbundle"Ævar Arnfjörð Bjarmason, Aug 23, 2021
  7. 2/4 bundle API: change "flags" to be "extra_index_pack_args"Ævar Arnfjörð Bjarmason, Aug 23, 2021
  8. Derrick StoleeAug 24, 2021
  9. Ævar Arnfjörð BjarmasonAug 24, 2021
  10. Derrick StoleeAug 24, 2021
  11. 1/4 bundle API: start writing API documentationÆvar Arnfjörð Bjarmason, Aug 23, 2021
  12. Derrick StoleeAug 24, 2021
  13. Ævar Arnfjörð BjarmasonAug 24, 2021
  14. 3/4 index-pack: add --progress-title optionÆvar Arnfjörð Bjarmason, Aug 23, 2021
  15. Derrick StoleeAug 24, 2021
  16. Ævar Arnfjörð BjarmasonAug 24, 2021
  17. 4/4 bundle: show progress on "unbundle"Ævar Arnfjörð Bjarmason, Aug 23, 2021
  18. Derrick StoleeAug 24, 2021
  19. Ævar Arnfjörð BjarmasonAug 24, 2021
  20. 0/5 bundle: show progress on "unbundle"Ævar Arnfjörð Bjarmason, Aug 26, 2021
  21. 1/5 bundle API: start writing API documentationÆvar Arnfjörð Bjarmason, Aug 26, 2021
  22. 3/5 bundle API: change "flags" to be "extra_index_pack_args"Ævar Arnfjörð Bjarmason, Aug 26, 2021
  23. Junio C HamanoAug 28, 2021
  24. 2/5 strvec: add a strvec_pushvec()Ævar Arnfjörð Bjarmason, Aug 26, 2021
  25. Junio C HamanoAug 28, 2021
  26. Junio C HamanoAug 28, 2021
  27. Jeff KingAug 28, 2021
  28. Junio C HamanoAug 29, 2021
  29. Derrick StoleeAug 30, 2021
  30. Ævar Arnfjörð BjarmasonSep 2, 2021
  31. Junio C HamanoSep 3, 2021
  32. Jeff KingSep 3, 2021
  33. 4/5 index-pack: add --progress-title optionÆvar Arnfjörð Bjarmason, Aug 26, 2021
  34. Junio C HamanoAug 28, 2021
  35. 5/5 bundle: show progress on "unbundle"Ævar Arnfjörð Bjarmason, Aug 26, 2021
  36. Junio C HamanoAug 28, 2021
  37. Ævar Arnfjörð BjarmasonSep 2, 2021
  38. 0/4 bundle: show progress on "unbundle"Ævar Arnfjörð Bjarmason, Sep 5, 2021
  39. 1/4 bundle API: start writing API documentationÆvar Arnfjörð Bjarmason, Sep 5, 2021
  40. 2/4 bundle API: change "flags" to be "extra_index_pack_args"Ævar Arnfjörð Bjarmason, Sep 5, 2021
  41. 3/4 index-pack: add --progress-title optionÆvar Arnfjörð Bjarmason, Sep 5, 2021
  42. 4/4 bundle: show progress on "unbundle"Ævar Arnfjörð Bjarmason, Sep 5, 2021

Read the whole thread, see it on lore, or plain text.

$ cat FOOTERMessages come from the public archive at lore.kernel.org/git, fetched every hour. The front page is chosen and written each morning by an AI editor and can be wrong; the threads themselves are the record. About and API. For agents: an MCP server at https://gitlist.dev/mcp, and any thread, story or person page as Markdown by adding .md to its URL (or sending Accept: text/markdown). Details in /llms.txt.