company-safe-substring: use a temp buffer

* No more situations where we replace actual text with whitespace.

* Still don't handle wide characters, except by untabifying in advance.

* It's fast enough, although it woudln't hurt to replace most of the string
  splitting and munching in the callers with direct buffer manipulation.
company-buffer-lines: Speed up

I wonder what had been fixed in 9b2b5b6c623579057e9322bd44a7342d0b08ee92
exactly. It will probably bite us later.