summary | shortlog | log | commit | commitdiff | tree
raw | patch | inline | side by side (parent: fc3abdf)
raw | patch | inline | side by side (parent: fc3abdf)
author | Junio C Hamano <junkio@cox.net> | |
Mon, 7 May 2007 08:14:21 +0000 (01:14 -0700) | ||
committer | Junio C Hamano <junkio@cox.net> | |
Mon, 7 May 2007 22:54:32 +0000 (15:54 -0700) |
diff_filespec has a slot to record the size of the data already,
so make use of it instead of a separate size cache.
Signed-off-by: Junio C Hamano <junkio@cox.net>
so make use of it instead of a separate size cache.
Signed-off-by: Junio C Hamano <junkio@cox.net>
diff.c | patch | blob | history |
index 2979bc57e4a98a7ea24412b5359cd8afd614256e..8354e71e0707960f7a1094e288bea0fac83ec6b8 100644 (file)
--- a/diff.c
+++ b/diff.c
#define FAST_WORKING_DIRECTORY 1
#endif
-static int use_size_cache;
-
static int diff_detect_rename_default;
static int diff_rename_limit_default = -1;
static int diff_use_color_default;
@@ -1408,55 +1406,6 @@ static int reuse_worktree_file(const char *name, const unsigned char *sha1, int
return 1;
}
-static struct sha1_size_cache {
- unsigned char sha1[20];
- unsigned long size;
-} **sha1_size_cache;
-static int sha1_size_cache_nr, sha1_size_cache_alloc;
-
-static struct sha1_size_cache *locate_size_cache(unsigned char *sha1,
- int find_only,
- unsigned long size)
-{
- int first, last;
- struct sha1_size_cache *e;
-
- first = 0;
- last = sha1_size_cache_nr;
- while (last > first) {
- int cmp, next = (last + first) >> 1;
- e = sha1_size_cache[next];
- cmp = hashcmp(e->sha1, sha1);
- if (!cmp)
- return e;
- if (cmp < 0) {
- last = next;
- continue;
- }
- first = next+1;
- }
- /* not found */
- if (find_only)
- return NULL;
- /* insert to make it at "first" */
- if (sha1_size_cache_alloc <= sha1_size_cache_nr) {
- sha1_size_cache_alloc = alloc_nr(sha1_size_cache_alloc);
- sha1_size_cache = xrealloc(sha1_size_cache,
- sha1_size_cache_alloc *
- sizeof(*sha1_size_cache));
- }
- sha1_size_cache_nr++;
- if (first < sha1_size_cache_nr)
- memmove(sha1_size_cache + first + 1, sha1_size_cache + first,
- (sha1_size_cache_nr - first - 1) *
- sizeof(*sha1_size_cache));
- e = xmalloc(sizeof(struct sha1_size_cache));
- sha1_size_cache[first] = e;
- hashcpy(e->sha1, sha1);
- e->size = size;
- return e;
-}
-
static int populate_from_stdin(struct diff_filespec *s)
{
#define INCREMENT 1024
if (S_ISDIR(s->mode))
return -1;
- if (!use_size_cache)
- size_only = 0;
-
if (s->data)
return 0;
+ if (size_only && 0 < s->size)
+ return 0;
+
if (S_ISDIRLNK(s->mode))
return diff_populate_gitlink(s, size_only);
}
else {
enum object_type type;
- struct sha1_size_cache *e;
-
- if (size_only && use_size_cache &&
- (e = locate_size_cache(s->sha1, 1, 0)) != NULL) {
- s->size = e->size;
- return 0;
- }
-
- if (size_only) {
+ if (size_only)
type = sha1_object_info(s->sha1, &s->size);
- if (use_size_cache && 0 < type)
- locate_size_cache(s->sha1, 0, s->size);
- }
else {
s->data = read_sha1_file(s->sha1, &type, &s->size);
s->should_free = 1;
*/
read_cache();
}
- if (options->setup & DIFF_SETUP_USE_SIZE_CACHE)
- use_size_cache = 1;
if (options->abbrev <= 0 || 40 < options->abbrev)
options->abbrev = 40; /* full */