summaryrefslogtreecommitdiff
path: root/entry.c
diff options
context:
space:
mode:
authorKjetil Barvik <barvik@broadpark.no>2009-02-09 20:54:08 (GMT)
committerJunio C Hamano <gitster@pobox.com>2009-02-10 04:59:26 (GMT)
commit81a9aa60a193f1181149b69920930e15c4e34059 (patch)
tree83183cf31fd679bb13635ea056260d79c99edf12 /entry.c
parent7847892716a3c9a7b8facc076fc056ac425bcfe6 (diff)
downloadgit-81a9aa60a193f1181149b69920930e15c4e34059.zip
git-81a9aa60a193f1181149b69920930e15c4e34059.tar.gz
git-81a9aa60a193f1181149b69920930e15c4e34059.tar.bz2
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>
Diffstat (limited to 'entry.c')
-rw-r--r--entry.c23
1 files changed, 14 insertions, 9 deletions
diff --git a/entry.c b/entry.c
index bb6bdb9..cc8f0c6 100644
--- a/entry.c
+++ b/entry.c
@@ -2,15 +2,19 @@
#include "blob.h"
#include "dir.h"
-static void create_directories(const char *path, const struct checkout *state)
+static void create_directories(const char *path, int path_len,
+ const struct checkout *state)
{
- int len = strlen(path);
- char *buf = xmalloc(len + 1);
- const char *slash = path;
-
- while ((slash = strchr(slash+1, '/')) != NULL) {
- len = slash - path;
- memcpy(buf, path, len);
+ char *buf = xmalloc(path_len + 1);
+ int len = 0;
+
+ while (len < path_len) {
+ do {
+ buf[len] = path[len];
+ len++;
+ } while (len < path_len && path[len] != '/');
+ if (len >= path_len)
+ break;
buf[len] = 0;
/*
@@ -190,6 +194,7 @@ int checkout_entry(struct cache_entry *ce, const struct checkout *state, char *t
memcpy(path, state->base_dir, len);
strcpy(path + len, ce->name);
+ len += ce_namelen(ce);
if (!lstat(path, &st)) {
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
return error("unable to unlink old '%s' (%s)", path, strerror(errno));
} else if (state->not_new)
return 0;
- create_directories(path, state);
+ create_directories(path, len, state);
return write_entry(ce, path, state, 0);
}