Speed up #build_formats (changes its API)

Rewrites build_formats for more speed.

1. Stops once best match is found and skips tests that won't match
1. Performs count directly instead of temporarily storing a value for every row
1. Uses symbols