{"action":"created","comment":{"url":"https://api.github.com/repos/dotnet/corefxlab/pulls/comments/96707636","pull_request_review_id":17297696,"id":96707636,"diff_hunk":"@@ -7,113 +7,145 @@ namespace System.Text.Utf16\n {\n     class Utf16TextEncodingLE : TextEncoder\n     {\n-        public override bool TryEncodeFromUtf8(ReadOnlySpan<byte> utf8, Span<byte> buffer, out int bytesWritten)\n+        #region Encoding Constants\n+\n+        // TODO: Some of these members are needed only in Utf16LittleEndianEncoder.\n+        //       Should we add the usage of them to UnicodeCodePoint class and merge this class with it?\n+        private const uint Utf16HighSurrogateFirstCodePoint = 0xD800;\n+        private const uint Utf16HighSurrogateLastCodePoint = 0xDFFF;\n+        private const uint Utf16LowSurrogateFirstCodePoint = 0xDC00;\n+        private const uint Utf16LowSurrogateLastCodePoint = 0xDFFF;\n+\n+        private const uint Utf16SurrogateRangeStart = Utf16HighSurrogateFirstCodePoint;\n+        private const uint Utf16SurrogateRangeEnd = Utf16LowSurrogateLastCodePoint;\n+\n+        // To get this to compile with dotnet cli, we need to temporarily un-binary the magic values\n+        private const byte b0000_0111U = 7;\n+        private const byte b0000_1111U = 15;\n+        private const byte b0001_1111U = 31;\n+        private const byte b0011_1111U = 63;\n+        private const byte b0111_1111U = 127;\n+        private const byte b1000_0000U = 128;\n+        private const byte b1100_0000U = 192;\n+        private const byte b1110_0000U = 224;\n+        private const byte b1111_0000U = 240;\n+        private const byte b1111_1000U = 248;\n+\n+        #endregion Encoding Constants\n+\n+        #region Decoding implementation\n+\n+        public override bool TryDecode(ReadOnlySpan<byte> data, out string text, out int bytesConsumed)\n         {\n-            bytesWritten = 0;\n-            int justWritten;\n-            foreach (var cp in new Utf8String(utf8).CodePoints)\n-            {\n-                if (!Utf16LittleEndianEncoder.TryEncodeCodePoint(cp, buffer.Slice(bytesWritten), out justWritten))\n-                {\n-                    bytesWritten = 0;\n-                    return false;\n-                }\n-                bytesWritten += justWritten;\n-            }\n+            var utf16 = data.Cast<byte, char>();","path":"src/System.Text.Primitives/System/Text/Encoding/Utf16/Utf16TextEncodingLE.cs","position":46,"original_position":46,"commit_id":"67c4816e338dfcb2d6cfd7135e71499bb5bbb37e","original_commit_id":"67c4816e338dfcb2d6cfd7135e71499bb5bbb37e","user":{"login":"shiftylogic","id":11233697,"avatar_url":"https://avatars.githubusercontent.com/u/11233697?v=3","gravatar_id":"","url":"https://api.github.com/users/shiftylogic","html_url":"https://github.com/shiftylogic","followers_url":"https://api.github.com/users/shiftylogic/followers","following_url":"https://api.github.com/users/shiftylogic/following{/other_user}","gists_url":"https://api.github.com/users/shiftylogic/gists{/gist_id}","starred_url":"https://api.github.com/users/shiftylogic/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/shiftylogic/subscriptions","organizations_url":"https://api.github.com/users/shiftylogic/orgs","repos_url":"https://api.github.com/users/shiftylogic/repos","events_url":"https://api.github.com/users/shiftylogic/events{/privacy}","received_events_url":"https://api.github.com/users/shiftylogic/received_events","type":"User","site_admin":false},"body":"It is so much easier to work with appropriate sized spans. Do you have a recommendation on what we should do here? For internal implementation, I would really like to cast up to the appropriate size. Also, I suspect optimizations will require the ability to cast as well for reading larger units.\r\n\r\nThoughts?","created_at":"2017-01-18T18:54:37Z","updated_at":"2017-01-18T18:54:37Z","html_url":"https://github.com/dotnet/corefxlab/pull/1132#discussion_r96707636","pull_request_url":"https://api.github.com/repos/dotnet/corefxlab/pulls/1132","_links":{"self":{"href":"https://api.github.com/repos/dotnet/corefxlab/pulls/comments/96707636"},"html":{"href":"https://github.com/dotnet/corefxlab/pull/1132#discussion_r96707636"},"pull_request":{"href":"https://api.github.com/repos/dotnet/corefxlab/pulls/1132"}}},"pull_request":{"url":"https://api.github.com/repos/dotnet/corefxlab/pulls/1132","id":102120253,"html_url":"https://github.com/dotnet/corefxlab/pull/1132","diff_url":"https://github.com/dotnet/corefxlab/pull/1132.diff","patch_url":"https://github.com/dotnet/corefxlab/pull/1132.patch","issue_url":"https://api.github.com/repos/dotnet/corefxlab/issues/1132","number":1132,"state":"open","locked":false,"title":"Redesign of text encoding public surface area","user":{"login":"shiftylogic","id":11233697,"avatar_url":"https://avatars.githubusercontent.com/u/11233697?v=3","gravatar_id":"","url":"https://api.github.com/users/shiftylogic","html_url":"https://github.com/shiftylogic","followers_url":"https://api.github.com/users/shiftylogic/followers","following_url":"https://api.github.com/users/shiftylogic/following{/other_user}","gists_url":"https://api.github.com/users/shiftylogic/gists{/gist_id}","starred_url":"https://api.github.com/users/shiftylogic/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/shiftylogic/subscriptions","organizations_url":"https://api.github.com/users/shiftylogic/orgs","repos_url":"https://api.github.com/users/shiftylogic/repos","events_url":"https://api.github.com/users/shiftylogic/events{/privacy}","received_events_url":"https://api.github.com/users/shiftylogic/received_events","type":"User","site_admin":false},"body":"* Text encoding public API surface proposal.\r\n* Some optimizations to encoding (still a lot of work to do here).\r\n\r\n@KrzysztofCwalina @ahsonkhan ","created_at":"2017-01-18T18:13:42Z","updated_at":"2017-01-18T18:54:37Z","closed_at":null,"merged_at":null,"merge_commit_sha":"eca044e8c0f60b720450d2543a5ef4637d4fc765","assignee":null,"assignees":[],"milestone":null,"commits_url":"https://api.github.com/repos/dotnet/corefxlab/pulls/1132/commits","review_comments_url":"https://api.github.com/repos/dotnet/corefxlab/pulls/1132/comments","review_comment_url":"https://api.github.com/repos/dotnet/corefxlab/pulls/comments{/number}","comments_url":"https://api.github.com/repos/dotnet/corefxlab/issues/1132/comments","statuses_url":"https://api.github.com/repos/dotnet/corefxlab/statuses/67c4816e338dfcb2d6cfd7135e71499bb5bbb37e","head":{"label":"shiftylogic:master","ref":"master","sha":"67c4816e338dfcb2d6cfd7135e71499bb5bbb37e","user":{"login":"shiftylogic","id":11233697,"avatar_url":"https://avatars.githubusercontent.com/u/11233697?v=3","gravatar_id":"","url":"https://api.github.com/users/shiftylogic","html_url":"https://github.com/shiftylogic","followers_url":"https://api.github.com/users/shiftylogic/followers","following_url":"https://api.github.com/users/shiftylogic/following{/other_user}","gists_url":"https://api.github.com/users/shiftylogic/gists{/gist_id}","starred_url":"https://api.github.com/users/shiftylogic/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/shiftylogic/subscriptions","organizations_url":"https://api.github.com/users/shiftylogic/orgs","repos_url":"https://api.github.com/users/shiftylogic/repos","events_url":"https://api.github.com/users/shiftylogic/events{/privacy}","received_events_url":"https://api.github.com/users/shiftylogic/received_events","type":"User","site_admin":false},"repo":{"id":77081499,"name":"corefxlab","full_name":"shiftylogic/corefxlab","owner":{"login":"shiftylogic","id":11233697,"avatar_url":"https://avatars.githubusercontent.com/u/11233697?v=3","gravatar_id":"","url":"https://api.github.com/users/shiftylogic","html_url":"https://github.com/shiftylogic","followers_url":"https://api.github.com/users/shiftylogic/followers","following_url":"https://api.github.com/users/shiftylogic/following{/other_user}","gists_url":"https://api.github.com/users/shiftylogic/gists{/gist_id}","starred_url":"https://api.github.com/users/shiftylogic/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/shiftylogic/subscriptions","organizations_url":"https://api.github.com/users/shiftylogic/orgs","repos_url":"https://api.github.com/users/shiftylogic/repos","events_url":"https://api.github.com/users/shiftylogic/events{/privacy}","received_events_url":"https://api.github.com/users/shiftylogic/received_events","type":"User","site_admin":false},"private":false,"html_url":"https://github.com/shiftylogic/corefxlab","description":"This repo is for experimentation and exploring new ideas that may or may not make it into the main corefx repo.","fork":true,"url":"https://api.github.com/repos/shiftylogic/corefxlab","forks_url":"https://api.github.com/repos/shiftylogic/corefxlab/forks","keys_url":"https://api.github.com/repos/shiftylogic/corefxlab/keys{/key_id}","collaborators_url":"https://api.github.com/repos/shiftylogic/corefxlab/collaborators{/collaborator}","teams_url":"https://api.github.com/repos/shiftylogic/corefxlab/teams","hooks_url":"https://api.github.com/repos/shiftylogic/corefxlab/hooks","issue_events_url":"https://api.github.com/repos/shiftylogic/corefxlab/issues/events{/number}","events_url":"https://api.github.com/repos/shiftylogic/corefxlab/events","assignees_url":"https://api.github.com/repos/shiftylogic/corefxlab/assignees{/user}","branches_url":"https://api.github.com/repos/shiftylogic/corefxlab/branches{/branch}","tags_url":"https://api.github.com/repos/shiftylogic/corefxlab/tags","blobs_url":"https://api.github.com/repos/shiftylogic/corefxlab/git/blobs{/sha}","git_tags_url":"https://api.github.com/repos/shiftylogic/corefxlab/git/tags{/sha}","git_refs_url":"https://api.github.com/repos/shiftylogic/corefxlab/git/refs{/sha}","trees_url":"https://api.github.com/repos/shiftylogic/corefxlab/git/trees{/sha}","statuses_url":"https://api.github.com/repos/shiftylogic/corefxlab/statuses/{sha}","languages_url":"https://api.github.com/repos/shiftylogic/corefxlab/languages","stargazers_url":"https://api.github.com/repos/shiftylogic/corefxlab/stargazers","contributors_url":"https://api.github.com/repos/shiftylogic/corefxlab/contributors","subscribers_url":"https://api.github.com/repos/shiftylogic/corefxlab/subscribers","subscription_url":"https://api.github.com/repos/shiftylogic/corefxlab/subscription","commits_url":"https://api.github.com/repos/shiftylogic/corefxlab/commits{/sha}","git_commits_url":"https://api.github.com/repos/shiftylogic/corefxlab/git/commits{/sha}","comments_url":"https://api.github.com/repos/shiftylogic/corefxlab/comments{/number}","issue_comment_url":"https://api.github.com/repos/shiftylogic/corefxlab/issues/comments{/number}","contents_url":"https://api.github.com/repos/shiftylogic/corefxlab/contents/{+path}","compare_url":"https://api.github.com/repos/shiftylogic/corefxlab/compare/{base}...{head}","merges_url":"https://api.github.com/repos/shiftylogic/corefxlab/merges","archive_url":"https://api.github.com/repos/shiftylogic/corefxlab/{archive_format}{/ref}","downloads_url":"https://api.github.com/repos/shiftylogic/corefxlab/downloads","issues_url":"https://api.github.com/repos/shiftylogic/corefxlab/issues{/number}","pulls_url":"https://api.github.com/repos/shiftylogic/corefxlab/pulls{/number}","milestones_url":"https://api.github.com/repos/shiftylogic/corefxlab/milestones{/number}","notifications_url":"https://api.github.com/repos/shiftylogic/corefxlab/notifications{?since,all,participating}","labels_url":"https://api.github.com/repos/shiftylogic/corefxlab/labels{/name}","releases_url":"https://api.github.com/repos/shiftylogic/corefxlab/releases{/id}","deployments_url":"https://api.github.com/repos/shiftylogic/corefxlab/deployments","created_at":"2016-12-21T19:48:21Z","updated_at":"2016-12-21T19:48:25Z","pushed_at":"2017-01-18T18:26:55Z","git_url":"git://github.com/shiftylogic/corefxlab.git","ssh_url":"git@github.com:shiftylogic/corefxlab.git","clone_url":"https://github.com/shiftylogic/corefxlab.git","svn_url":"https://github.com/shiftylogic/corefxlab","homepage":"","size":31925,"stargazers_count":0,"watchers_count":0,"language":"C#","has_issues":false,"has_downloads":true,"has_wiki":true,"has_pages":false,"forks_count":0,"mirror_url":null,"open_issues_count":0,"forks":0,"open_issues":0,"watchers":0,"default_branch":"master"}},"base":{"label":"dotnet:master","ref":"master","sha":"89b32da3374262778d8e7ff3c28029243cc1ee11","user":{"login":"dotnet","id":9141961,"avatar_url":"https://avatars.githubusercontent.com/u/9141961?v=3","gravatar_id":"","url":"https://api.github.com/users/dotnet","html_url":"https://github.com/dotnet","followers_url":"https://api.github.com/users/dotnet/followers","following_url":"https://api.github.com/users/dotnet/following{/other_user}","gists_url":"https://api.github.com/users/dotnet/gists{/gist_id}","starred_url":"https://api.github.com/users/dotnet/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/dotnet/subscriptions","organizations_url":"https://api.github.com/users/dotnet/orgs","repos_url":"https://api.github.com/users/dotnet/repos","events_url":"https://api.github.com/users/dotnet/events{/privacy}","received_events_url":"https://api.github.com/users/dotnet/received_events","type":"Organization","site_admin":false},"repo":{"id":29504192,"name":"corefxlab","full_name":"dotnet/corefxlab","owner":{"login":"dotnet","id":9141961,"avatar_url":"https://avatars.githubusercontent.com/u/9141961?v=3","gravatar_id":"","url":"https://api.github.com/users/dotnet","html_url":"https://github.com/dotnet","followers_url":"https://api.github.com/users/dotnet/followers","following_url":"https://api.github.com/users/dotnet/following{/other_user}","gists_url":"https://api.github.com/users/dotnet/gists{/gist_id}","starred_url":"https://api.github.com/users/dotnet/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/dotnet/subscriptions","organizations_url":"https://api.github.com/users/dotnet/orgs","repos_url":"https://api.github.com/users/dotnet/repos","events_url":"https://api.github.com/users/dotnet/events{/privacy}","received_events_url":"https://api.github.com/users/dotnet/received_events","type":"Organization","site_admin":false},"private":false,"html_url":"https://github.com/dotnet/corefxlab","description":"This repo is for experimentation and exploring new ideas that may or may not make it into the main corefx repo.","fork":false,"url":"https://api.github.com/repos/dotnet/corefxlab","forks_url":"https://api.github.com/repos/dotnet/corefxlab/forks","keys_url":"https://api.github.com/repos/dotnet/corefxlab/keys{/key_id}","collaborators_url":"https://api.github.com/repos/dotnet/corefxlab/collaborators{/collaborator}","teams_url":"https://api.github.com/repos/dotnet/corefxlab/teams","hooks_url":"https://api.github.com/repos/dotnet/corefxlab/hooks","issue_events_url":"https://api.github.com/repos/dotnet/corefxlab/issues/events{/number}","events_url":"https://api.github.com/repos/dotnet/corefxlab/events","assignees_url":"https://api.github.com/repos/dotnet/corefxlab/assignees{/user}","branches_url":"https://api.github.com/repos/dotnet/corefxlab/branches{/branch}","tags_url":"https://api.github.com/repos/dotnet/corefxlab/tags","blobs_url":"https://api.github.com/repos/dotnet/corefxlab/git/blobs{/sha}","git_tags_url":"https://api.github.com/repos/dotnet/corefxlab/git/tags{/sha}","git_refs_url":"https://api.github.com/repos/dotnet/corefxlab/git/refs{/sha}","trees_url":"https://api.github.com/repos/dotnet/corefxlab/git/trees{/sha}","statuses_url":"https://api.github.com/repos/dotnet/corefxlab/statuses/{sha}","languages_url":"https://api.github.com/repos/dotnet/corefxlab/languages","stargazers_url":"https://api.github.com/repos/dotnet/corefxlab/stargazers","contributors_url":"https://api.github.com/repos/dotnet/corefxlab/contributors","subscribers_url":"https://api.github.com/repos/dotnet/corefxlab/subscribers","subscription_url":"https://api.github.com/repos/dotnet/corefxlab/subscription","commits_url":"https://api.github.com/repos/dotnet/corefxlab/commits{/sha}","git_commits_url":"https://api.github.com/repos/dotnet/corefxlab/git/commits{/sha}","comments_url":"https://api.github.com/repos/dotnet/corefxlab/comments{/number}","issue_comment_url":"https://api.github.com/repos/dotnet/corefxlab/issues/comments{/number}","contents_url":"https://api.github.com/repos/dotnet/corefxlab/contents/{+path}","compare_url":"https://api.github.com/repos/dotnet/corefxlab/compare/{base}...{head}","merges_url":"https://api.github.com/repos/dotnet/corefxlab/merges","archive_url":"https://api.github.com/repos/dotnet/corefxlab/{archive_format}{/ref}","downloads_url":"https://api.github.com/repos/dotnet/corefxlab/downloads","issues_url":"https://api.github.com/repos/dotnet/corefxlab/issues{/number}","pulls_url":"https://api.github.com/repos/dotnet/corefxlab/pulls{/number}","milestones_url":"https://api.github.com/repos/dotnet/corefxlab/milestones{/number}","notifications_url":"https://api.github.com/repos/dotnet/corefxlab/notifications{?since,all,participating}","labels_url":"https://api.github.com/repos/dotnet/corefxlab/labels{/name}","releases_url":"https://api.github.com/repos/dotnet/corefxlab/releases{/id}","deployments_url":"https://api.github.com/repos/dotnet/corefxlab/deployments","created_at":"2015-01-20T00:44:35Z","updated_at":"2017-01-18T18:26:47Z","pushed_at":"2017-01-18T18:54:28Z","git_url":"git://github.com/dotnet/corefxlab.git","ssh_url":"git@github.com:dotnet/corefxlab.git","clone_url":"https://github.com/dotnet/corefxlab.git","svn_url":"https://github.com/dotnet/corefxlab","homepage":"","size":31845,"stargazers_count":583,"watchers_count":583,"language":"C#","has_issues":true,"has_downloads":true,"has_wiki":true,"has_pages":false,"forks_count":176,"mirror_url":null,"open_issues_count":164,"forks":176,"open_issues":164,"watchers":583,"default_branch":"master"}},"_links":{"self":{"href":"https://api.github.com/repos/dotnet/corefxlab/pulls/1132"},"html":{"href":"https://github.com/dotnet/corefxlab/pull/1132"},"issue":{"href":"https://api.github.com/repos/dotnet/corefxlab/issues/1132"},"comments":{"href":"https://api.github.com/repos/dotnet/corefxlab/issues/1132/comments"},"review_comments":{"href":"https://api.github.com/repos/dotnet/corefxlab/pulls/1132/comments"},"review_comment":{"href":"https://api.github.com/repos/dotnet/corefxlab/pulls/comments{/number}"},"commits":{"href":"https://api.github.com/repos/dotnet/corefxlab/pulls/1132/commits"},"statuses":{"href":"https://api.github.com/repos/dotnet/corefxlab/statuses/67c4816e338dfcb2d6cfd7135e71499bb5bbb37e"}}}}
{"actor":{"display_login":"shiftylogic"}}