summary | shortlog | log | commit | commitdiff | tree
raw | patch | inline | side by side (parent: 7a2078b)
raw | patch | inline | side by side (parent: 7a2078b)
author | Junio C Hamano <gitster@pobox.com> | |
Sat, 19 Jan 2008 08:42:22 +0000 (00:42 -0800) | ||
committer | Junio C Hamano <gitster@pobox.com> | |
Tue, 5 Feb 2008 08:38:41 +0000 (00:38 -0800) |
This moves three "if" conditions out of line from find_offset()
function, which is responsible for finding the matching place in
the preimage to apply the patch. There is no change in the
logic of the program.
Signed-off-by: Junio C Hamano <gitster@pobox.com>
function, which is responsible for finding the matching place in
the preimage to apply the patch. There is no change in the
logic of the program.
Signed-off-by: Junio C Hamano <gitster@pobox.com>
builtin-apply.c | patch | blob | history |
diff --git a/builtin-apply.c b/builtin-apply.c
index 15432b6782400b556333ee4117c7daaff20412ab..2c052f80e5296377eca6079bbe72adea43a1cfaa 100644 (file)
--- a/builtin-apply.c
+++ b/builtin-apply.c
@@ -1437,6 +1437,17 @@ static int read_old_data(struct stat *st, const char *path, struct strbuf *buf)
}
}
+static int match_fragment(const char *buf, unsigned long size,
+ unsigned long try,
+ const char *fragment, unsigned long fragsize)
+{
+ if (try + fragsize > size)
+ return 0;
+ if (memcmp(buf + try, fragment, fragsize))
+ return 0;
+ return 1;
+}
+
static int find_offset(const char *buf, unsigned long size,
const char *fragment, unsigned long fragsize,
int line, int *lines)
}
/* Exact line number? */
- if ((start + fragsize <= size) &&
- !memcmp(buf + start, fragment, fragsize))
+ if (match_fragment(buf, size, start, fragment, fragsize))
return start;
/*
try = forwards;
}
- if (try + fragsize > size)
- continue;
- if (memcmp(buf + try, fragment, fragsize))
+ if (!match_fragment(buf, size, try, fragment, fragsize))
continue;
n = (i >> 1)+1;
if (i & 1)