[fpc-pascal]Word count function
Barry Kelly
dynagen at eircom.net
Tue Oct 2 17:08:44 CEST 2001
On Mon, 1 Oct 2001 16:41:16 -0400, James_Wilson at i2.com wrote:
> >>const
> >> DELIMITERS = ' .,!?_-)}]>;:=@/\#9';
> >Replace the string by a set, this is much faster:
> >const
> >DELIMITERS : set of char = ['
> ','.',',','!','?','_','-',')','}',']','>',';',':','=','@','/','\',#9];
>
> >if StringToCheck [succ (Index)] in DELIMITERS then
> >should beat the pos call easily
>
> Much faster? Boy, was that an understatement. [...] But I must confess
> that I don't know exactly why there would be such a huge difference. Why
> is a "set of char" soooo much faster then a const?
Because Pascal isn't C. :-) Pascal has this concept built in; Pos checks
for a string in another string, it isn't optimized for just a character.
> >while (Index < LineLength) and (CurrentChar in
> ['A'..'Z','a'..'z','0'..'9']) do
> >might be faster as well
>
> This was certainly cleaner looking then what I had posted,
What you posted looked typically C-ish alright.
-- Barry
--
If you're not part of the solution, you're part of the precipitate.
Team JEDI: http://www.delphi-jedi.org
NNQ - Quoting Style in Newsgroup Postings
http://web.infoave.net/~dcalhoun/nnq/nquote.html
More information about the fpc-pascal
mailing list