Re: trim whitespace
- From: John Kelly <jak@xxxxxxxxxxxx>
- Date: Sun, 22 Aug 2010 11:34:33 +0000
On Sun, 22 Aug 2010 04:32:31 -0400, Shao Miller <sha0.miller@xxxxxxxxx>
wrote:
You do two C operations for every character. A read, and a store.Right. Well, a read for every character, and a store for every
character after the left trim, plus one store for the terminator.
Are you saying this code
/* Trim left */
while (isspace(*string = *i))
++i;
does not do a read and store on every iteration?
I only read each character. The memmove() may be library optimized withAnd if it isn't?
assembly language.
Then mine is no worse than yours.
Suppose 'memmove' "remaps" the pointer to point directly to the target.
Well that'd certainly be a nearly instantaneous "write pass".
Maybe 'strchr' could quickly give you a pointer to the end of the string
and you can 'isspace' your way backwards to find the right-hand trim
boundary.
The implementations of 'memmove' and 'strchr' are unknowns. How can you
guarantee that your own read pass followed by a 'memmove' will be no
slower than your own read pass and your own write pass?
Seems intuitive to me.
Function calls to C Standard Library functions can have overhead.
Checking overlap conditions in a 'memmove' implementation can have
overhead. Using a buffer in a 'memmove' implementation can have
overhead. Calculating the number of times to copy X bytes-at-a-time
followed by the remaining bytes can have overhead. I'm not suggesting
that these concerns are valid for your target implementation(s), but
they are unknowns, aren't they?
Maybe we should race.
--
Web mail, POP3, and SMTP
http://www.beewyz.com/freeaccounts.php
.
- Follow-Ups:
- Re: trim whitespace
- From: Shao Miller
- Re: trim whitespace
- References:
- trim whitespace
- From: John Kelly
- Re: trim whitespace
- From: Nick
- Re: trim whitespace
- From: John Kelly
- Re: trim whitespace
- From: John Kelly
- Re: trim whitespace
- From: Shao Miller
- Re: trim whitespace
- From: John Kelly
- Re: trim whitespace
- From: Lew Pitcher
- Re: trim whitespace
- From: Shao Miller
- Re: trim whitespace
- From: John Kelly
- Re: trim whitespace
- From: Shao Miller
- trim whitespace
- Prev by Date: Re: trim whitespace, bullet proof version
- Next by Date: Re: trim whitespace, bullet proof version
- Previous by thread: Re: trim whitespace
- Next by thread: Re: trim whitespace
- Index(es):
Relevant Pages
|