Don't use forEach in loops

I know that @tschaub doesn't like `forEach` :)

This PR uses `for` loops instead of `forEach` in performance-critical code.

Open questions:

 * Should the `length` property be cached or not? i.e. should we use `for (i = 0, n = arr.length; i < n; ++i)` or `for (i = 0; i < arr.length; ++i)` ? [jsperf says it only has marginal effect](http://jsperf.com/array-length-vs-cached/14), and typically `arr.length < 10`.

 * Should we check object properties with `hasOwnProperty`, even when we know that the object has no prototype? [Crockford thinks we should](http://javascript.crockford.com/code.html), but I don't know if this test decreases performance (by adding a check) or increases performance (by hinting to the JS engine that we'll never traverse the prototype chain).

Thanks for any input.