That code will copy and rehash data in your "in" string every iteration. At some point I implemented %*4711s in sscanf() just to be able to avoid that bottleneck and it gave significant savings in my test case (the XML markup repair code in Roxen CMS).