mirror of
https://github.com/git/git.git
synced 2025-12-12 20:36:24 +01:00
xdiff: use unambiguous types in xdl_hash_record()
Convert the function signature and body to use unambiguous types. char is changed to uint8_t because this function processes bytes in memory. unsigned long to uint64_t so that the hash output is consistent across platforms. `flags` was changed from long to uint64_t to ensure the high order bits are not dropped on platforms that treat long as 32 bits. Signed-off-by: Ezekiel Newren <ezekielnewren@gmail.com> Signed-off-by: Junio C Hamano <gitster@pobox.com>
This commit is contained in:
committed by
Junio C Hamano
parent
9bd193253c
commit
b0d4ae30f5
@@ -300,7 +300,7 @@ void xdiff_clear_find_func(xdemitconf_t *xecfg)
|
|||||||
|
|
||||||
unsigned long xdiff_hash_string(const char *s, size_t len, long flags)
|
unsigned long xdiff_hash_string(const char *s, size_t len, long flags)
|
||||||
{
|
{
|
||||||
return xdl_hash_record(&s, s + len, flags);
|
return xdl_hash_record((uint8_t const**)&s, (uint8_t const*)s + len, flags);
|
||||||
}
|
}
|
||||||
|
|
||||||
int xdiff_compare_lines(const char *l1, long s1,
|
int xdiff_compare_lines(const char *l1, long s1,
|
||||||
|
|||||||
@@ -137,8 +137,8 @@ static void xdl_free_ctx(xdfile_t *xdf)
|
|||||||
static int xdl_prepare_ctx(unsigned int pass, mmfile_t *mf, long narec, xpparam_t const *xpp,
|
static int xdl_prepare_ctx(unsigned int pass, mmfile_t *mf, long narec, xpparam_t const *xpp,
|
||||||
xdlclassifier_t *cf, xdfile_t *xdf) {
|
xdlclassifier_t *cf, xdfile_t *xdf) {
|
||||||
long bsize;
|
long bsize;
|
||||||
unsigned long hav;
|
uint64_t hav;
|
||||||
char const *blk, *cur, *top, *prev;
|
uint8_t const *blk, *cur, *top, *prev;
|
||||||
xrecord_t *crec;
|
xrecord_t *crec;
|
||||||
|
|
||||||
xdf->rindex = NULL;
|
xdf->rindex = NULL;
|
||||||
@@ -156,7 +156,7 @@ static int xdl_prepare_ctx(unsigned int pass, mmfile_t *mf, long narec, xpparam_
|
|||||||
if (XDL_ALLOC_GROW(xdf->recs, xdf->nrec + 1, narec))
|
if (XDL_ALLOC_GROW(xdf->recs, xdf->nrec + 1, narec))
|
||||||
goto abort;
|
goto abort;
|
||||||
crec = &xdf->recs[xdf->nrec++];
|
crec = &xdf->recs[xdf->nrec++];
|
||||||
crec->ptr = (uint8_t const *)prev;
|
crec->ptr = prev;
|
||||||
crec->size = cur - prev;
|
crec->size = cur - prev;
|
||||||
crec->ha = hav;
|
crec->ha = hav;
|
||||||
if (xdl_classify_record(pass, cf, crec) < 0)
|
if (xdl_classify_record(pass, cf, crec) < 0)
|
||||||
|
|||||||
@@ -249,11 +249,11 @@ int xdl_recmatch(const char *l1, long s1, const char *l2, long s2, long flags)
|
|||||||
return 1;
|
return 1;
|
||||||
}
|
}
|
||||||
|
|
||||||
unsigned long xdl_hash_record_with_whitespace(char const **data,
|
uint64_t xdl_hash_record_with_whitespace(uint8_t const **data,
|
||||||
char const *top, long flags) {
|
uint8_t const *top, uint64_t flags) {
|
||||||
unsigned long ha = 5381;
|
uint64_t ha = 5381;
|
||||||
char const *ptr = *data;
|
uint8_t const *ptr = *data;
|
||||||
int cr_at_eol_only = (flags & XDF_WHITESPACE_FLAGS) == XDF_IGNORE_CR_AT_EOL;
|
bool cr_at_eol_only = (flags & XDF_WHITESPACE_FLAGS) == XDF_IGNORE_CR_AT_EOL;
|
||||||
|
|
||||||
for (; ptr < top && *ptr != '\n'; ptr++) {
|
for (; ptr < top && *ptr != '\n'; ptr++) {
|
||||||
if (cr_at_eol_only) {
|
if (cr_at_eol_only) {
|
||||||
@@ -263,8 +263,8 @@ unsigned long xdl_hash_record_with_whitespace(char const **data,
|
|||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
else if (XDL_ISSPACE(*ptr)) {
|
else if (XDL_ISSPACE(*ptr)) {
|
||||||
const char *ptr2 = ptr;
|
const uint8_t *ptr2 = ptr;
|
||||||
int at_eol;
|
bool at_eol;
|
||||||
while (ptr + 1 < top && XDL_ISSPACE(ptr[1])
|
while (ptr + 1 < top && XDL_ISSPACE(ptr[1])
|
||||||
&& ptr[1] != '\n')
|
&& ptr[1] != '\n')
|
||||||
ptr++;
|
ptr++;
|
||||||
@@ -274,20 +274,20 @@ unsigned long xdl_hash_record_with_whitespace(char const **data,
|
|||||||
else if (flags & XDF_IGNORE_WHITESPACE_CHANGE
|
else if (flags & XDF_IGNORE_WHITESPACE_CHANGE
|
||||||
&& !at_eol) {
|
&& !at_eol) {
|
||||||
ha += (ha << 5);
|
ha += (ha << 5);
|
||||||
ha ^= (unsigned long) ' ';
|
ha ^= (uint64_t) ' ';
|
||||||
}
|
}
|
||||||
else if (flags & XDF_IGNORE_WHITESPACE_AT_EOL
|
else if (flags & XDF_IGNORE_WHITESPACE_AT_EOL
|
||||||
&& !at_eol) {
|
&& !at_eol) {
|
||||||
while (ptr2 != ptr + 1) {
|
while (ptr2 != ptr + 1) {
|
||||||
ha += (ha << 5);
|
ha += (ha << 5);
|
||||||
ha ^= (unsigned long) *ptr2;
|
ha ^= (uint64_t) *ptr2;
|
||||||
ptr2++;
|
ptr2++;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
ha += (ha << 5);
|
ha += (ha << 5);
|
||||||
ha ^= (unsigned long) *ptr;
|
ha ^= (uint64_t) *ptr;
|
||||||
}
|
}
|
||||||
*data = ptr < top ? ptr + 1: ptr;
|
*data = ptr < top ? ptr + 1: ptr;
|
||||||
|
|
||||||
@@ -304,9 +304,9 @@ unsigned long xdl_hash_record_with_whitespace(char const **data,
|
|||||||
#define REASSOC_FENCE(x, y)
|
#define REASSOC_FENCE(x, y)
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
unsigned long xdl_hash_record_verbatim(char const **data, char const *top) {
|
uint64_t xdl_hash_record_verbatim(uint8_t const **data, uint8_t const *top) {
|
||||||
unsigned long ha = 5381, c0, c1;
|
uint64_t ha = 5381, c0, c1;
|
||||||
char const *ptr = *data;
|
uint8_t const *ptr = *data;
|
||||||
#if 0
|
#if 0
|
||||||
/*
|
/*
|
||||||
* The baseline form of the optimized loop below. This is the djb2
|
* The baseline form of the optimized loop below. This is the djb2
|
||||||
@@ -314,7 +314,7 @@ unsigned long xdl_hash_record_verbatim(char const **data, char const *top) {
|
|||||||
*/
|
*/
|
||||||
for (; ptr < top && *ptr != '\n'; ptr++) {
|
for (; ptr < top && *ptr != '\n'; ptr++) {
|
||||||
ha += (ha << 5);
|
ha += (ha << 5);
|
||||||
ha += (unsigned long) *ptr;
|
ha += (uint64_t) *ptr;
|
||||||
}
|
}
|
||||||
*data = ptr < top ? ptr + 1: ptr;
|
*data = ptr < top ? ptr + 1: ptr;
|
||||||
#else
|
#else
|
||||||
|
|||||||
@@ -34,9 +34,9 @@ void *xdl_cha_alloc(chastore_t *cha);
|
|||||||
long xdl_guess_lines(mmfile_t *mf, long sample);
|
long xdl_guess_lines(mmfile_t *mf, long sample);
|
||||||
int xdl_blankline(const char *line, long size, long flags);
|
int xdl_blankline(const char *line, long size, long flags);
|
||||||
int xdl_recmatch(const char *l1, long s1, const char *l2, long s2, long flags);
|
int xdl_recmatch(const char *l1, long s1, const char *l2, long s2, long flags);
|
||||||
unsigned long xdl_hash_record_verbatim(char const **data, char const *top);
|
uint64_t xdl_hash_record_verbatim(uint8_t const **data, uint8_t const *top);
|
||||||
unsigned long xdl_hash_record_with_whitespace(char const **data, char const *top, long flags);
|
uint64_t xdl_hash_record_with_whitespace(uint8_t const **data, uint8_t const *top, uint64_t flags);
|
||||||
static inline unsigned long xdl_hash_record(char const **data, char const *top, long flags)
|
static inline uint64_t xdl_hash_record(uint8_t const **data, uint8_t const *top, uint64_t flags)
|
||||||
{
|
{
|
||||||
if (flags & XDF_WHITESPACE_FLAGS)
|
if (flags & XDF_WHITESPACE_FLAGS)
|
||||||
return xdl_hash_record_with_whitespace(data, top, flags);
|
return xdl_hash_record_with_whitespace(data, top, flags);
|
||||||
|
|||||||
Reference in New Issue
Block a user