After some sleep, remembered allocating memory in a tight loop is a bad
idea... Performance now slightly better than hand-tuned JS.