summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorLibravatar Junio C Hamano <junkio@cox.net>2007-05-07 01:14:21 -0700
committerLibravatar Junio C Hamano <junkio@cox.net>2007-05-07 15:54:32 -0700
commit6e0b8ed6d35d0ed94b22652d6e8545b610cc43ab (patch)
tree6bb023da52a5360267b9672e0b648c80387c5648
parentdiff: release blobs after generating textual diff. (diff)
downloadtgif-6e0b8ed6d35d0ed94b22652d6e8545b610cc43ab.tar.xz
diff.c: do not use a separate "size cache".
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>
-rw-r--r--diff.c72
1 files changed, 4 insertions, 68 deletions
diff --git a/diff.c b/diff.c
index 2979bc57e4..8354e71e07 100644
--- a/diff.c
+++ b/diff.c
@@ -16,8 +16,6 @@
#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
@@ -1512,12 +1461,12 @@ int diff_populate_filespec(struct diff_filespec *s, int size_only)
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);
@@ -1579,19 +1528,8 @@ int diff_populate_filespec(struct diff_filespec *s, int 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;
@@ -2102,8 +2040,6 @@ int diff_setup_done(struct diff_options *options)
*/
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 */