зеркало из https://github.com/microsoft/git.git
builtin-apply.c: refactor small part that matches context
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>
This commit is contained in:
Родитель
7a2078b4b0
Коммит
c89fb6b19a
|
@ -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,
|
static int find_offset(const char *buf, unsigned long size,
|
||||||
const char *fragment, unsigned long fragsize,
|
const char *fragment, unsigned long fragsize,
|
||||||
int line, int *lines)
|
int line, int *lines)
|
||||||
|
@ -1461,8 +1472,7 @@ static int find_offset(const char *buf, unsigned long size,
|
||||||
}
|
}
|
||||||
|
|
||||||
/* Exact line number? */
|
/* Exact line number? */
|
||||||
if ((start + fragsize <= size) &&
|
if (match_fragment(buf, size, start, fragment, fragsize))
|
||||||
!memcmp(buf + start, fragment, fragsize))
|
|
||||||
return start;
|
return start;
|
||||||
|
|
||||||
/*
|
/*
|
||||||
|
@ -1494,9 +1504,7 @@ static int find_offset(const char *buf, unsigned long size,
|
||||||
try = forwards;
|
try = forwards;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (try + fragsize > size)
|
if (!match_fragment(buf, size, try, fragment, fragsize))
|
||||||
continue;
|
|
||||||
if (memcmp(buf + try, fragment, fragsize))
|
|
||||||
continue;
|
continue;
|
||||||
n = (i >> 1)+1;
|
n = (i >> 1)+1;
|
||||||
if (i & 1)
|
if (i & 1)
|
||||||
|
|
Загрузка…
Ссылка в новой задаче