Re: Comment on trim string function please




Willem <willem@xxxxxxxx> wrote in message
news:slrng7e79s.2a5v.willem@xxxxxxxxxxxxxxxxx
Bill Reid wrote:

) (I turn them ALL off, which means sub-scripting is not converted
) to pointers, which I believe takes longer, so to retain the speed
) I've manually converted most of the stuff like this).

As far as I know, there is no speed difference between sub-scripting
and pointers on most modern CPUs.

DAMN!!! More time I've wasted because I JUST WON'T LISTEN!!!

In any event, does the following win the prize for most efficient
implementation of the presumed requirements of the function?

char *remove_beg_end_non_text(char *text) {
char *beg;
size_t length;

for(beg=text;*beg!='\0';beg++)
if(!isspace(*beg)) break;

length=strlen(beg);

while(length>0)
if(!isspace(*(beg+(--length)))) break;

*(beg+(++length))='\0';

return beg==text ? text : memmove(text,beg,length+1);
}

Gotta admit, you couldn't reduce the cycles too much on
that, could you? And it could even win a little bonus prize
for obfuscatory conditions like if(!isspace(*(beg+(--length))))...

---
William Ernest Reid



.



Relevant Pages

  • Re: Java
    ... Programmer wrote: ... And where did 'pointers' get transformed to the generic 'it'? ... SaSW, Willem ... You all think I'm paranoid, ...
    (comp.programming)
  • Re: fast dictionary search algorithm
    ... >) Willem wrote: ... >) collection of pointers, one for each letter. ... > That's a suffix tree, ... "Quidquid latine dictum sit, altum viditur!" ...
    (comp.programming)
  • Re: Choosing a PL - What you can do or how you do it?
    ... Willem wrote: ... thinking of higher-order functions as the main use for returning function ... you might as well not be able to return function pointers? ... - Logan ...
    (comp.programming)