git.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
From: Junio C Hamano <gitster@pobox.com>
To: Thomas Rast <trast@student.ethz.ch>
Cc: <git@vger.kernel.org>
Subject: Re: [PATCH v2] xdiff: load full words in the inner loop of xdl_hash_record
Date: Mon, 09 Apr 2012 16:03:38 -0700	[thread overview]
Message-ID: <7viph8tsmt.fsf@alter.siamese.dyndns.org> (raw)
In-Reply-To: <e0f938e9b849108e958da2e45e177f6f33d1118d.1333745883.git.trast@student.ethz.ch> (Thomas Rast's message of "Fri, 6 Apr 2012 23:01:23 +0200")

Thomas Rast <trast@student.ethz.ch> 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 ;-)

      reply	other threads:[~2012-04-09 23:03 UTC|newest]

Thread overview: 2+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2012-04-06 21:01 [PATCH v2] xdiff: load full words in the inner loop of xdl_hash_record Thomas Rast
2012-04-09 23:03 ` Junio C Hamano [this message]

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=7viph8tsmt.fsf@alter.siamese.dyndns.org \
    --to=gitster@pobox.com \
    --cc=git@vger.kernel.org \
    --cc=trast@student.ethz.ch \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).