Re: [PATCH v2] xdiff: load full words in the inner loop of xdl_hash_record
- From
Junio C Hamano <gitster@pobox.com>
- Date
- Apr 9, 2012, 23:03 UTC
- Message-ID
- <7viph8tsmt.fsf@alter.siamese.dyndns.org>
- In-Reply-To
- <e0f938e9b849108e958da2e45e177f6f33d1118d.1333745883.git.trast@student.ethz.ch>
Thomas Rast <trast@student.ethz.ch> writes:
Show 27 quoted lines
> +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 ;-)