I would start with not asking the array all the time how big it is. It doesn't change, so cache that value. Replacing the ranges with classic for loops might speed things up. I doubt a substr based solution be any faster. This is simple enough to do it in C though, even for a novice. If it's really time critical I would write it as XS.
holli
You can lead your users to water, but alas, you cannot drown them.
Comment on Re: improving speed in ngrams algorithm