Thread (5 messages) flat view 5 messages, 2 authors, 2016-06-15
DORMANTno replies

[PATCH v2] builtin/rm.c: Use ALLOC_GROW instead of alloc_nr and xrealloc.

From: Thiago Farina <hidden>
Date: 2016-06-15 22:50:16
Subsystem: the rest · Maintainer: Linus Torvalds

Signed-off-by: Thiago Farina <redacted>
---
 Changes from v1:
 - Remove the add_list function since it's used only once per Nguyen Thai Ngoc Duy
   review.

 builtin/rm.c |   12 ++----------
 1 files changed, 2 insertions(+), 10 deletions(-)
diff --git a/builtin/rm.c b/builtin/rm.c
index c7b7bb3..ff491d7 100644
--- a/builtin/rm.c
+++ b/builtin/rm.c
@@ -20,15 +20,6 @@ static struct {
 	const char **name;
 } list;
 
-static void add_list(const char *name)
-{
-	if (list.nr >= list.alloc) {
-		list.alloc = alloc_nr(list.alloc);
-		list.name = xrealloc(list.name, list.alloc * sizeof(const char *));
-	}
-	list.name[list.nr++] = name;
-}
-
 static int check_local_mod(unsigned char *head, int index_only)
 {
 	/*
@@ -182,7 +173,8 @@ int cmd_rm(int argc, const char **argv, const char *prefix)
 		struct cache_entry *ce = active_cache[i];
 		if (!match_pathspec(pathspec, ce->name, ce_namelen(ce), 0, seen))
 			continue;
-		add_list(ce->name);
+		ALLOC_GROW(list.name, list.nr + 1, list.alloc);
+		list.name[list.nr++] = ce->name;
 	}
 
 	if (pathspec) {
-- 
1.7.3.2.343.g7d43d
Keyboard shortcuts
hback out one level
jnext message in thread
kprevious message in thread
ldrill in
Escclose help / fold thread tree
?toggle this help