Re: [PATCH v2] xdiff: load full words in the inner loop of xdl_hash_record

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

 



Thomas Rast <trast@xxxxxxxxxxxxxxx> writes:

> +unsigned long xdl_hash_record(char const **data, char const *top, long flags) {
> +	unsigned long hash = 5381;
> +	unsigned long a = 0, mask = 0;
> +	char const *ptr = *data;
> +	char const *end = top-sizeof(unsigned long)+1;
> +
> +	if (flags & XDF_WHITESPACE_FLAGS)
> +		return xdl_hash_record_with_whitespace(data, top, flags);
> +
> +	ptr -= sizeof(unsigned long);
> +	do {
> +		hash += hash << 5;
> +		hash ^= a;
> +		ptr += sizeof(unsigned long);
> +		if (ptr >= end)
> +			break;
> +		a = *(unsigned long *)ptr;
> +		/* Do we have any '\n' bytes in this word? */
> +		mask = has_zero(a ^ NEWLINEBYTES);
> +	} while (!mask);
> +
> +	if (ptr >= end) {
> +		/*
> +		 * There is only a partial word left at the end of the
> +		 * buffer. Because we may work with a memory mapping,
> +		 * we have to grab the rest byte by byte instead of
> +		 * blindly reading it.

Ok, because end is sufficiently below "top" and because you know "top-1"
should be a mapped byte, the "ptr >= end" check in the above loop ensures
that reading ul at ptr will stay within the range of mapped pages.

Cute but ugly ;-)
--
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]