made function static to enable compiler optimization and moved

str.length() outside the loop to prevent unneeded method calls.
Merge pull request #305 from igal-getrailo/improve-003

made function static to enable compiler optimization and moved