runtime: improve makechan memory checks and allocation calls
runtime: improve makechan memory checks and allocation calls

Use mallogc instead of newarray to save some overhead since
makechan already checks for _MaxMem constraints.

Flattens the if else construct that determines if buf and hchan struct
should be allocated in one mallocgc call and where buf should point to.

Uses maxSliceCap to avoid divisions similar to makeslice.

name                old time/op  new time/op  delta
MakeChan/Byte       82.0ns ± 8%  81.4ns ± 7%    ~     (p=0.643 n=10+10)
MakeChan/Int        97.9ns ± 2%  96.6ns ± 2%  -1.40%  (p=0.009 n=10+10)
MakeChan/Ptr         128ns ± 3%   120ns ± 1%  -6.63%  (p=0.000 n=10+10)
MakeChan/Struct/0   66.7ns ± 4%  66.4ns ± 2%    ~     (p=0.697 n=10+10)
MakeChan/Struct/32   136ns ± 1%   130ns ± 0%  -4.42%  (p=0.000 n=10+10)
MakeChan/Struct/40   150ns ± 1%   150ns ± 1%    ~     (p=0.725 n=10+10)

Change-Id: Ibb5675d0843a072aae2bfa58ecd39cf4cd926533
Reviewed-on: https://go-review.googlesource.com/55132
Run-TryBot: Martin Möhrmann <9c82b83f348009b39856043bb9ed3ef41e171aeb@google.com>
TryBot-Result: Gobot Gobot <66cb808b70d30c07676d5e946fee83fd561249e5@golang.org>
Reviewed-by: Keith Randall <8c99c3a9284e493be632950b84cd789d08ed3e9d@golang.org>

akutz/go,josharian/go,polyverse-security/go,nawawi/go,Cofyc/go,Cofyc/go,polyverse-security/go,cloudflare/go,josharian/go,codestation/go,CAFxX/go,CAFxX/go,Cofyc/go,codestation/go,codestation/go,golang/go,golang/go,nawawi/go,josharian/go,polyverse-security/go,akutz/go,golang/go,golang/go,CAFxX/go,akutz/go,akutz/go,akutz/go,polyverse-security/go,josharian/go,josharian/go,josharian/go,codestation/go,cloudflare/go,CAFxX/go,cloudflare/go,cloudflare/go,polyverse-security/go,Cofyc/go,akutz/go,nawawi/go,nawawi/go,cloudflare/go,Cofyc/go,codestation/go,christopher-henderson/Go,nawawi/go,josharian/go,cloudflare/go,codestation/go,Cofyc/go,nawawi/go,codestation/go,golang/go,polyverse-security/go,polyverse-security/go,Cofyc/go,CAFxX/go,nawawi/go,akutz/go,CAFxX/go,golang/go,Cofyc/go,CAFxX/go,CAFxX/go,polyverse-security/go,akutz/go,cloudflare/go,josharian/go,nawawi/go,golang/go,codestation/go,cloudflare/go,golang/go