{"action":"created","comment":{"url":"https://api.github.com/repos/aspnet/Antiforgery/pulls/comments/51660651","id":51660651,"diff_hunk":"@@ -0,0 +1,133 @@\n+﻿// Copyright (c) .NET Foundation. All rights reserved.\n+// Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information.\n+\n+using System;\n+using System.IO;\n+using System.Security.Cryptography;\n+using System.Text;\n+\n+namespace Microsoft.AspNetCore.Antiforgery\n+{\n+    public class AntiforgerySerializationContext : IDisposable\n+    {\n+        // Avoid allocating 256 bytes (the default) and using 18 (the AntiforgeryToken minimum). 64 bytes is enough for\n+        // a short username or claim UID and some additional data. MemoryStream bumps capacity to 256 if exceeded.\n+        private const int InitialStreamSize = 64;\n+\n+        // Don't let the MemoryStream grow beyond 1 MB.\n+        private const int MaximumStreamSize = 0x100000;\n+\n+        private MemoryStream _memory;\n+        private BinaryReader _reader;\n+        private BinaryWriter _writer;\n+        private SHA256 _sha256;\n+\n+        public MemoryStream Memory","path":"src/Microsoft.AspNetCore.Antiforgery/AntiforgerySerializationContext.cs","position":25,"original_position":25,"commit_id":"a42aea254b0b003edd07cc5ae508097da5174912","original_commit_id":"a42aea254b0b003edd07cc5ae508097da5174912","user":{"login":"dougbu","id":6431421,"avatar_url":"https://avatars.githubusercontent.com/u/6431421?v=3","gravatar_id":"","url":"https://api.github.com/users/dougbu","html_url":"https://github.com/dougbu","followers_url":"https://api.github.com/users/dougbu/followers","following_url":"https://api.github.com/users/dougbu/following{/other_user}","gists_url":"https://api.github.com/users/dougbu/gists{/gist_id}","starred_url":"https://api.github.com/users/dougbu/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/dougbu/subscriptions","organizations_url":"https://api.github.com/users/dougbu/orgs","repos_url":"https://api.github.com/users/dougbu/repos","events_url":"https://api.github.com/users/dougbu/events{/privacy}","received_events_url":"https://api.github.com/users/dougbu/received_events","type":"User","site_admin":false},"body":"done","created_at":"2016-02-03T00:24:40Z","updated_at":"2016-02-03T00:24:40Z","html_url":"https://github.com/aspnet/Antiforgery/pull/41#discussion_r51660651","pull_request_url":"https://api.github.com/repos/aspnet/Antiforgery/pulls/41","_links":{"self":{"href":"https://api.github.com/repos/aspnet/Antiforgery/pulls/comments/51660651"},"html":{"href":"https://github.com/aspnet/Antiforgery/pull/41#discussion_r51660651"},"pull_request":{"href":"https://api.github.com/repos/aspnet/Antiforgery/pulls/41"}}},"pull_request":{"url":"https://api.github.com/repos/aspnet/Antiforgery/pulls/41","id":58060107,"html_url":"https://github.com/aspnet/Antiforgery/pull/41","diff_url":"https://github.com/aspnet/Antiforgery/pull/41.diff","patch_url":"https://github.com/aspnet/Antiforgery/pull/41.patch","issue_url":"https://api.github.com/repos/aspnet/Antiforgery/issues/41","number":41,"state":"open","locked":false,"title":"Pool `MemoryStream`, `BinaryReader`, `BinaryWriter`, and `SHA256` instances","user":{"login":"dougbu","id":6431421,"avatar_url":"https://avatars.githubusercontent.com/u/6431421?v=3","gravatar_id":"","url":"https://api.github.com/users/dougbu","html_url":"https://github.com/dougbu","followers_url":"https://api.github.com/users/dougbu/followers","following_url":"https://api.github.com/users/dougbu/following{/other_user}","gists_url":"https://api.github.com/users/dougbu/gists{/gist_id}","starred_url":"https://api.github.com/users/dougbu/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/dougbu/subscriptions","organizations_url":"https://api.github.com/users/dougbu/orgs","repos_url":"https://api.github.com/users/dougbu/repos","events_url":"https://api.github.com/users/dougbu/events{/privacy}","received_events_url":"https://api.github.com/users/dougbu/received_events","type":"User","site_admin":false},"body":"- #23 part 2\r\n- reduce `byte[]` and `char[]` allocations because all have internal buffers\r\n - fortunately, only `MemoryStream` has an unbounded buffer","created_at":"2016-02-02T22:22:29Z","updated_at":"2016-02-03T00:24:40Z","closed_at":null,"merged_at":null,"merge_commit_sha":"ccebf4dbc959e0517f270c9295e26f101ce2ce87","assignee":null,"milestone":null,"commits_url":"https://api.github.com/repos/aspnet/Antiforgery/pulls/41/commits","review_comments_url":"https://api.github.com/repos/aspnet/Antiforgery/pulls/41/comments","review_comment_url":"https://api.github.com/repos/aspnet/Antiforgery/pulls/comments{/number}","comments_url":"https://api.github.com/repos/aspnet/Antiforgery/issues/41/comments","statuses_url":"https://api.github.com/repos/aspnet/Antiforgery/statuses/a42aea254b0b003edd07cc5ae508097da5174912","head":{"label":"aspnet:dougbu/perf.23","ref":"dougbu/perf.23","sha":"a42aea254b0b003edd07cc5ae508097da5174912","user":{"login":"aspnet","id":6476660,"avatar_url":"https://avatars.githubusercontent.com/u/6476660?v=3","gravatar_id":"","url":"https://api.github.com/users/aspnet","html_url":"https://github.com/aspnet","followers_url":"https://api.github.com/users/aspnet/followers","following_url":"https://api.github.com/users/aspnet/following{/other_user}","gists_url":"https://api.github.com/users/aspnet/gists{/gist_id}","starred_url":"https://api.github.com/users/aspnet/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/aspnet/subscriptions","organizations_url":"https://api.github.com/users/aspnet/orgs","repos_url":"https://api.github.com/users/aspnet/repos","events_url":"https://api.github.com/users/aspnet/events{/privacy}","received_events_url":"https://api.github.com/users/aspnet/received_events","type":"Organization","site_admin":false},"repo":{"id":36972072,"name":"Antiforgery","full_name":"aspnet/Antiforgery","owner":{"login":"aspnet","id":6476660,"avatar_url":"https://avatars.githubusercontent.com/u/6476660?v=3","gravatar_id":"","url":"https://api.github.com/users/aspnet","html_url":"https://github.com/aspnet","followers_url":"https://api.github.com/users/aspnet/followers","following_url":"https://api.github.com/users/aspnet/following{/other_user}","gists_url":"https://api.github.com/users/aspnet/gists{/gist_id}","starred_url":"https://api.github.com/users/aspnet/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/aspnet/subscriptions","organizations_url":"https://api.github.com/users/aspnet/orgs","repos_url":"https://api.github.com/users/aspnet/repos","events_url":"https://api.github.com/users/aspnet/events{/privacy}","received_events_url":"https://api.github.com/users/aspnet/received_events","type":"Organization","site_admin":false},"private":false,"html_url":"https://github.com/aspnet/Antiforgery","description":"AntiForgery token feature for ASP.NET","fork":false,"url":"https://api.github.com/repos/aspnet/Antiforgery","forks_url":"https://api.github.com/repos/aspnet/Antiforgery/forks","keys_url":"https://api.github.com/repos/aspnet/Antiforgery/keys{/key_id}","collaborators_url":"https://api.github.com/repos/aspnet/Antiforgery/collaborators{/collaborator}","teams_url":"https://api.github.com/repos/aspnet/Antiforgery/teams","hooks_url":"https://api.github.com/repos/aspnet/Antiforgery/hooks","issue_events_url":"https://api.github.com/repos/aspnet/Antiforgery/issues/events{/number}","events_url":"https://api.github.com/repos/aspnet/Antiforgery/events","assignees_url":"https://api.github.com/repos/aspnet/Antiforgery/assignees{/user}","branches_url":"https://api.github.com/repos/aspnet/Antiforgery/branches{/branch}","tags_url":"https://api.github.com/repos/aspnet/Antiforgery/tags","blobs_url":"https://api.github.com/repos/aspnet/Antiforgery/git/blobs{/sha}","git_tags_url":"https://api.github.com/repos/aspnet/Antiforgery/git/tags{/sha}","git_refs_url":"https://api.github.com/repos/aspnet/Antiforgery/git/refs{/sha}","trees_url":"https://api.github.com/repos/aspnet/Antiforgery/git/trees{/sha}","statuses_url":"https://api.github.com/repos/aspnet/Antiforgery/statuses/{sha}","languages_url":"https://api.github.com/repos/aspnet/Antiforgery/languages","stargazers_url":"https://api.github.com/repos/aspnet/Antiforgery/stargazers","contributors_url":"https://api.github.com/repos/aspnet/Antiforgery/contributors","subscribers_url":"https://api.github.com/repos/aspnet/Antiforgery/subscribers","subscription_url":"https://api.github.com/repos/aspnet/Antiforgery/subscription","commits_url":"https://api.github.com/repos/aspnet/Antiforgery/commits{/sha}","git_commits_url":"https://api.github.com/repos/aspnet/Antiforgery/git/commits{/sha}","comments_url":"https://api.github.com/repos/aspnet/Antiforgery/comments{/number}","issue_comment_url":"https://api.github.com/repos/aspnet/Antiforgery/issues/comments{/number}","contents_url":"https://api.github.com/repos/aspnet/Antiforgery/contents/{+path}","compare_url":"https://api.github.com/repos/aspnet/Antiforgery/compare/{base}...{head}","merges_url":"https://api.github.com/repos/aspnet/Antiforgery/merges","archive_url":"https://api.github.com/repos/aspnet/Antiforgery/{archive_format}{/ref}","downloads_url":"https://api.github.com/repos/aspnet/Antiforgery/downloads","issues_url":"https://api.github.com/repos/aspnet/Antiforgery/issues{/number}","pulls_url":"https://api.github.com/repos/aspnet/Antiforgery/pulls{/number}","milestones_url":"https://api.github.com/repos/aspnet/Antiforgery/milestones{/number}","notifications_url":"https://api.github.com/repos/aspnet/Antiforgery/notifications{?since,all,participating}","labels_url":"https://api.github.com/repos/aspnet/Antiforgery/labels{/name}","releases_url":"https://api.github.com/repos/aspnet/Antiforgery/releases{/id}","deployments_url":"https://api.github.com/repos/aspnet/Antiforgery/deployments","created_at":"2015-06-06T07:48:28Z","updated_at":"2016-02-02T02:31:02Z","pushed_at":"2016-02-02T22:22:30Z","git_url":"git://github.com/aspnet/Antiforgery.git","ssh_url":"git@github.com:aspnet/Antiforgery.git","clone_url":"https://github.com/aspnet/Antiforgery.git","svn_url":"https://github.com/aspnet/Antiforgery","homepage":"","size":297,"stargazers_count":15,"watchers_count":15,"language":"C#","has_issues":true,"has_downloads":true,"has_wiki":true,"has_pages":false,"forks_count":6,"mirror_url":null,"open_issues_count":5,"forks":6,"open_issues":5,"watchers":15,"default_branch":"dev"}},"base":{"label":"aspnet:dev","ref":"dev","sha":"96063e2476396fab141da8301c48ae379e72711f","user":{"login":"aspnet","id":6476660,"avatar_url":"https://avatars.githubusercontent.com/u/6476660?v=3","gravatar_id":"","url":"https://api.github.com/users/aspnet","html_url":"https://github.com/aspnet","followers_url":"https://api.github.com/users/aspnet/followers","following_url":"https://api.github.com/users/aspnet/following{/other_user}","gists_url":"https://api.github.com/users/aspnet/gists{/gist_id}","starred_url":"https://api.github.com/users/aspnet/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/aspnet/subscriptions","organizations_url":"https://api.github.com/users/aspnet/orgs","repos_url":"https://api.github.com/users/aspnet/repos","events_url":"https://api.github.com/users/aspnet/events{/privacy}","received_events_url":"https://api.github.com/users/aspnet/received_events","type":"Organization","site_admin":false},"repo":{"id":36972072,"name":"Antiforgery","full_name":"aspnet/Antiforgery","owner":{"login":"aspnet","id":6476660,"avatar_url":"https://avatars.githubusercontent.com/u/6476660?v=3","gravatar_id":"","url":"https://api.github.com/users/aspnet","html_url":"https://github.com/aspnet","followers_url":"https://api.github.com/users/aspnet/followers","following_url":"https://api.github.com/users/aspnet/following{/other_user}","gists_url":"https://api.github.com/users/aspnet/gists{/gist_id}","starred_url":"https://api.github.com/users/aspnet/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/aspnet/subscriptions","organizations_url":"https://api.github.com/users/aspnet/orgs","repos_url":"https://api.github.com/users/aspnet/repos","events_url":"https://api.github.com/users/aspnet/events{/privacy}","received_events_url":"https://api.github.com/users/aspnet/received_events","type":"Organization","site_admin":false},"private":false,"html_url":"https://github.com/aspnet/Antiforgery","description":"AntiForgery token feature for ASP.NET","fork":false,"url":"https://api.github.com/repos/aspnet/Antiforgery","forks_url":"https://api.github.com/repos/aspnet/Antiforgery/forks","keys_url":"https://api.github.com/repos/aspnet/Antiforgery/keys{/key_id}","collaborators_url":"https://api.github.com/repos/aspnet/Antiforgery/collaborators{/collaborator}","teams_url":"https://api.github.com/repos/aspnet/Antiforgery/teams","hooks_url":"https://api.github.com/repos/aspnet/Antiforgery/hooks","issue_events_url":"https://api.github.com/repos/aspnet/Antiforgery/issues/events{/number}","events_url":"https://api.github.com/repos/aspnet/Antiforgery/events","assignees_url":"https://api.github.com/repos/aspnet/Antiforgery/assignees{/user}","branches_url":"https://api.github.com/repos/aspnet/Antiforgery/branches{/branch}","tags_url":"https://api.github.com/repos/aspnet/Antiforgery/tags","blobs_url":"https://api.github.com/repos/aspnet/Antiforgery/git/blobs{/sha}","git_tags_url":"https://api.github.com/repos/aspnet/Antiforgery/git/tags{/sha}","git_refs_url":"https://api.github.com/repos/aspnet/Antiforgery/git/refs{/sha}","trees_url":"https://api.github.com/repos/aspnet/Antiforgery/git/trees{/sha}","statuses_url":"https://api.github.com/repos/aspnet/Antiforgery/statuses/{sha}","languages_url":"https://api.github.com/repos/aspnet/Antiforgery/languages","stargazers_url":"https://api.github.com/repos/aspnet/Antiforgery/stargazers","contributors_url":"https://api.github.com/repos/aspnet/Antiforgery/contributors","subscribers_url":"https://api.github.com/repos/aspnet/Antiforgery/subscribers","subscription_url":"https://api.github.com/repos/aspnet/Antiforgery/subscription","commits_url":"https://api.github.com/repos/aspnet/Antiforgery/commits{/sha}","git_commits_url":"https://api.github.com/repos/aspnet/Antiforgery/git/commits{/sha}","comments_url":"https://api.github.com/repos/aspnet/Antiforgery/comments{/number}","issue_comment_url":"https://api.github.com/repos/aspnet/Antiforgery/issues/comments{/number}","contents_url":"https://api.github.com/repos/aspnet/Antiforgery/contents/{+path}","compare_url":"https://api.github.com/repos/aspnet/Antiforgery/compare/{base}...{head}","merges_url":"https://api.github.com/repos/aspnet/Antiforgery/merges","archive_url":"https://api.github.com/repos/aspnet/Antiforgery/{archive_format}{/ref}","downloads_url":"https://api.github.com/repos/aspnet/Antiforgery/downloads","issues_url":"https://api.github.com/repos/aspnet/Antiforgery/issues{/number}","pulls_url":"https://api.github.com/repos/aspnet/Antiforgery/pulls{/number}","milestones_url":"https://api.github.com/repos/aspnet/Antiforgery/milestones{/number}","notifications_url":"https://api.github.com/repos/aspnet/Antiforgery/notifications{?since,all,participating}","labels_url":"https://api.github.com/repos/aspnet/Antiforgery/labels{/name}","releases_url":"https://api.github.com/repos/aspnet/Antiforgery/releases{/id}","deployments_url":"https://api.github.com/repos/aspnet/Antiforgery/deployments","created_at":"2015-06-06T07:48:28Z","updated_at":"2016-02-02T02:31:02Z","pushed_at":"2016-02-02T22:22:30Z","git_url":"git://github.com/aspnet/Antiforgery.git","ssh_url":"git@github.com:aspnet/Antiforgery.git","clone_url":"https://github.com/aspnet/Antiforgery.git","svn_url":"https://github.com/aspnet/Antiforgery","homepage":"","size":297,"stargazers_count":15,"watchers_count":15,"language":"C#","has_issues":true,"has_downloads":true,"has_wiki":true,"has_pages":false,"forks_count":6,"mirror_url":null,"open_issues_count":5,"forks":6,"open_issues":5,"watchers":15,"default_branch":"dev"}},"_links":{"self":{"href":"https://api.github.com/repos/aspnet/Antiforgery/pulls/41"},"html":{"href":"https://github.com/aspnet/Antiforgery/pull/41"},"issue":{"href":"https://api.github.com/repos/aspnet/Antiforgery/issues/41"},"comments":{"href":"https://api.github.com/repos/aspnet/Antiforgery/issues/41/comments"},"review_comments":{"href":"https://api.github.com/repos/aspnet/Antiforgery/pulls/41/comments"},"review_comment":{"href":"https://api.github.com/repos/aspnet/Antiforgery/pulls/comments{/number}"},"commits":{"href":"https://api.github.com/repos/aspnet/Antiforgery/pulls/41/commits"},"statuses":{"href":"https://api.github.com/repos/aspnet/Antiforgery/statuses/a42aea254b0b003edd07cc5ae508097da5174912"}}}}