refactor stream reading for great glory
refactor stream reading for great glory

This probably ends up being a little more memory hungry in some cases,
but it's a huge win overall. For seekable input, use fread, which does
buffering for us. Alloc the whole file at once and read into the
buffer. For unseekable input, fall back on a manual loop using read(2)
and a separate BUFSIZ'd buffer.

The net result is a huge performance win which is very noticeable on
larger inputs:

Using a test command of:

  journalctl -b -o json |
      sed -e '1i[' -e '$!s/$/,/' -e '$a]' |
      bash -c 'time jshon >/dev/null'

This generates a json array with nearly 22000 objects.

Before:

  real    0m12.358s
  user    0m12.197s
  sys     0m0.163s

After:

  real    0m1.864s
  user    0m0.810s
  sys     0m0.065s

And for testing seekable input, dump the same data to a file, and test
with:

  time jshon <json.txt >/dev/null

Before:

  real    0m12.255s
  user    0m12.146s
  sys     0m0.129s

After:
  real    0m0.841s
  user    0m0.793s
  sys     0m0.049s

rowanthorpe/jshon,anshprat/jshon,anshprat/jshon,keenerd/jshon,keenerd/jshon,rowanthorpe/jshon