@matheusbsbs / matheus-bagliano / commits / 81a9aa60a1
Fork 0

create_directories(): remove some memcpy() and strchr() calls

Remove the call to memcpy() and strchr() for each path component tested, and instead add each path component as we go forward inside the while-loop. Impact: small optimisation Signed-off-by: Kjetil Barvik <barvik@broadpark.no> Signed-off-by: Junio C Hamano <gitster@pobox.com>

Kjetil Barvik committed Feb 9, 2009 at 21:54 UTC 81a9aa60a193f1181149b69920930e15c4e34059
1 file changed +14 -9
entry.c
+14 -9
@@ -2,15 +2,19 @@
2 #include "blob.h"
3 #include "dir.h"
4
5 -static void create_directories(const char *path, const struct checkout *state)
5 +static void create_directories(const char *path, int path_len,
6 + const struct checkout *state)
7 {
7 - int len = strlen(path);
8 - char *buf = xmalloc(len + 1);
9 - const char *slash = path;
10 -
11 - while ((slash = strchr(slash+1, '/')) != NULL) {
12 - len = slash - path;
13 - memcpy(buf, path, len);
8 + char *buf = xmalloc(path_len + 1);
9 + int len = 0;
10 +
11 + while (len < path_len) {
12 + do {
13 + buf[len] = path[len];
14 + len++;
15 + } while (len < path_len && path[len] != '/');
16 + if (len >= path_len)
17 + break;
18 buf[len] = 0;
19
20 /*
@@ -190,6 +194,7 @@ int checkout_entry(struct cache_entry *ce, const struct checkout *state, char *t
194
195 memcpy(path, state->base_dir, len);
196 strcpy(path + len, ce->name);
197 + len += ce_namelen(ce);
198
199 if (!lstat(path, &st)) {
200 unsigned changed = ce_match_stat(ce, &st, CE_MATCH_IGNORE_VALID);
@@ -218,6 +223,6 @@ int checkout_entry(struct cache_entry *ce, const struct checkout *state, char *t
223 return error("unable to unlink old '%s' (%s)", path, strerror(errno));
224 } else if (state->not_new)
225 return 0;
221 - create_directories(path, state);
226 + create_directories(path, len, state);
227 return write_entry(ce, path, state, 0);
228 }