{"thread":{"id":"36043","subject":"[PATCH v4 00/14] Use ALLOC_GROW() instead of inline code","startedAt":"2014-03-03T22:31:48Z","lastAt":"2014-03-03T23:02:57Z","messageCount":17,"participants":["Dmitry S. Dolzhenko","Junio C Hamano"],"isPatch":true,"patchVersion":4,"patchTotal":14},"messages":[{"id":"235928","messageId":"1393885922-21616-1-git-send-email-dmitrys.dolzhenko@yandex.ru","threadId":"36043","inReplyTo":null,"subject":"[PATCH v4 00/14] Use ALLOC_GROW() instead of inline code","fromName":"Dmitry S. Dolzhenko","fromEmail":"dmitrys.dolzhenko@yandex.ru","sentAt":"2014-03-03T22:31:48Z","receivedAt":"2014-03-03T22:31:48Z","isPatch":true,"sender":{"key":"dmitrys.dolzhenko@yandex.ru","avatar":null},"body":"This version differs from previous [1] the following changes:\n  - added three new commits with similar changes in \"builtin/mktree.c\",\n    \"cache-tree.c\" and \"sha1_file.c\".\n  - updated commit messages: \"use ALLOC_GROW() in function_name()\" instead of\n    \"change function_name() to use ALLOC_GROW()\"\n  - updated [PATCH v2 01/11] [2] to keep code lines within 80 columns in \n    \"builtin/pack-objects.c\"\n\nDuy Nguyen, Michael Haggerty, Junio C Hamano, Eric Sunshine, and He Sun, \nthanks you very much for your remarks and advices\n\n[1] http://thread.gmane.org/gmane.comp.version-control.git/242919\n[2] http://thread.gmane.org/gmane.comp.version-control.git/242920\n\nDmitry S. Dolzhenko (14):\n  builtin/pack-objects.c: use ALLOC_GROW() in check_pbase_path()\n  bundle.c: use ALLOC_GROW() in add_to_ref_list()\n  cache-tree.c: use ALLOC_GROW() in find_subtree()\n  commit.c: use ALLOC_GROW() in register_commit_graft()\n  diff.c: use ALLOC_GROW()\n  diffcore-rename.c: use ALLOC_GROW()\n  patch-ids.c: use ALLOC_GROW() in add_commit()\n  replace_object.c: use ALLOC_GROW() in register_replace_object()\n  reflog-walk.c: use ALLOC_GROW()\n  dir.c: use ALLOC_GROW() in create_simplify()\n  attr.c: use ALLOC_GROW() in handle_attr_line()\n  builtin/mktree.c: use ALLOC_GROW() in append_to_tree()\n  read-cache.c: use ALLOC_GROW() in add_index_entry()\n  sha1_file.c: use ALLOC_GROW() in pretend_sha1_file()\n\n attr.c                 |  7 +------\n builtin/mktree.c       |  5 +----\n builtin/pack-objects.c |  9 +++------\n bundle.c               |  6 +-----\n cache-tree.c           |  6 +-----\n commit.c               |  8 ++------\n diff.c                 | 12 ++----------\n diffcore-rename.c      | 12 ++----------\n dir.c                  |  5 +----\n patch-ids.c            |  5 +----\n read-cache.c           |  6 +-----\n reflog-walk.c          | 12 ++----------\n replace_object.c       |  8 ++------\n sha1_file.c            |  7 +------\n 14 files changed, 21 insertions(+), 87 deletions(-)\n\n-- \n1.8.3.2\n"},{"id":"235929","messageId":"1393885922-21616-2-git-send-email-dmitrys.dolzhenko@yandex.ru","threadId":"36043","inReplyTo":"1393885922-21616-1-git-send-email-dmitrys.dolzhenko@yandex.ru","subject":"[PATCH v4 01/14] builtin/pack-objects.c: use ALLOC_GROW() in check_pbase_path()","fromName":"Dmitry S. Dolzhenko","fromEmail":"dmitrys.dolzhenko@yandex.ru","sentAt":"2014-03-03T22:31:49Z","receivedAt":"2014-03-03T22:31:49Z","isPatch":true,"sender":{"key":"dmitrys.dolzhenko@yandex.ru","avatar":null},"body":"Signed-off-by: Dmitry S. Dolzhenko <dmitrys.dolzhenko@yandex.ru>\n---\n builtin/pack-objects.c | 9 +++------\n 1 file changed, 3 insertions(+), 6 deletions(-)\n\ndiff --git a/builtin/pack-objects.c b/builtin/pack-objects.c\nindex c733379..0ffad6f 100644\n--- a/builtin/pack-objects.c\n+++ b/builtin/pack-objects.c\n@@ -1213,12 +1213,9 @@ static int check_pbase_path(unsigned hash)\n \tif (0 <= pos)\n \t\treturn 1;\n \tpos = -pos - 1;\n-\tif (done_pbase_paths_alloc <= done_pbase_paths_num) {\n-\t\tdone_pbase_paths_alloc = alloc_nr(done_pbase_paths_alloc);\n-\t\tdone_pbase_paths = xrealloc(done_pbase_paths,\n-\t\t\t\t\t    done_pbase_paths_alloc *\n-\t\t\t\t\t    sizeof(unsigned));\n-\t}\n+\tALLOC_GROW(done_pbase_paths,\n+\t\t   done_pbase_paths_num + 1,\n+\t\t   done_pbase_paths_alloc);\n \tdone_pbase_paths_num++;\n \tif (pos < done_pbase_paths_num)\n \t\tmemmove(done_pbase_paths + pos + 1,\n-- \n1.8.3.2\n"},{"id":"235930","messageId":"1393885922-21616-3-git-send-email-dmitrys.dolzhenko@yandex.ru","threadId":"36043","inReplyTo":"1393885922-21616-1-git-send-email-dmitrys.dolzhenko@yandex.ru","subject":"[PATCH v4 02/14] bundle.c: use ALLOC_GROW() in add_to_ref_list()","fromName":"Dmitry S. Dolzhenko","fromEmail":"dmitrys.dolzhenko@yandex.ru","sentAt":"2014-03-03T22:31:50Z","receivedAt":"2014-03-03T22:31:50Z","isPatch":true,"sender":{"key":"dmitrys.dolzhenko@yandex.ru","avatar":null},"body":"Signed-off-by: Dmitry S. Dolzhenko <dmitrys.dolzhenko@yandex.ru>\n---\n bundle.c | 6 +-----\n 1 file changed, 1 insertion(+), 5 deletions(-)\n\ndiff --git a/bundle.c b/bundle.c\nindex e99065c..1388a3e 100644\n--- a/bundle.c\n+++ b/bundle.c\n@@ -14,11 +14,7 @@ static const char bundle_signature[] = \"# v2 git bundle\\n\";\n static void add_to_ref_list(const unsigned char *sha1, const char *name,\n \t\tstruct ref_list *list)\n {\n-\tif (list->nr + 1 >= list->alloc) {\n-\t\tlist->alloc = alloc_nr(list->nr + 1);\n-\t\tlist->list = xrealloc(list->list,\n-\t\t\t\tlist->alloc * sizeof(list->list[0]));\n-\t}\n+\tALLOC_GROW(list->list, list->nr + 1, list->alloc);\n \tmemcpy(list->list[list->nr].sha1, sha1, 20);\n \tlist->list[list->nr].name = xstrdup(name);\n \tlist->nr++;\n-- \n1.8.3.2\n"},{"id":"235938","messageId":"1393885922-21616-4-git-send-email-dmitrys.dolzhenko@yandex.ru","threadId":"36043","inReplyTo":"1393885922-21616-1-git-send-email-dmitrys.dolzhenko@yandex.ru","subject":"[PATCH v4 03/14] cache-tree.c: use ALLOC_GROW() in find_subtree()","fromName":"Dmitry S. Dolzhenko","fromEmail":"dmitrys.dolzhenko@yandex.ru","sentAt":"2014-03-03T22:31:51Z","receivedAt":"2014-03-03T22:31:51Z","isPatch":true,"sender":{"key":"dmitrys.dolzhenko@yandex.ru","avatar":null},"body":"Signed-off-by: Dmitry S. Dolzhenko <dmitrys.dolzhenko@yandex.ru>\n---\n cache-tree.c | 6 +-----\n 1 file changed, 1 insertion(+), 5 deletions(-)\n\ndiff --git a/cache-tree.c b/cache-tree.c\nindex 0bbec43..30149d1 100644\n--- a/cache-tree.c\n+++ b/cache-tree.c\n@@ -75,11 +75,7 @@ static struct cache_tree_sub *find_subtree(struct cache_tree *it,\n \t\treturn NULL;\n \n \tpos = -pos-1;\n-\tif (it->subtree_alloc <= it->subtree_nr) {\n-\t\tit->subtree_alloc = alloc_nr(it->subtree_alloc);\n-\t\tit->down = xrealloc(it->down, it->subtree_alloc *\n-\t\t\t\t    sizeof(*it->down));\n-\t}\n+\tALLOC_GROW(it->down, it->subtree_nr + 1, it->subtree_alloc);\n \tit->subtree_nr++;\n \n \tdown = xmalloc(sizeof(*down) + pathlen + 1);\n-- \n1.8.3.2\n"},{"id":"235942","messageId":"1393885922-21616-5-git-send-email-dmitrys.dolzhenko@yandex.ru","threadId":"36043","inReplyTo":"1393885922-21616-1-git-send-email-dmitrys.dolzhenko@yandex.ru","subject":"[PATCH v4 04/14] commit.c: use ALLOC_GROW() in register_commit_graft()","fromName":"Dmitry S. Dolzhenko","fromEmail":"dmitrys.dolzhenko@yandex.ru","sentAt":"2014-03-03T22:31:52Z","receivedAt":"2014-03-03T22:31:52Z","isPatch":true,"sender":{"key":"dmitrys.dolzhenko@yandex.ru","avatar":null},"body":"Signed-off-by: Dmitry S. Dolzhenko <dmitrys.dolzhenko@yandex.ru>\n---\n commit.c | 8 ++------\n 1 file changed, 2 insertions(+), 6 deletions(-)\n\ndiff --git a/commit.c b/commit.c\nindex 6bf4fe0..e004314 100644\n--- a/commit.c\n+++ b/commit.c\n@@ -147,12 +147,8 @@ int register_commit_graft(struct commit_graft *graft, int ignore_dups)\n \t\treturn 1;\n \t}\n \tpos = -pos - 1;\n-\tif (commit_graft_alloc <= ++commit_graft_nr) {\n-\t\tcommit_graft_alloc = alloc_nr(commit_graft_alloc);\n-\t\tcommit_graft = xrealloc(commit_graft,\n-\t\t\t\t\tsizeof(*commit_graft) *\n-\t\t\t\t\tcommit_graft_alloc);\n-\t}\n+\tALLOC_GROW(commit_graft, commit_graft_nr + 1, commit_graft_alloc);\n+\tcommit_graft_nr++;\n \tif (pos < commit_graft_nr)\n \t\tmemmove(commit_graft + pos + 1,\n \t\t\tcommit_graft + pos,\n-- \n1.8.3.2\n"},{"id":"235940","messageId":"1393885922-21616-6-git-send-email-dmitrys.dolzhenko@yandex.ru","threadId":"36043","inReplyTo":"1393885922-21616-1-git-send-email-dmitrys.dolzhenko@yandex.ru","subject":"[PATCH v4 05/14] diff.c: use ALLOC_GROW()","fromName":"Dmitry S. Dolzhenko","fromEmail":"dmitrys.dolzhenko@yandex.ru","sentAt":"2014-03-03T22:31:53Z","receivedAt":"2014-03-03T22:31:53Z","isPatch":true,"sender":{"key":"dmitrys.dolzhenko@yandex.ru","avatar":null},"body":"Use ALLOC_GROW() instead inline code in\ndiffstat_add() and diff_q()\n\nSigned-off-by: Dmitry S. Dolzhenko <dmitrys.dolzhenko@yandex.ru>\n---\n diff.c | 12 ++----------\n 1 file changed, 2 insertions(+), 10 deletions(-)\n\ndiff --git a/diff.c b/diff.c\nindex e800666..aebdfda 100644\n--- a/diff.c\n+++ b/diff.c\n@@ -1361,11 +1361,7 @@ static struct diffstat_file *diffstat_add(struct diffstat_t *diffstat,\n {\n \tstruct diffstat_file *x;\n \tx = xcalloc(sizeof (*x), 1);\n-\tif (diffstat->nr == diffstat->alloc) {\n-\t\tdiffstat->alloc = alloc_nr(diffstat->alloc);\n-\t\tdiffstat->files = xrealloc(diffstat->files,\n-\t\t\t\tdiffstat->alloc * sizeof(x));\n-\t}\n+\tALLOC_GROW(diffstat->files, diffstat->nr + 1, diffstat->alloc);\n \tdiffstat->files[diffstat->nr++] = x;\n \tif (name_b) {\n \t\tx->from_name = xstrdup(name_a);\n@@ -3965,11 +3961,7 @@ struct diff_queue_struct diff_queued_diff;\n \n void diff_q(struct diff_queue_struct *queue, struct diff_filepair *dp)\n {\n-\tif (queue->alloc <= queue->nr) {\n-\t\tqueue->alloc = alloc_nr(queue->alloc);\n-\t\tqueue->queue = xrealloc(queue->queue,\n-\t\t\t\t\tsizeof(dp) * queue->alloc);\n-\t}\n+\tALLOC_GROW(queue->queue, queue->nr + 1, queue->alloc);\n \tqueue->queue[queue->nr++] = dp;\n }\n \n-- \n1.8.3.2\n"},{"id":"235941","messageId":"1393885922-21616-7-git-send-email-dmitrys.dolzhenko@yandex.ru","threadId":"36043","inReplyTo":"1393885922-21616-1-git-send-email-dmitrys.dolzhenko@yandex.ru","subject":"[PATCH v4 06/14] diffcore-rename.c: use ALLOC_GROW()","fromName":"Dmitry S. Dolzhenko","fromEmail":"dmitrys.dolzhenko@yandex.ru","sentAt":"2014-03-03T22:31:54Z","receivedAt":"2014-03-03T22:31:54Z","isPatch":true,"sender":{"key":"dmitrys.dolzhenko@yandex.ru","avatar":null},"body":"Use ALLOC_GROW() instead inline code in\nlocate_rename_dst() and register_rename_src()\n\nSigned-off-by: Dmitry S. Dolzhenko <dmitrys.dolzhenko@yandex.ru>\n---\n diffcore-rename.c | 12 ++----------\n 1 file changed, 2 insertions(+), 10 deletions(-)\n\ndiff --git a/diffcore-rename.c b/diffcore-rename.c\nindex 9b4f068..fbf3272 100644\n--- a/diffcore-rename.c\n+++ b/diffcore-rename.c\n@@ -38,11 +38,7 @@ static struct diff_rename_dst *locate_rename_dst(struct diff_filespec *two,\n \tif (!insert_ok)\n \t\treturn NULL;\n \t/* insert to make it at \"first\" */\n-\tif (rename_dst_alloc <= rename_dst_nr) {\n-\t\trename_dst_alloc = alloc_nr(rename_dst_alloc);\n-\t\trename_dst = xrealloc(rename_dst,\n-\t\t\t\t      rename_dst_alloc * sizeof(*rename_dst));\n-\t}\n+\tALLOC_GROW(rename_dst, rename_dst_nr + 1, rename_dst_alloc);\n \trename_dst_nr++;\n \tif (first < rename_dst_nr)\n \t\tmemmove(rename_dst + first + 1, rename_dst + first,\n@@ -82,11 +78,7 @@ static struct diff_rename_src *register_rename_src(struct diff_filepair *p)\n \t}\n \n \t/* insert to make it at \"first\" */\n-\tif (rename_src_alloc <= rename_src_nr) {\n-\t\trename_src_alloc = alloc_nr(rename_src_alloc);\n-\t\trename_src = xrealloc(rename_src,\n-\t\t\t\t      rename_src_alloc * sizeof(*rename_src));\n-\t}\n+\tALLOC_GROW(rename_src, rename_src_nr + 1, rename_src_alloc);\n \trename_src_nr++;\n \tif (first < rename_src_nr)\n \t\tmemmove(rename_src + first + 1, rename_src + first,\n-- \n1.8.3.2\n"},{"id":"235937","messageId":"1393885922-21616-8-git-send-email-dmitrys.dolzhenko@yandex.ru","threadId":"36043","inReplyTo":"1393885922-21616-1-git-send-email-dmitrys.dolzhenko@yandex.ru","subject":"[PATCH v4 07/14] patch-ids.c: use ALLOC_GROW() in add_commit()","fromName":"Dmitry S. Dolzhenko","fromEmail":"dmitrys.dolzhenko@yandex.ru","sentAt":"2014-03-03T22:31:55Z","receivedAt":"2014-03-03T22:31:55Z","isPatch":true,"sender":{"key":"dmitrys.dolzhenko@yandex.ru","avatar":null},"body":"Signed-off-by: Dmitry S. Dolzhenko <dmitrys.dolzhenko@yandex.ru>\n---\n patch-ids.c | 5 +----\n 1 file changed, 1 insertion(+), 4 deletions(-)\n\ndiff --git a/patch-ids.c b/patch-ids.c\nindex bc8a28f..bf81b92 100644\n--- a/patch-ids.c\n+++ b/patch-ids.c\n@@ -83,10 +83,7 @@ static struct patch_id *add_commit(struct commit *commit,\n \tent = &bucket->bucket[bucket->nr++];\n \thashcpy(ent->patch_id, sha1);\n \n-\tif (ids->alloc <= ids->nr) {\n-\t\tids->alloc = alloc_nr(ids->nr);\n-\t\tids->table = xrealloc(ids->table, sizeof(ent) * ids->alloc);\n-\t}\n+\tALLOC_GROW(ids->table, ids->nr + 1, ids->alloc);\n \tif (pos < ids->nr)\n \t\tmemmove(ids->table + pos + 1, ids->table + pos,\n \t\t\tsizeof(ent) * (ids->nr - pos));\n-- \n1.8.3.2\n"},{"id":"235931","messageId":"1393885922-21616-9-git-send-email-dmitrys.dolzhenko@yandex.ru","threadId":"36043","inReplyTo":"1393885922-21616-1-git-send-email-dmitrys.dolzhenko@yandex.ru","subject":"[PATCH v4 08/14] replace_object.c: use ALLOC_GROW() in register_replace_object()","fromName":"Dmitry S. Dolzhenko","fromEmail":"dmitrys.dolzhenko@yandex.ru","sentAt":"2014-03-03T22:31:56Z","receivedAt":"2014-03-03T22:31:56Z","isPatch":true,"sender":{"key":"dmitrys.dolzhenko@yandex.ru","avatar":null},"body":"Signed-off-by: Dmitry S. Dolzhenko <dmitrys.dolzhenko@yandex.ru>\n---\n replace_object.c | 8 ++------\n 1 file changed, 2 insertions(+), 6 deletions(-)\n\ndiff --git a/replace_object.c b/replace_object.c\nindex cdcaf8c..843deef 100644\n--- a/replace_object.c\n+++ b/replace_object.c\n@@ -36,12 +36,8 @@ static int register_replace_object(struct replace_object *replace,\n \t\treturn 1;\n \t}\n \tpos = -pos - 1;\n-\tif (replace_object_alloc <= ++replace_object_nr) {\n-\t\treplace_object_alloc = alloc_nr(replace_object_alloc);\n-\t\treplace_object = xrealloc(replace_object,\n-\t\t\t\t\t  sizeof(*replace_object) *\n-\t\t\t\t\t  replace_object_alloc);\n-\t}\n+\tALLOC_GROW(replace_object, replace_object_nr + 1, replace_object_alloc);\n+\treplace_object_nr++;\n \tif (pos < replace_object_nr)\n \t\tmemmove(replace_object + pos + 1,\n \t\t\treplace_object + pos,\n-- \n1.8.3.2\n"},{"id":"235939","messageId":"1393885922-21616-10-git-send-email-dmitrys.dolzhenko@yandex.ru","threadId":"36043","inReplyTo":"1393885922-21616-1-git-send-email-dmitrys.dolzhenko@yandex.ru","subject":"[PATCH v4 09/14] reflog-walk.c: use ALLOC_GROW()","fromName":"Dmitry S. Dolzhenko","fromEmail":"dmitrys.dolzhenko@yandex.ru","sentAt":"2014-03-03T22:31:57Z","receivedAt":"2014-03-03T22:31:57Z","isPatch":true,"sender":{"key":"dmitrys.dolzhenko@yandex.ru","avatar":null},"body":"Use ALLOC_GROW() instead inline code in\nadd_commit_info() and read_one_reflog()\n\nSigned-off-by: Dmitry S. Dolzhenko <dmitrys.dolzhenko@yandex.ru>\n---\n reflog-walk.c | 12 ++----------\n 1 file changed, 2 insertions(+), 10 deletions(-)\n\ndiff --git a/reflog-walk.c b/reflog-walk.c\nindex b2fbdb2..2899729 100644\n--- a/reflog-walk.c\n+++ b/reflog-walk.c\n@@ -26,11 +26,7 @@ static int read_one_reflog(unsigned char *osha1, unsigned char *nsha1,\n \tstruct complete_reflogs *array = cb_data;\n \tstruct reflog_info *item;\n \n-\tif (array->nr >= array->alloc) {\n-\t\tarray->alloc = alloc_nr(array->nr + 1);\n-\t\tarray->items = xrealloc(array->items, array->alloc *\n-\t\t\tsizeof(struct reflog_info));\n-\t}\n+\tALLOC_GROW(array->items, array->nr + 1, array->alloc);\n \titem = array->items + array->nr;\n \tmemcpy(item->osha1, osha1, 20);\n \tmemcpy(item->nsha1, nsha1, 20);\n@@ -114,11 +110,7 @@ static void add_commit_info(struct commit *commit, void *util,\n \t\tstruct commit_info_lifo *lifo)\n {\n \tstruct commit_info *info;\n-\tif (lifo->nr >= lifo->alloc) {\n-\t\tlifo->alloc = alloc_nr(lifo->nr + 1);\n-\t\tlifo->items = xrealloc(lifo->items,\n-\t\t\tlifo->alloc * sizeof(struct commit_info));\n-\t}\n+\tALLOC_GROW(lifo->items, lifo->nr + 1, lifo->alloc);\n \tinfo = lifo->items + lifo->nr;\n \tinfo->commit = commit;\n \tinfo->util = util;\n-- \n1.8.3.2\n"},{"id":"235934","messageId":"1393885922-21616-11-git-send-email-dmitrys.dolzhenko@yandex.ru","threadId":"36043","inReplyTo":"1393885922-21616-1-git-send-email-dmitrys.dolzhenko@yandex.ru","subject":"[PATCH v4 10/14] dir.c: use ALLOC_GROW() in create_simplify()","fromName":"Dmitry S. Dolzhenko","fromEmail":"dmitrys.dolzhenko@yandex.ru","sentAt":"2014-03-03T22:31:58Z","receivedAt":"2014-03-03T22:31:58Z","isPatch":true,"sender":{"key":"dmitrys.dolzhenko@yandex.ru","avatar":null},"body":"Signed-off-by: Dmitry S. Dolzhenko <dmitrys.dolzhenko@yandex.ru>\n---\n dir.c | 5 +----\n 1 file changed, 1 insertion(+), 4 deletions(-)\n\ndiff --git a/dir.c b/dir.c\nindex 98bb50f..4ae38e4 100644\n--- a/dir.c\n+++ b/dir.c\n@@ -1341,10 +1341,7 @@ static struct path_simplify *create_simplify(const char **pathspec)\n \n \tfor (nr = 0 ; ; nr++) {\n \t\tconst char *match;\n-\t\tif (nr >= alloc) {\n-\t\t\talloc = alloc_nr(alloc);\n-\t\t\tsimplify = xrealloc(simplify, alloc * sizeof(*simplify));\n-\t\t}\n+\t\tALLOC_GROW(simplify, nr + 1, alloc);\n \t\tmatch = *pathspec++;\n \t\tif (!match)\n \t\t\tbreak;\n-- \n1.8.3.2\n"},{"id":"235935","messageId":"1393885922-21616-12-git-send-email-dmitrys.dolzhenko@yandex.ru","threadId":"36043","inReplyTo":"1393885922-21616-1-git-send-email-dmitrys.dolzhenko@yandex.ru","subject":"[PATCH v4 11/14] attr.c: use ALLOC_GROW() in handle_attr_line()","fromName":"Dmitry S. Dolzhenko","fromEmail":"dmitrys.dolzhenko@yandex.ru","sentAt":"2014-03-03T22:31:59Z","receivedAt":"2014-03-03T22:31:59Z","isPatch":true,"sender":{"key":"dmitrys.dolzhenko@yandex.ru","avatar":null},"body":"Signed-off-by: Dmitry S. Dolzhenko <dmitrys.dolzhenko@yandex.ru>\n---\n attr.c | 7 +------\n 1 file changed, 1 insertion(+), 6 deletions(-)\n\ndiff --git a/attr.c b/attr.c\nindex 8d13d70..734222d 100644\n--- a/attr.c\n+++ b/attr.c\n@@ -338,12 +338,7 @@ static void handle_attr_line(struct attr_stack *res,\n \ta = parse_attr_line(line, src, lineno, macro_ok);\n \tif (!a)\n \t\treturn;\n-\tif (res->alloc <= res->num_matches) {\n-\t\tres->alloc = alloc_nr(res->num_matches);\n-\t\tres->attrs = xrealloc(res->attrs,\n-\t\t\t\t      sizeof(struct match_attr *) *\n-\t\t\t\t      res->alloc);\n-\t}\n+\tALLOC_GROW(res->attrs, res->num_matches + 1, res->alloc);\n \tres->attrs[res->num_matches++] = a;\n }\n \n-- \n1.8.3.2\n"},{"id":"235932","messageId":"1393885922-21616-13-git-send-email-dmitrys.dolzhenko@yandex.ru","threadId":"36043","inReplyTo":"1393885922-21616-1-git-send-email-dmitrys.dolzhenko@yandex.ru","subject":"[PATCH v4 12/14] builtin/mktree.c: use ALLOC_GROW() in append_to_tree()","fromName":"Dmitry S. Dolzhenko","fromEmail":"dmitrys.dolzhenko@yandex.ru","sentAt":"2014-03-03T22:32:00Z","receivedAt":"2014-03-03T22:32:00Z","isPatch":true,"sender":{"key":"dmitrys.dolzhenko@yandex.ru","avatar":null},"body":"Helped-by: He Sun <sunheehnus@gmail.com>\nSigned-off-by: Dmitry S. Dolzhenko <dmitrys.dolzhenko@yandex.ru>\n---\n builtin/mktree.c | 5 +----\n 1 file changed, 1 insertion(+), 4 deletions(-)\n\ndiff --git a/builtin/mktree.c b/builtin/mktree.c\nindex f92ba40..a964d6b 100644\n--- a/builtin/mktree.c\n+++ b/builtin/mktree.c\n@@ -23,10 +23,7 @@ static void append_to_tree(unsigned mode, unsigned char *sha1, char *path)\n \tif (strchr(path, '/'))\n \t\tdie(\"path %s contains slash\", path);\n \n-\tif (alloc <= used) {\n-\t\talloc = alloc_nr(used);\n-\t\tentries = xrealloc(entries, sizeof(*entries) * alloc);\n-\t}\n+\tALLOC_GROW(entries, used + 1, alloc);\n \tent = entries[used++] = xmalloc(sizeof(**entries) + len + 1);\n \tent->mode = mode;\n \tent->len = len;\n-- \n1.8.3.2\n"},{"id":"235936","messageId":"1393885922-21616-14-git-send-email-dmitrys.dolzhenko@yandex.ru","threadId":"36043","inReplyTo":"1393885922-21616-1-git-send-email-dmitrys.dolzhenko@yandex.ru","subject":"[PATCH v4 13/14] read-cache.c: use ALLOC_GROW() in add_index_entry()","fromName":"Dmitry S. Dolzhenko","fromEmail":"dmitrys.dolzhenko@yandex.ru","sentAt":"2014-03-03T22:32:01Z","receivedAt":"2014-03-03T22:32:01Z","isPatch":true,"sender":{"key":"dmitrys.dolzhenko@yandex.ru","avatar":null},"body":"Signed-off-by: Dmitry S. Dolzhenko <dmitrys.dolzhenko@yandex.ru>\n---\n read-cache.c | 6 +-----\n 1 file changed, 1 insertion(+), 5 deletions(-)\n\ndiff --git a/read-cache.c b/read-cache.c\nindex fb440b4..cbdf954 100644\n--- a/read-cache.c\n+++ b/read-cache.c\n@@ -990,11 +990,7 @@ int add_index_entry(struct index_state *istate, struct cache_entry *ce, int opti\n \t}\n \n \t/* Make sure the array is big enough .. */\n-\tif (istate->cache_nr == istate->cache_alloc) {\n-\t\tistate->cache_alloc = alloc_nr(istate->cache_alloc);\n-\t\tistate->cache = xrealloc(istate->cache,\n-\t\t\t\t\tistate->cache_alloc * sizeof(*istate->cache));\n-\t}\n+\tALLOC_GROW(istate->cache, istate->cache_nr + 1, istate->cache_alloc);\n \n \t/* Add it in.. */\n \tistate->cache_nr++;\n-- \n1.8.3.2\n"},{"id":"235933","messageId":"1393885922-21616-15-git-send-email-dmitrys.dolzhenko@yandex.ru","threadId":"36043","inReplyTo":"1393885922-21616-1-git-send-email-dmitrys.dolzhenko@yandex.ru","subject":"[PATCH v4 14/14] sha1_file.c: use ALLOC_GROW() in pretend_sha1_file()","fromName":"Dmitry S. Dolzhenko","fromEmail":"dmitrys.dolzhenko@yandex.ru","sentAt":"2014-03-03T22:32:02Z","receivedAt":"2014-03-03T22:32:02Z","isPatch":true,"sender":{"key":"dmitrys.dolzhenko@yandex.ru","avatar":null},"body":"Helped-by: He Sun <sunheehnus@gmail.com>\nSigned-off-by: Dmitry S. Dolzhenko <dmitrys.dolzhenko@yandex.ru>\n---\n sha1_file.c | 7 +------\n 1 file changed, 1 insertion(+), 6 deletions(-)\n\ndiff --git a/sha1_file.c b/sha1_file.c\nindex 019628a..3cb17b8 100644\n--- a/sha1_file.c\n+++ b/sha1_file.c\n@@ -2624,12 +2624,7 @@ int pretend_sha1_file(void *buf, unsigned long len, enum object_type type,\n \thash_sha1_file(buf, len, typename(type), sha1);\n \tif (has_sha1_file(sha1) || find_cached_object(sha1))\n \t\treturn 0;\n-\tif (cached_object_alloc <= cached_object_nr) {\n-\t\tcached_object_alloc = alloc_nr(cached_object_alloc);\n-\t\tcached_objects = xrealloc(cached_objects,\n-\t\t\t\t\t  sizeof(*cached_objects) *\n-\t\t\t\t\t  cached_object_alloc);\n-\t}\n+\tALLOC_GROW(cached_objects, cached_object_nr + 1, cached_object_alloc);\n \tco = &cached_objects[cached_object_nr++];\n \tco->size = len;\n \tco->type = type;\n-- \n1.8.3.2\n"},{"id":"235946","messageId":"xmqq1tyioq4e.fsf@gitster.dls.corp.google.com","threadId":"36043","inReplyTo":"1393885922-21616-6-git-send-email-dmitrys.dolzhenko@yandex.ru","subject":"Re: [PATCH v4 05/14] diff.c: use ALLOC_GROW()","fromName":"Junio C Hamano","fromEmail":"gitster@pobox.com","sentAt":"2014-03-03T22:48:33Z","receivedAt":"2014-03-03T22:48:33Z","isPatch":true,"sender":{"key":"gitster@pobox.com","avatar":"https://avatars.githubusercontent.com/u/54884?v=4"},"body":"\"Dmitry S. Dolzhenko\" <dmitrys.dolzhenko@yandex.ru> writes:\n\n> Use ALLOC_GROW() instead inline code in\n> diffstat_add() and diff_q()\n\n\"...instead of open coding it in...\" may read better.\n\n>\n> Signed-off-by: Dmitry S. Dolzhenko <dmitrys.dolzhenko@yandex.ru>\n> ---\n>  diff.c | 12 ++----------\n>  1 file changed, 2 insertions(+), 10 deletions(-)\n>\n> diff --git a/diff.c b/diff.c\n> index e800666..aebdfda 100644\n> --- a/diff.c\n> +++ b/diff.c\n> @@ -1361,11 +1361,7 @@ static struct diffstat_file *diffstat_add(struct diffstat_t *diffstat,\n>  {\n>  \tstruct diffstat_file *x;\n>  \tx = xcalloc(sizeof (*x), 1);\n> -\tif (diffstat->nr == diffstat->alloc) {\n> -\t\tdiffstat->alloc = alloc_nr(diffstat->alloc);\n> -\t\tdiffstat->files = xrealloc(diffstat->files,\n> -\t\t\t\tdiffstat->alloc * sizeof(x));\n> -\t}\n> +\tALLOC_GROW(diffstat->files, diffstat->nr + 1, diffstat->alloc);\n>  \tdiffstat->files[diffstat->nr++] = x;\n>  \tif (name_b) {\n>  \t\tx->from_name = xstrdup(name_a);\n> @@ -3965,11 +3961,7 @@ struct diff_queue_struct diff_queued_diff;\n>  \n>  void diff_q(struct diff_queue_struct *queue, struct diff_filepair *dp)\n>  {\n> -\tif (queue->alloc <= queue->nr) {\n> -\t\tqueue->alloc = alloc_nr(queue->alloc);\n> -\t\tqueue->queue = xrealloc(queue->queue,\n> -\t\t\t\t\tsizeof(dp) * queue->alloc);\n> -\t}\n> +\tALLOC_GROW(queue->queue, queue->nr + 1, queue->alloc);\n>  \tqueue->queue[queue->nr++] = dp;\n>  }\n"},{"id":"235950","messageId":"xmqqwqganavy.fsf@gitster.dls.corp.google.com","threadId":"36043","inReplyTo":"1393885922-21616-1-git-send-email-dmitrys.dolzhenko@yandex.ru","subject":"Re: [PATCH v4 00/14] Use ALLOC_GROW() instead of inline code","fromName":"Junio C Hamano","fromEmail":"gitster@pobox.com","sentAt":"2014-03-03T23:02:57Z","receivedAt":"2014-03-03T23:02:57Z","isPatch":true,"sender":{"key":"gitster@pobox.com","avatar":"https://avatars.githubusercontent.com/u/54884?v=4"},"body":"> Dmitry S. Dolzhenko (14):\n>   builtin/pack-objects.c: use ALLOC_GROW() in check_pbase_path()\n>   bundle.c: use ALLOC_GROW() in add_to_ref_list()\n>   cache-tree.c: use ALLOC_GROW() in find_subtree()\n>   commit.c: use ALLOC_GROW() in register_commit_graft()\n>   diff.c: use ALLOC_GROW()\n>   diffcore-rename.c: use ALLOC_GROW()\n>   patch-ids.c: use ALLOC_GROW() in add_commit()\n>   replace_object.c: use ALLOC_GROW() in register_replace_object()\n>   reflog-walk.c: use ALLOC_GROW()\n>   dir.c: use ALLOC_GROW() in create_simplify()\n>   attr.c: use ALLOC_GROW() in handle_attr_line()\n>   builtin/mktree.c: use ALLOC_GROW() in append_to_tree()\n>   read-cache.c: use ALLOC_GROW() in add_index_entry()\n>   sha1_file.c: use ALLOC_GROW() in pretend_sha1_file()\n\nAll looked cleanly done.\n\nThe resulting code of 1, 3, 4, 6 and 8 share this pattern:\n\n\tALLOC_GROW(table, number + 1, alloc);\n        number++;\n\nwhich may be easier to understand if done the other way around:\n\n        number++;\n\tALLOC_GROW(table, number, alloc);\n\nThat is, \"we know we want one more, so make sure they fit in the\ntable\".\n\nBut that is just a minor issue; I suspect many existing callsites to\nALLOC_GROW() already follow the former pattern, and if we decide to\nto switch the former to the latter, we shouldn't be doing so within\nthis series (we should do that as a separate series on top of this).\n\nThanks; will queue.\n"}]}