summary | shortlog | log | commit | commitdiff | tree
raw | patch | inline | side by side (parent: e923eae)
raw | patch | inline | side by side (parent: e923eae)
author | Dmitry Potapov <dpotapov@gmail.com> | |
Sun, 21 Feb 2010 06:32:19 +0000 (09:32 +0300) | ||
committer | Junio C Hamano <gitster@pobox.com> | |
Sun, 21 Feb 2010 19:39:10 +0000 (11:39 -0800) |
Using read() instead of mmap() can be 39% speed up for 1Kb files and is
1% speed up 1Mb files. For larger files, it is better to use mmap(),
because the difference between is not significant, and when there is not
enough memory, mmap() performs much better, because it avoids swapping.
Signed-off-by: Dmitry Potapov <dpotapov@gmail.com>
Signed-off-by: Junio C Hamano <gitster@pobox.com>
1% speed up 1Mb files. For larger files, it is better to use mmap(),
because the difference between is not significant, and when there is not
enough memory, mmap() performs much better, because it avoids swapping.
Signed-off-by: Dmitry Potapov <dpotapov@gmail.com>
Signed-off-by: Junio C Hamano <gitster@pobox.com>
sha1_file.c | patch | blob | history |
diff --git a/sha1_file.c b/sha1_file.c
index 657825e14ef78c19649779fe89e1d09ae672901a..0375159604205cb1fe00adf7d33533224475a61d 100644 (file)
--- a/sha1_file.c
+++ b/sha1_file.c
return ret;
}
+#define SMALL_FILE_SIZE (32*1024)
+
int index_fd(unsigned char *sha1, int fd, struct stat *st, int write_object,
enum object_type type, const char *path)
{
else
ret = -1;
strbuf_release(&sbuf);
+ } else if (size <= SMALL_FILE_SIZE) {
+ char *buf = xmalloc(size);
+ if (size == read_in_full(fd, buf, size))
+ ret = index_mem(sha1, buf, size, write_object, type,
+ path);
+ else
+ ret = error("short read %s", strerror(errno));
+ free(buf);
} else if (size) {
void *buf = xmmap(NULL, size, PROT_READ, MAP_PRIVATE, fd, 0);
ret = index_mem(sha1, buf, size, write_object, type, path);