]> git.ipfire.org Git - thirdparty/git.git/commit - symlinks.c
lstat_cache(): more cache effective symlink/directory detection
authorKjetil Barvik <barvik@broadpark.no>
Sun, 18 Jan 2009 15:14:50 +0000 (16:14 +0100)
committerJunio C Hamano <gitster@pobox.com>
Sun, 18 Jan 2009 21:54:45 +0000 (13:54 -0800)
commit92604b466344b2157efc42ef3521dac22d7906a2
tree7ceaea4b2a2f1a893e985cbfe4eb3179f5af427f
parent7eb5bbdb645e04d746bc0edea102744f50a5e529
lstat_cache(): more cache effective symlink/directory detection

Make the cache functionality more effective.  Previously when A/B/C/D
was in the cache and A/B/C/E/file.c was called for, there was no match
at all from the cache.  Now we use the fact that the paths "A", "A/B"
and "A/B/C" are already tested, and we only need to do an lstat() call
on "A/B/C/E".

We only cache/store the last path regardless of its type.  Since the
cache functionality is always used with alphabetically sorted names
(at least it seems so for me), there is no need to store both the last
symlink-leading path and the last real-directory path.  Note that if
the cache is not called with (mostly) alphabetically sorted names,
neither the old, nor this new one, would be very effective.

Previously, when symlink A/B/C/S was cached/stored in the symlink-
leading path, and A/B/C/file.c was called for, it was not easy to use
the fact that we already knew that the paths "A", "A/B" and "A/B/C"
are real directories.

Avoid copying the first path components of the name 2 zillion times
when we test new path components.  Since we always cache/store the
last path, we can copy each component as we test those directly into
the cache.  Previously we ended up doing a memcpy() for the full
path/name right before each lstat() call, and when updating the cache
for each time we have tested a new path component.

We also use less memory, that is, PATH_MAX bytes less memory on the
stack and PATH_MAX bytes less memory on the heap.

Thanks to Junio C Hamano, Linus Torvalds and Rene Scharfe for valuable
comments to this patch!

Signed-off-by: Kjetil Barvik <barvik@broadpark.no>
Signed-off-by: Junio C Hamano <gitster@pobox.com>
symlinks.c