Merge branch 'dd/use-alloc-grow'
Replace open-coded reallocation with ALLOC_GROW() macro. * dd/use-alloc-grow: sha1_file.c: use ALLOC_GROW() in pretend_sha1_file() read-cache.c: use ALLOC_GROW() in add_index_entry() builtin/mktree.c: use ALLOC_GROW() in append_to_tree() attr.c: use ALLOC_GROW() in handle_attr_line() dir.c: use ALLOC_GROW() in create_simplify() reflog-walk.c: use ALLOC_GROW() replace_object.c: use ALLOC_GROW() in register_replace_object() patch-ids.c: use ALLOC_GROW() in add_commit() diffcore-rename.c: use ALLOC_GROW() diff.c: use ALLOC_GROW() commit.c: use ALLOC_GROW() in register_commit_graft() cache-tree.c: use ALLOC_GROW() in find_subtree() bundle.c: use ALLOC_GROW() in add_to_ref_list() builtin/pack-objects.c: use ALLOC_GROW() in check_pbase_path()
This commit is contained in:
commit
fe9122a352
7
attr.c
7
attr.c
@ -338,12 +338,7 @@ static void handle_attr_line(struct attr_stack *res,
|
|||||||
a = parse_attr_line(line, src, lineno, macro_ok);
|
a = parse_attr_line(line, src, lineno, macro_ok);
|
||||||
if (!a)
|
if (!a)
|
||||||
return;
|
return;
|
||||||
if (res->alloc <= res->num_matches) {
|
ALLOC_GROW(res->attrs, res->num_matches + 1, res->alloc);
|
||||||
res->alloc = alloc_nr(res->num_matches);
|
|
||||||
res->attrs = xrealloc(res->attrs,
|
|
||||||
sizeof(struct match_attr *) *
|
|
||||||
res->alloc);
|
|
||||||
}
|
|
||||||
res->attrs[res->num_matches++] = a;
|
res->attrs[res->num_matches++] = a;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -23,10 +23,7 @@ static void append_to_tree(unsigned mode, unsigned char *sha1, char *path)
|
|||||||
if (strchr(path, '/'))
|
if (strchr(path, '/'))
|
||||||
die("path %s contains slash", path);
|
die("path %s contains slash", path);
|
||||||
|
|
||||||
if (alloc <= used) {
|
ALLOC_GROW(entries, used + 1, alloc);
|
||||||
alloc = alloc_nr(used);
|
|
||||||
entries = xrealloc(entries, sizeof(*entries) * alloc);
|
|
||||||
}
|
|
||||||
ent = entries[used++] = xmalloc(sizeof(**entries) + len + 1);
|
ent = entries[used++] = xmalloc(sizeof(**entries) + len + 1);
|
||||||
ent->mode = mode;
|
ent->mode = mode;
|
||||||
ent->len = len;
|
ent->len = len;
|
||||||
|
@ -1213,12 +1213,9 @@ static int check_pbase_path(unsigned hash)
|
|||||||
if (0 <= pos)
|
if (0 <= pos)
|
||||||
return 1;
|
return 1;
|
||||||
pos = -pos - 1;
|
pos = -pos - 1;
|
||||||
if (done_pbase_paths_alloc <= done_pbase_paths_num) {
|
ALLOC_GROW(done_pbase_paths,
|
||||||
done_pbase_paths_alloc = alloc_nr(done_pbase_paths_alloc);
|
done_pbase_paths_num + 1,
|
||||||
done_pbase_paths = xrealloc(done_pbase_paths,
|
done_pbase_paths_alloc);
|
||||||
done_pbase_paths_alloc *
|
|
||||||
sizeof(unsigned));
|
|
||||||
}
|
|
||||||
done_pbase_paths_num++;
|
done_pbase_paths_num++;
|
||||||
if (pos < done_pbase_paths_num)
|
if (pos < done_pbase_paths_num)
|
||||||
memmove(done_pbase_paths + pos + 1,
|
memmove(done_pbase_paths + pos + 1,
|
||||||
|
6
bundle.c
6
bundle.c
@ -14,11 +14,7 @@ static const char bundle_signature[] = "# v2 git bundle\n";
|
|||||||
static void add_to_ref_list(const unsigned char *sha1, const char *name,
|
static void add_to_ref_list(const unsigned char *sha1, const char *name,
|
||||||
struct ref_list *list)
|
struct ref_list *list)
|
||||||
{
|
{
|
||||||
if (list->nr + 1 >= list->alloc) {
|
ALLOC_GROW(list->list, list->nr + 1, list->alloc);
|
||||||
list->alloc = alloc_nr(list->nr + 1);
|
|
||||||
list->list = xrealloc(list->list,
|
|
||||||
list->alloc * sizeof(list->list[0]));
|
|
||||||
}
|
|
||||||
memcpy(list->list[list->nr].sha1, sha1, 20);
|
memcpy(list->list[list->nr].sha1, sha1, 20);
|
||||||
list->list[list->nr].name = xstrdup(name);
|
list->list[list->nr].name = xstrdup(name);
|
||||||
list->nr++;
|
list->nr++;
|
||||||
|
@ -75,11 +75,7 @@ static struct cache_tree_sub *find_subtree(struct cache_tree *it,
|
|||||||
return NULL;
|
return NULL;
|
||||||
|
|
||||||
pos = -pos-1;
|
pos = -pos-1;
|
||||||
if (it->subtree_alloc <= it->subtree_nr) {
|
ALLOC_GROW(it->down, it->subtree_nr + 1, it->subtree_alloc);
|
||||||
it->subtree_alloc = alloc_nr(it->subtree_alloc);
|
|
||||||
it->down = xrealloc(it->down, it->subtree_alloc *
|
|
||||||
sizeof(*it->down));
|
|
||||||
}
|
|
||||||
it->subtree_nr++;
|
it->subtree_nr++;
|
||||||
|
|
||||||
down = xmalloc(sizeof(*down) + pathlen + 1);
|
down = xmalloc(sizeof(*down) + pathlen + 1);
|
||||||
|
8
commit.c
8
commit.c
@ -141,12 +141,8 @@ int register_commit_graft(struct commit_graft *graft, int ignore_dups)
|
|||||||
return 1;
|
return 1;
|
||||||
}
|
}
|
||||||
pos = -pos - 1;
|
pos = -pos - 1;
|
||||||
if (commit_graft_alloc <= ++commit_graft_nr) {
|
ALLOC_GROW(commit_graft, commit_graft_nr + 1, commit_graft_alloc);
|
||||||
commit_graft_alloc = alloc_nr(commit_graft_alloc);
|
commit_graft_nr++;
|
||||||
commit_graft = xrealloc(commit_graft,
|
|
||||||
sizeof(*commit_graft) *
|
|
||||||
commit_graft_alloc);
|
|
||||||
}
|
|
||||||
if (pos < commit_graft_nr)
|
if (pos < commit_graft_nr)
|
||||||
memmove(commit_graft + pos + 1,
|
memmove(commit_graft + pos + 1,
|
||||||
commit_graft + pos,
|
commit_graft + pos,
|
||||||
|
12
diff.c
12
diff.c
@ -1361,11 +1361,7 @@ static struct diffstat_file *diffstat_add(struct diffstat_t *diffstat,
|
|||||||
{
|
{
|
||||||
struct diffstat_file *x;
|
struct diffstat_file *x;
|
||||||
x = xcalloc(sizeof (*x), 1);
|
x = xcalloc(sizeof (*x), 1);
|
||||||
if (diffstat->nr == diffstat->alloc) {
|
ALLOC_GROW(diffstat->files, diffstat->nr + 1, diffstat->alloc);
|
||||||
diffstat->alloc = alloc_nr(diffstat->alloc);
|
|
||||||
diffstat->files = xrealloc(diffstat->files,
|
|
||||||
diffstat->alloc * sizeof(x));
|
|
||||||
}
|
|
||||||
diffstat->files[diffstat->nr++] = x;
|
diffstat->files[diffstat->nr++] = x;
|
||||||
if (name_b) {
|
if (name_b) {
|
||||||
x->from_name = xstrdup(name_a);
|
x->from_name = xstrdup(name_a);
|
||||||
@ -3958,11 +3954,7 @@ struct diff_queue_struct diff_queued_diff;
|
|||||||
|
|
||||||
void diff_q(struct diff_queue_struct *queue, struct diff_filepair *dp)
|
void diff_q(struct diff_queue_struct *queue, struct diff_filepair *dp)
|
||||||
{
|
{
|
||||||
if (queue->alloc <= queue->nr) {
|
ALLOC_GROW(queue->queue, queue->nr + 1, queue->alloc);
|
||||||
queue->alloc = alloc_nr(queue->alloc);
|
|
||||||
queue->queue = xrealloc(queue->queue,
|
|
||||||
sizeof(dp) * queue->alloc);
|
|
||||||
}
|
|
||||||
queue->queue[queue->nr++] = dp;
|
queue->queue[queue->nr++] = dp;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -38,11 +38,7 @@ static struct diff_rename_dst *locate_rename_dst(struct diff_filespec *two,
|
|||||||
if (!insert_ok)
|
if (!insert_ok)
|
||||||
return NULL;
|
return NULL;
|
||||||
/* insert to make it at "first" */
|
/* insert to make it at "first" */
|
||||||
if (rename_dst_alloc <= rename_dst_nr) {
|
ALLOC_GROW(rename_dst, rename_dst_nr + 1, rename_dst_alloc);
|
||||||
rename_dst_alloc = alloc_nr(rename_dst_alloc);
|
|
||||||
rename_dst = xrealloc(rename_dst,
|
|
||||||
rename_dst_alloc * sizeof(*rename_dst));
|
|
||||||
}
|
|
||||||
rename_dst_nr++;
|
rename_dst_nr++;
|
||||||
if (first < rename_dst_nr)
|
if (first < rename_dst_nr)
|
||||||
memmove(rename_dst + first + 1, rename_dst + first,
|
memmove(rename_dst + first + 1, rename_dst + first,
|
||||||
@ -82,11 +78,7 @@ static struct diff_rename_src *register_rename_src(struct diff_filepair *p)
|
|||||||
}
|
}
|
||||||
|
|
||||||
/* insert to make it at "first" */
|
/* insert to make it at "first" */
|
||||||
if (rename_src_alloc <= rename_src_nr) {
|
ALLOC_GROW(rename_src, rename_src_nr + 1, rename_src_alloc);
|
||||||
rename_src_alloc = alloc_nr(rename_src_alloc);
|
|
||||||
rename_src = xrealloc(rename_src,
|
|
||||||
rename_src_alloc * sizeof(*rename_src));
|
|
||||||
}
|
|
||||||
rename_src_nr++;
|
rename_src_nr++;
|
||||||
if (first < rename_src_nr)
|
if (first < rename_src_nr)
|
||||||
memmove(rename_src + first + 1, rename_src + first,
|
memmove(rename_src + first + 1, rename_src + first,
|
||||||
|
5
dir.c
5
dir.c
@ -1364,10 +1364,7 @@ static struct path_simplify *create_simplify(const char **pathspec)
|
|||||||
|
|
||||||
for (nr = 0 ; ; nr++) {
|
for (nr = 0 ; ; nr++) {
|
||||||
const char *match;
|
const char *match;
|
||||||
if (nr >= alloc) {
|
ALLOC_GROW(simplify, nr + 1, alloc);
|
||||||
alloc = alloc_nr(alloc);
|
|
||||||
simplify = xrealloc(simplify, alloc * sizeof(*simplify));
|
|
||||||
}
|
|
||||||
match = *pathspec++;
|
match = *pathspec++;
|
||||||
if (!match)
|
if (!match)
|
||||||
break;
|
break;
|
||||||
|
@ -83,10 +83,7 @@ static struct patch_id *add_commit(struct commit *commit,
|
|||||||
ent = &bucket->bucket[bucket->nr++];
|
ent = &bucket->bucket[bucket->nr++];
|
||||||
hashcpy(ent->patch_id, sha1);
|
hashcpy(ent->patch_id, sha1);
|
||||||
|
|
||||||
if (ids->alloc <= ids->nr) {
|
ALLOC_GROW(ids->table, ids->nr + 1, ids->alloc);
|
||||||
ids->alloc = alloc_nr(ids->nr);
|
|
||||||
ids->table = xrealloc(ids->table, sizeof(ent) * ids->alloc);
|
|
||||||
}
|
|
||||||
if (pos < ids->nr)
|
if (pos < ids->nr)
|
||||||
memmove(ids->table + pos + 1, ids->table + pos,
|
memmove(ids->table + pos + 1, ids->table + pos,
|
||||||
sizeof(ent) * (ids->nr - pos));
|
sizeof(ent) * (ids->nr - pos));
|
||||||
|
@ -990,11 +990,7 @@ int add_index_entry(struct index_state *istate, struct cache_entry *ce, int opti
|
|||||||
}
|
}
|
||||||
|
|
||||||
/* Make sure the array is big enough .. */
|
/* Make sure the array is big enough .. */
|
||||||
if (istate->cache_nr == istate->cache_alloc) {
|
ALLOC_GROW(istate->cache, istate->cache_nr + 1, istate->cache_alloc);
|
||||||
istate->cache_alloc = alloc_nr(istate->cache_alloc);
|
|
||||||
istate->cache = xrealloc(istate->cache,
|
|
||||||
istate->cache_alloc * sizeof(*istate->cache));
|
|
||||||
}
|
|
||||||
|
|
||||||
/* Add it in.. */
|
/* Add it in.. */
|
||||||
istate->cache_nr++;
|
istate->cache_nr++;
|
||||||
|
@ -26,11 +26,7 @@ static int read_one_reflog(unsigned char *osha1, unsigned char *nsha1,
|
|||||||
struct complete_reflogs *array = cb_data;
|
struct complete_reflogs *array = cb_data;
|
||||||
struct reflog_info *item;
|
struct reflog_info *item;
|
||||||
|
|
||||||
if (array->nr >= array->alloc) {
|
ALLOC_GROW(array->items, array->nr + 1, array->alloc);
|
||||||
array->alloc = alloc_nr(array->nr + 1);
|
|
||||||
array->items = xrealloc(array->items, array->alloc *
|
|
||||||
sizeof(struct reflog_info));
|
|
||||||
}
|
|
||||||
item = array->items + array->nr;
|
item = array->items + array->nr;
|
||||||
memcpy(item->osha1, osha1, 20);
|
memcpy(item->osha1, osha1, 20);
|
||||||
memcpy(item->nsha1, nsha1, 20);
|
memcpy(item->nsha1, nsha1, 20);
|
||||||
@ -114,11 +110,7 @@ static void add_commit_info(struct commit *commit, void *util,
|
|||||||
struct commit_info_lifo *lifo)
|
struct commit_info_lifo *lifo)
|
||||||
{
|
{
|
||||||
struct commit_info *info;
|
struct commit_info *info;
|
||||||
if (lifo->nr >= lifo->alloc) {
|
ALLOC_GROW(lifo->items, lifo->nr + 1, lifo->alloc);
|
||||||
lifo->alloc = alloc_nr(lifo->nr + 1);
|
|
||||||
lifo->items = xrealloc(lifo->items,
|
|
||||||
lifo->alloc * sizeof(struct commit_info));
|
|
||||||
}
|
|
||||||
info = lifo->items + lifo->nr;
|
info = lifo->items + lifo->nr;
|
||||||
info->commit = commit;
|
info->commit = commit;
|
||||||
info->util = util;
|
info->util = util;
|
||||||
|
@ -41,12 +41,8 @@ static int register_replace_object(struct replace_object *replace,
|
|||||||
return 1;
|
return 1;
|
||||||
}
|
}
|
||||||
pos = -pos - 1;
|
pos = -pos - 1;
|
||||||
if (replace_object_alloc <= ++replace_object_nr) {
|
ALLOC_GROW(replace_object, replace_object_nr + 1, replace_object_alloc);
|
||||||
replace_object_alloc = alloc_nr(replace_object_alloc);
|
replace_object_nr++;
|
||||||
replace_object = xrealloc(replace_object,
|
|
||||||
sizeof(*replace_object) *
|
|
||||||
replace_object_alloc);
|
|
||||||
}
|
|
||||||
if (pos < replace_object_nr)
|
if (pos < replace_object_nr)
|
||||||
memmove(replace_object + pos + 1,
|
memmove(replace_object + pos + 1,
|
||||||
replace_object + pos,
|
replace_object + pos,
|
||||||
|
@ -2635,12 +2635,7 @@ int pretend_sha1_file(void *buf, unsigned long len, enum object_type type,
|
|||||||
hash_sha1_file(buf, len, typename(type), sha1);
|
hash_sha1_file(buf, len, typename(type), sha1);
|
||||||
if (has_sha1_file(sha1) || find_cached_object(sha1))
|
if (has_sha1_file(sha1) || find_cached_object(sha1))
|
||||||
return 0;
|
return 0;
|
||||||
if (cached_object_alloc <= cached_object_nr) {
|
ALLOC_GROW(cached_objects, cached_object_nr + 1, cached_object_alloc);
|
||||||
cached_object_alloc = alloc_nr(cached_object_alloc);
|
|
||||||
cached_objects = xrealloc(cached_objects,
|
|
||||||
sizeof(*cached_objects) *
|
|
||||||
cached_object_alloc);
|
|
||||||
}
|
|
||||||
co = &cached_objects[cached_object_nr++];
|
co = &cached_objects[cached_object_nr++];
|
||||||
co->size = len;
|
co->size = len;
|
||||||
co->type = type;
|
co->type = type;
|
||||||
|
Loading…
x
Reference in New Issue
Block a user