Optimizes and tests FormatInt by removing inefficient string
concatenation but also making it so much clearer with how one would
express adding thousand separators in natural language. It uses
a combination of strings.Builder whose values can be grown
The performance improvement is stark in every dimension:
```shell
$ benchstat before.txt after3.txt
name old time/op new time/op delta
DecimalValueRendererFormat-8 4.48µs ± 1% 2.11µs ± 2% -52.90% (p=0.000 n=10+10)
name old alloc/op new alloc/op delta
DecimalValueRendererFormat-8 3.62kB ± 0% 0.78kB ± 0% -78.59% (p=0.000 n=10+10)
name old allocs/op new allocs/op delta
DecimalValueRendererFormat-8 83.0 ± 0% 28.0 ± 0% -66.27% (p=0.000 n=10+10)
```
While here, also simplified zero padding for LegacyNewDecFromStr
simply by using strings.Repeat instead of a convoluted
fmt.Sprintf+strconv.Itoa.
Fixes#14008Fixes#14003
Co-authored-by: Marko <marbar3778@yahoo.com>
* refactor: Move FormatCoins to `core`
* Rename to shorter names
* Add chaneglog
* Don't panic
* add comments
* go mod tidy
* fix changelog
* move structs to top
* Fix test
* go mod tidy
* Refactor tests
The specification of "copy", the builtin function per
https://pkg.go.dev/builtin#copy, says that it returns the minimum of
len(src) and len(dst) when invoked as:
copy(dst, src)
of which the prior code blindly assumed that everytime that
copy is invoked that the buffer provided had enough size
to accomodate the contents of *.MarshalTo but this isn't true
at all if len(data) is less than the values of .Marshal()