From: Kjetil Barvik <barvik@broadpark.no>
To: git@vger.kernel.org
Cc: Kjetil Barvik <barvik@broadpark.no>
Subject: [PATCH/RFC v1 4/6] use fstat() instead of lstat() when we have an opened file
Date: Mon, 26 Jan 2009 22:17:15 +0100 [thread overview]
Message-ID: <1233004637-15112-5-git-send-email-barvik@broadpark.no> (raw)
In-Reply-To: <1233004637-15112-1-git-send-email-barvik@broadpark.no>
Currently inside write_entry() we do an lstat(path, &st) call on a
file which have just been opened inside the exact same function. It
should be better to call fstat(fd, &st) on the file while it is
opened, and it should be at least as fast as the lstat() method.
Signed-off-by: Kjetil Barvik <barvik@broadpark.no>
---
entry.c | 11 ++++++++---
1 files changed, 8 insertions(+), 3 deletions(-)
diff --git a/entry.c b/entry.c
index 8543755..c932ae8 100644
--- a/entry.c
+++ b/entry.c
@@ -96,11 +96,12 @@ write_entry(struct cache_entry *ce, char *path, const struct checkout *state,
int to_tempfile)
{
unsigned int ce_mode_s_ifmt = ce->ce_mode & S_IFMT;
- int fd, ret;
+ int fd, ret, fstat_done = 0;
char *new;
struct strbuf buf = STRBUF_INIT;
unsigned long size;
size_t wrote, newsize = 0;
+ struct stat st;
switch (ce_mode_s_ifmt) {
case S_IFREG:
@@ -151,6 +152,10 @@ write_entry(struct cache_entry *ce, char *path, const struct checkout *state,
}
wrote = write_in_full(fd, new, size);
+ if (state->refresh_cache) {
+ fstat(fd, &st);
+ fstat_done = 1;
+ }
close(fd);
free(new);
if (wrote != size)
@@ -174,8 +179,8 @@ write_entry(struct cache_entry *ce, char *path, const struct checkout *state,
}
if (state->refresh_cache) {
- struct stat st;
- lstat(ce->name, &st);
+ if (!fstat_done)
+ lstat(ce->name, &st);
fill_stat_cache_info(ce, &st);
}
return 0;
--
1.6.1.349.g99fa5
next prev parent reply other threads:[~2009-01-26 21:19 UTC|newest]
Thread overview: 16+ messages / expand[flat|nested] mbox.gz Atom feed top
2009-01-26 21:17 [PATCH/RFC v1 0/6] git checkout: more cleanups, optimisation, less lstat() calls Kjetil Barvik
2009-01-26 21:17 ` [PATCH/RFC v1 1/6] symlinks.c: small cleanup and optimisation Kjetil Barvik
2009-01-28 20:36 ` ??? " Junio C Hamano
2009-01-29 14:19 ` Kjetil Barvik
2009-01-26 21:17 ` [PATCH/RFC v1 2/6] remove some memcpy() and strchr() calls inside create_directories() Kjetil Barvik
2009-01-28 20:36 ` Junio C Hamano
2009-01-26 21:17 ` [PATCH/RFC v1 3/6] cleanup of write_entry() in entry.c Kjetil Barvik
2009-01-28 21:31 ` Junio C Hamano
2009-01-26 21:17 ` Kjetil Barvik [this message]
2009-01-26 21:17 ` [PATCH/RFC v1 5/6] combine-diff.c: remove a call to fstat() inside show_patch_diff() Kjetil Barvik
2009-01-27 9:35 ` Mike Ralphson
2009-01-27 12:03 ` Kjetil Barvik
2009-01-27 12:06 ` Mike Ralphson
2009-01-28 20:37 ` Junio C Hamano
2009-01-29 1:16 ` Junio C Hamano
2009-01-29 8:20 ` Kjetil Barvik
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=1233004637-15112-5-git-send-email-barvik@broadpark.no \
--to=barvik@broadpark.no \
--cc=git@vger.kernel.org \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).