martamius/TJSON — pull request #4 by andyli (2013-12-17 14:38:19+00:00)
Title: Optimize TJSON.encode

I'm encoding some large object, and found it a little bit slow, so I took the chance to improve the encode method:
* Use `StringBuf` instead of `+=`.
* Added a `tab` property to `FancyStyle`.
* Use a internal cache for `FancyStyle`'s `charTimesN` method.

I tested with a large (1.8M) json file, compiled to neko:
```haxe

package ;
import TestParser;
class TestAll {
function new(){

}
static function main(){
var t = Sys.cpuTime();
var obj = tjson.TJSON.parse(sys.io.File.getContent("large.json"));
trace(Sys.cpuTime() - t);

var t = Sys.cpuTime();
for (i in 0...10) {
tjson.TJSON.encode(obj);
}
trace(Sys.cpuTime() - t);

var t = Sys.cpuTime();
for (i in 0...10) {
tjson.TJSON.encode(obj, "fancy");
}
trace(Sys.cpuTime() - t);
}
}
```

original:
```
TestAll.hx:11: 11.27
TestAll.hx:17: 8.63
TestAll.hx:23: 15.23
```

improved:
```
TestAll.hx:11: 11.29
TestAll.hx:17: 4.15
TestAll.hx:23: 5.89
```