[PATCH 3/3] convert.c: Optimize convert_cmp_checkout() for changed file len

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



From: Torsten Bögershausen <tboegi@xxxxxx>

Whenever the size of data from convert_to_working_tree() is different
from the length of the file in the working tree, the must be different
and compare_with_fd() can be skipped.

Signed-off-by: Torsten Bögershausen <tboegi@xxxxxx>
---
 convert.c | 34 +++++++++++++++++-----------------
 1 file changed, 17 insertions(+), 17 deletions(-)

diff --git a/convert.c b/convert.c
index 9cbc62c..2593367 100644
--- a/convert.c
+++ b/convert.c
@@ -838,30 +838,30 @@ static void convert_attrs(struct conv_attrs *ca, const char *path)
 int convert_cmp_checkout(const char *path)
 {
 	struct conv_attrs ca;
-	int match = -1; /* no match */
-	int fd;
+	size_t sz;
+	void *data;
+	int match = -1; /* no match, or unknown */
 	convert_attrs(&ca, path);
 	if (ca.crlf_action == CRLF_BINARY && !ca.drv && !ca.ident)
 	  return -1; /* No eol conversion, no ident, no filter */
 
-	fd = open(path, O_RDONLY);
-	if (fd >= 0) {
-		unsigned long sz;
-		void *data;
-		data = read_blob_data_from_cache(path, &sz);
-		if (!data)
-			match = -1;
-		else {
-			struct strbuf worktree = STRBUF_INIT;
-			if (convert_to_working_tree(path, data, sz, &worktree)) {
-				free(data);
-				data = strbuf_detach(&worktree, &sz);
+	data = read_blob_data_from_cache(path, &sz);
+	if (data) {
+		struct strbuf worktree = STRBUF_INIT;
+		struct stat st;
+		if (convert_to_working_tree(path, data, sz, &worktree)) {
+			free(data);
+			data = strbuf_detach(&worktree, &sz);
+		}
+		if (!lstat(path, &st) && sz == xsize_t(st.st_size)) {
+			int fd = open(path, O_RDONLY);
+			if (fd >= 0) {
+				if (!compare_with_fd(data, sz, fd))
+					match = 0;
+				close(fd);
 			}
-			if (!compare_with_fd(data, sz, fd))
-				match = 0;
 		}
 		free(data);
-		close(fd);
 	}
 	return match;
 }
-- 
2.7.0.303.g2c4f448.dirty

--
To unsubscribe from this list: send the line "unsubscribe git" in
the body of a message to majordomo@xxxxxxxxxxxxxxx
More majordomo info at  http://vger.kernel.org/majordomo-info.html



[Index of Archives]     [Linux Kernel Development]     [Gcc Help]     [IETF Annouce]     [DCCP]     [Netdev]     [Networking]     [Security]     [V4L]     [Bugtraq]     [Yosemite]     [MIPS Linux]     [ARM Linux]     [Linux Security]     [Linux RAID]     [Linux SCSI]     [Fedora Users]