Skip to contentSkip to conversation

diff-lib.c: don't strdup twice

PATCH In review René Scharfe 2 participants 2 messages Jun 15, 2016

lore
Share & tools
lore
#0 lore raw

PATCH 1/1 diff-lib.c: don't strdup twice

The static function read_directory in diff-lib.c is only ever called with struct path_list lists with .strdup_paths turned on, i.e. path_list_insert will strdup the paths for us (again). Let's take advantage of that and stop doing it twice.

---

 diff-lib.c |    2 +-
 1 files changed, 1 insertions(+), 1 deletions(-)
diff-lib.c +1 -1
index 7fb19c7..92c0e39 100644
@@ -24,7 +24,7 @@ static int read_directory(const char *path, struct path_list *list)
 
 	while ((e = readdir(dir)))
 		if (strcmp(".", e->d_name) && strcmp("..", e->d_name))
-			path_list_insert(xstrdup(e->d_name), list);
+			path_list_insert(e->d_name, list);
 
 	closedir(dir);
 	return 0;
Acked-by on v1 1/1
#1 lore raw

Hi,

Quoted 4 lines · Ren? Scharfe

The static function read_directory in diff-lib.c is only ever called with struct path_list lists with .strdup_paths turned on, i.e. path_list_insert will strdup the paths for us (again). Let's take advantage of that and stop doing it twice.

Indeed.

Thanks,
Dscho