benbjohnson/megajson — pull request #15 by aybabtme (2014-03-30 05:24:59+00:00)
Title: Add support long strings

This is not perfect and I'm sure a better way could be found. It negatively affect performance on strings:

master:
```
BenchmarkScanNumber 50000000 58.6 ns/op 51.23 MB/s
BenchmarkScanString 20000000 98.4 ns/op 101.58 MB/s
BenchmarkScanLongString 5000000 489 ns/op 116.42 MB/s
BenchmarkScanEscapedString 10000000 149 ns/op 120.50 MB/s
BenchmarkReadString 10000000 153 ns/op 65.04 MB/s
BenchmarkReadLongString 5000000 557 ns/op 102.18 MB/s
BenchmarkReadInt 50000000 62.5 ns/op 79.99 MB/s
BenchmarkReadFloat64 10000000 163 ns/op 97.89 MB/s
BenchmarkReadBool 50000000 62.0 ns/op 64.52 MB/s
ok github.com/benbjohnson/megajson/scanner 23.022s
```
This branch:
```
BenchmarkScanNumber 50000000 54.0 ns/op 55.53 MB/s
BenchmarkScanString 20000000 111 ns/op 89.95 MB/s
BenchmarkScanLongString 5000000 574 ns/op 99.14 MB/s
BenchmarkScanEscapedString 10000000 163 ns/op 109.99 MB/s
BenchmarkReadString 10000000 161 ns/op 62.10 MB/s
BenchmarkReadLongString 5000000 637 ns/op 89.43 MB/s
BenchmarkReadInt 20000000 76.5 ns/op 65.33 MB/s
BenchmarkReadFloat64 10000000 183 ns/op 87.03 MB/s
BenchmarkReadBool 50000000 61.1 ns/op 65.44 MB/s
ok github.com/benbjohnson/megajson/scanner 22.880s
```

I think this is a hack and it's not very clean. I'd like to have input as to how this could be done better. Should there be another func that is delegated to once `n == len(s.scratch)`?

I'll try that out next.