All of lore.kernel.org
 help / color / mirror / Atom feed
From: Joe Perches <joe@perches.com>
To: Orestes Leal Rodriguez <lukes357@gmail.com>
Cc: linux-kernel@vger.kernel.org, mihai.dontu@gmail.com
Subject: Re: [PATCH 1/1] lib: small update for strlen, strnlen, use less cpu instructions
Date: Tue, 16 Jun 2015 15:16:45 -0700	[thread overview]
Message-ID: <1434493005.2689.12.camel@perches.com> (raw)
In-Reply-To: <55806FE8.9030302@gmail.com>

On Tue, 2015-06-16 at 13:50 -0500, Orestes Leal Rodriguez wrote:
> Very small update to strlen and strnlen that now use less cpu 
> instructions by using a counter to avoid the memory addresses 
> substraction to find the length of the string.
[]
> @@ -418,12 +422,13 @@ EXPORT_SYMBOL(strlen);
>    */
>   size_t strnlen(const char *s, size_t count)
>   {
> -	const char *sc;
> +	size_t sz = 0;
> 
> -	for (sc = s; count-- && *sc != '\0'; ++sc)
> -		/* nothing */;
> -	return sc - s;
> +	for (; count-- && *s++ != '\0'; sz++)
> +		/* empty */;
> +	return sz;

That's one subtraction at end-of-string vs
a register increment for each non-zero byte.

smaller isn't worth slower.


  reply	other threads:[~2015-06-16 22:16 UTC|newest]

Thread overview: 6+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2015-06-16 18:50 [PATCH 1/1] lib: small update for strlen, strnlen, use less cpu instructions Orestes Leal Rodriguez
2015-06-16 22:16 ` Joe Perches [this message]
  -- strict thread matches above, loose matches on Subject: below --
2015-06-16 18:51 Orestes Leal Rodriguez
2015-06-16 22:51 Orestes Leal Rodriguez
2015-06-17 20:07 ` Richard Weinberger
2015-06-19  3:11   ` Orestes Leal Rodriguez

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=1434493005.2689.12.camel@perches.com \
    --to=joe@perches.com \
    --cc=linux-kernel@vger.kernel.org \
    --cc=lukes357@gmail.com \
    --cc=mihai.dontu@gmail.com \
    /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 an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.