notmasteryet/jpgjs — pull request #20 by fkaelberer (2014-01-10 16:06:26+00:00)
Title: Slightly shorter / slightly faster

I compacted the code a little bit, resulting in 5-10% faster running times
(Measured in Chrome 33dev and Firefox Nightly under Windows and Linux).

Speed is increased by slightly less copying in the DCT, and by the use of narrower integer arrays for 'zigzag' and quantization tables. This should also reduce memory use a little.

Also, inlining the "sample" variable in the DCT as below saved a significant amount of time... JS performance keeps surprising me!
```
for (i = 0; i < 64; ++i) {
- var sample = (p[i] + 2056) >> 4;
- p[i] = clampTo8bit(sample);
+ p[i] = clampTo8bit((p[i] + 2056) >> 4);
}
```

The changes in the getData() function and below just shorten the code. Performance is not really affected.

The only semantic change is that if 'Unsupported color mode (4 components)' is thrown, then image data array is unnecessarily built before throwing the exception. But since that is a rare case, it should be ok.

Also, I switched to performance.now() in the benchmark, since Date's millisecond resolution is too coarse on operations that merely take a couple of milliseconds.