git/list[1] front-page[2] threads[3] people[4] search[5] about
 

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 ;-)
Previous: Thomas Rast
Message 2 of 2 in “xdiff: load full words in the inner loop of xdl_hash_record”
  1. xdiff: load full words in the inner loop of xdl_hash_recordThomas Rast, Apr 6, 2012
  2. Junio C HamanoApr 9, 2012

Read the whole thread, see it on lore, or plain text.

$ cat FOOTERMessages come from the public archive at lore.kernel.org/git, fetched every hour. The front page is chosen and written each morning by an AI editor and can be wrong; the threads themselves are the record. About and API. For agents: an MCP server at https://gitlist.dev/mcp, and any thread, story or person page as Markdown by adding .md to its URL (or sending Accept: text/markdown). Details in /llms.txt.