Reduce cost of CreateSecKeyAndSecWebSocketAccept (#49831)
authorStephen Toub <stoub@microsoft.com>
Mon, 22 Mar 2021 10:33:17 +0000 (06:33 -0400)
committerGitHub <noreply@github.com>
Mon, 22 Mar 2021 10:33:17 +0000 (06:33 -0400)
commit11868166a541b2746eb86b8812302bd65ecfd2f7
tree8f6178476532889af9620803002a52753caf3d85
parent96e45f3beab058c2b86792f16a2df34cda41e41d
Reduce cost of CreateSecKeyAndSecWebSocketAccept (#49831)

This isn't a big deal as it's once per websocket connection, but it annoys me every time I see the unnecessary waste in a trace.  Previously this would allocate:
1. A byte[] for the bytes from the guid
2. A base64-encoded string for (1)
3. A string concatenating (2) and the known server guid
4. A byte[] containing the bytes from (3)
5. A byte[] containing the SHA1-hashed bytes of (4)
6. A base64-encoded string of (5)

Now, it only allocates (2) and (6).
src/libraries/System.Net.WebSockets.Client/src/System/Net/WebSockets/WebSocketHandle.Managed.cs