crypto/tls: cache Leaf certificate during BuildNameToCertificate
crypto/tls: cache Leaf certificate during BuildNameToCertificate

I am working on a TLS server program, which issues new TLS certificates
on demand. The new certificates will be added into tls.Config.Certificates.
BuildNameToCertificate will be called to refresh the name table afterwards.
This change will reduce some workload on existing certificates.

Note that you can’t modify the Certificates field (or call BuildNameToCertificate)
on a Config in use by a Server. You can however modify an unused Config that gets
cloned in GetConfigForClient with appropriate locking.

Change-Id: I7bdb7d23fc5d68df83c73f3bfa3ba9181d38fbde
GitHub-Last-Rev: c3788f4116be47f2fdb777935c421e7dd694f5c8
GitHub-Pull-Request: golang/go#24920
Reviewed-on: https://go-review.googlesource.com/c/107627
Reviewed-by: Filippo Valsorda <4f40cda291c5f9634e1affd3db44947af61f705c@golang.org>

josharian/go,nawawi/go,akutz/go,nawawi/go,akutz/go,akutz/go,CAFxX/go,nawawi/go,cloudflare/go,CAFxX/go,josharian/go,cloudflare/go,akutz/go,golang/go,akutz/go,golang/go,golang/go,CAFxX/go,cloudflare/go,josharian/go,akutz/go,nawawi/go,cloudflare/go,golang/go,nawawi/go,cloudflare/go,nawawi/go,josharian/go,CAFxX/go,akutz/go,cloudflare/go,josharian/go,golang/go,CAFxX/go,CAFxX/go,golang/go,josharian/go,golang/go,akutz/go,nawawi/go,josharian/go,CAFxX/go,cloudflare/go,CAFxX/go,golang/go,nawawi/go,cloudflare/go,josharian/go