From: Wilco Dijkstra <Wilco.Dijkstra@arm.com>
To: "adhemerval.zanella@linaro.org" <adhemerval.zanella@linaro.org>,
"Andreas Schwab" <schwab@suse.de>
Cc: "libc-alpha@sourceware.org" <libc-alpha@sourceware.org>, nd <nd@arm.com>
Subject: Re: [PATCH] Fix undefined behaviour inconsistent for strtok
Date: Tue, 25 Oct 2016 16:46:00 -0000 [thread overview]
Message-ID: <AM5PR0802MB2610EA174D70285E261CA91283A80@AM5PR0802MB2610.eurprd08.prod.outlook.com> (raw)
In-Reply-To: <AM5PR0802MB2610A3388EDD439E3EDED65083A80@AM5PR0802MB2610.eurprd08.prod.outlook.com>
Hi,
>+ if ((s == NULL) && ((s = olds) == NULL))
>+ return NULL;
>
> What is the benefit of this given:
>
> if (s == NULL)
> /* This token finishes the string. */
> olds = __rawmemchr (token, '\0');
Right, looking at this a bit more, if we call strcspn rather than strpbrk,
we get the end of the string for free and avoid 2 calls.
It looks like the reason behind the (s = olds) == NULL check is purely
performance. Checking *s == '\0' at the start is slightly faster still (and
would seem better as it catches incorrect use of strtok).
With these changes you get > 2x speedup for most cases. I'll post a patch.
Wilco
next prev parent reply other threads:[~2016-10-25 16:46 UTC|newest]
Thread overview: 14+ messages / expand[flat|nested] mbox.gz Atom feed top
2016-10-25 14:04 Wilco Dijkstra
2016-10-25 16:46 ` Wilco Dijkstra [this message]
-- strict thread matches above, loose matches on Subject: below --
2016-10-25 10:58 Adhemerval Zanella
2016-10-25 11:31 ` Andreas Schwab
2016-10-25 12:33 ` Adhemerval Zanella
2016-10-25 12:57 ` Andreas Schwab
2016-10-25 13:13 ` Adhemerval Zanella
2016-10-25 13:20 ` Andreas Schwab
2016-10-25 13:23 ` Adhemerval Zanella
2016-10-25 13:45 ` Andreas Schwab
2016-10-25 13:49 ` Adhemerval Zanella
2016-10-25 13:51 ` Joseph Myers
2016-10-25 14:08 ` Adhemerval Zanella
2016-10-25 13:32 ` Florian Weimer
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=AM5PR0802MB2610EA174D70285E261CA91283A80@AM5PR0802MB2610.eurprd08.prod.outlook.com \
--to=wilco.dijkstra@arm.com \
--cc=adhemerval.zanella@linaro.org \
--cc=libc-alpha@sourceware.org \
--cc=nd@arm.com \
--cc=schwab@suse.de \
/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 read-only IMAP folder(s) and NNTP newsgroup(s).