{"action":"created","comment":{"url":"https://api.github.com/repos/dotnet/coreclr/pulls/comments/76911337","id":76911337,"diff_hunk":"@@ -3449,36 +3436,37 @@ public static string Concat(params object[] args)\n \n \n         [System.Security.SecuritySafeCritical]  // auto-generated\n-        public static String Concat(String str0, String str1) {\n+        public unsafe static String Concat(String str0, String str1) {\n             Contract.Ensures(Contract.Result<String>() != null);\n             Contract.Ensures(Contract.Result<String>().Length ==\n                 (str0 == null ? 0 : str0.Length) +\n                 (str1 == null ? 0 : str1.Length));\n             Contract.EndContractBlock();\n \n-            if (IsNullOrEmpty(str0)) {\n-                if (IsNullOrEmpty(str1)) {\n-                    return String.Empty;\n-                }\n-                return str1;\n+            if (IsNullOrEmpty(str0))\n+            {\n+                return str1 ?? string.Empty;\n             }\n \n-            if (IsNullOrEmpty(str1)) {\n+            if (IsNullOrEmpty(str1))\n+            {\n                 return str0;\n             }\n \n-            int str0Length = str0.Length;\n-            \n-            String result = FastAllocateString(str0Length + str1.Length);\n-            \n-            FillStringChecked(result, 0,        str0);\n-            FillStringChecked(result, str0Length, str1);\n+            int totalLength = str0.Length + str1.Length;\n+            string result = FastAllocateString(totalLength);","path":"src/mscorlib/src/System/String.cs","position":92,"original_position":92,"commit_id":"c61b9244cd432ceb1c2e4cb428a92c5d84797a43","original_commit_id":"c61b9244cd432ceb1c2e4cb428a92c5d84797a43","user":{"login":"jamesqo","id":9159214,"avatar_url":"https://avatars.githubusercontent.com/u/9159214?v=3","gravatar_id":"","url":"https://api.github.com/users/jamesqo","html_url":"https://github.com/jamesqo","followers_url":"https://api.github.com/users/jamesqo/followers","following_url":"https://api.github.com/users/jamesqo/following{/other_user}","gists_url":"https://api.github.com/users/jamesqo/gists{/gist_id}","starred_url":"https://api.github.com/users/jamesqo/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/jamesqo/subscriptions","organizations_url":"https://api.github.com/users/jamesqo/orgs","repos_url":"https://api.github.com/users/jamesqo/repos","events_url":"https://api.github.com/users/jamesqo/events{/privacy}","received_events_url":"https://api.github.com/users/jamesqo/received_events","type":"User","site_admin":false},"body":"@jkotas, the logic here is so simple though-- basically just adding, very similar to the logic [here](https://github.com/dotnet/coreclr/blob/master/src/mscorlib/src/System/String.Manipulation.cs#L535-L537) for example. We're not making double passes over the array or anything, plus this code is very frequently used unlike `Join`.","created_at":"2016-08-31T01:42:02Z","updated_at":"2016-08-31T01:42:02Z","html_url":"https://github.com/dotnet/coreclr/pull/6789#discussion_r76911337","pull_request_url":"https://api.github.com/repos/dotnet/coreclr/pulls/6789","_links":{"self":{"href":"https://api.github.com/repos/dotnet/coreclr/pulls/comments/76911337"},"html":{"href":"https://github.com/dotnet/coreclr/pull/6789#discussion_r76911337"},"pull_request":{"href":"https://api.github.com/repos/dotnet/coreclr/pulls/6789"}}},"pull_request":{"url":"https://api.github.com/repos/dotnet/coreclr/pulls/6789","id":81767045,"html_url":"https://github.com/dotnet/coreclr/pull/6789","diff_url":"https://github.com/dotnet/coreclr/pull/6789.diff","patch_url":"https://github.com/dotnet/coreclr/pull/6789.patch","issue_url":"https://api.github.com/repos/dotnet/coreclr/issues/6789","number":6789,"state":"open","locked":false,"title":"Remove usages of FillStringChecked from String","user":{"login":"jamesqo","id":9159214,"avatar_url":"https://avatars.githubusercontent.com/u/9159214?v=3","gravatar_id":"","url":"https://api.github.com/users/jamesqo","html_url":"https://github.com/jamesqo","followers_url":"https://api.github.com/users/jamesqo/followers","following_url":"https://api.github.com/users/jamesqo/following{/other_user}","gists_url":"https://api.github.com/users/jamesqo/gists{/gist_id}","starred_url":"https://api.github.com/users/jamesqo/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/jamesqo/subscriptions","organizations_url":"https://api.github.com/users/jamesqo/orgs","repos_url":"https://api.github.com/users/jamesqo/repos","events_url":"https://api.github.com/users/jamesqo/events{/privacy}","received_events_url":"https://api.github.com/users/jamesqo/received_events","type":"User","site_admin":false},"body":"There are some very-frequently called `String.Concat` overloads that call a helper method `FillStringChecked`, which pins both the source/destination strings and does a `wstrcpy`. This is somewhat inefficient since in all of the callers, the destination is the same string (and so the result of `fixed` can be cached), however it's not being cached.\r\n\r\nThis PR introduces a new method `CopyToPointer` and uses that instead. Something that looked like this before:\r\n\r\n```cs\r\nstring result = FastAllocateString(len);\r\n\r\nFillStringChecked(result, pos1, str1);\r\nFillStringChecked(result, pos2, str2);\r\n```\r\n\r\nwill now look like this:\r\n\r\n```cs\r\nstring result = FastAllocateString(len);\r\n\r\nfixed (char* pResult = result)\r\n{\r\n    str1.CopyToPointer(pResult + pos1);\r\n    str2.CopyToPointer(pResult + pos2);\r\n}\r\n```\r\n\r\nThe `fixed` is now done inline in the caller, so the string is pinned only once. The source strings are each individually pinned by `CopyToPointer`.\r\n\r\n## Perf results\r\n\r\n- [`string.Concat(string[])`](https://gist.github.com/jamesqo/b8b778bf4c76dff7e78698e9487cbbc4)\r\n- [`string.Concat(object[])`](https://gist.github.com/jamesqo/f8e70dc79d16c768dbf86bf250577c14)\r\n\r\nIf you look at the timings for length 20/50/100 string arrays, there is a consistent speedup of about 5%. (Take into account the fact that these methods also do a lot of other work, incl. a double pass over the array.)\r\n\r\n<s>I accidentally deleted</s> [Here is](https://gist.github.com/jamesqo/4ccda07f8e2ce06b7392a56d25d466dd) the source code for the `Concat(string, string, ...)`-based overloads, but I still have the results (times are what most frequently appeared):\r\n\r\n| **Method** | **Baseline** | **Experimental**\r\n--- | --- | ---\r\n| Concat(string, string) | ~1.5s | ~1.5s\r\n| Concat(3 strings) | ~2.1s | ~2.0s\r\n| Concat(4 strings) | ~2.8s | ~2.6s\r\n\r\nSo for those overloads there is about a 5-7% speedup.\r\n\r\nI know this isn't that much, especially considering that in the first two tests I used `\"1\"` for all the strings, but IMO the changes aren't too earth-shattering and I took the time to cleanup some of the code.\r\n\r\ncc @jkotas @bbowyersmyth @mikedn \r\n\r\nTests are coming to CoreFX.","created_at":"2016-08-18T07:14:13Z","updated_at":"2016-08-31T01:42:02Z","closed_at":null,"merged_at":null,"merge_commit_sha":"7960697b2cb07fcc3f2685ab8d458b25c67de305","assignee":null,"assignees":[],"milestone":null,"commits_url":"https://api.github.com/repos/dotnet/coreclr/pulls/6789/commits","review_comments_url":"https://api.github.com/repos/dotnet/coreclr/pulls/6789/comments","review_comment_url":"https://api.github.com/repos/dotnet/coreclr/pulls/comments{/number}","comments_url":"https://api.github.com/repos/dotnet/coreclr/issues/6789/comments","statuses_url":"https://api.github.com/repos/dotnet/coreclr/statuses/c61b9244cd432ceb1c2e4cb428a92c5d84797a43","head":{"label":"jamesqo:remove-fillstringchecked","ref":"remove-fillstringchecked","sha":"c61b9244cd432ceb1c2e4cb428a92c5d84797a43","user":{"login":"jamesqo","id":9159214,"avatar_url":"https://avatars.githubusercontent.com/u/9159214?v=3","gravatar_id":"","url":"https://api.github.com/users/jamesqo","html_url":"https://github.com/jamesqo","followers_url":"https://api.github.com/users/jamesqo/followers","following_url":"https://api.github.com/users/jamesqo/following{/other_user}","gists_url":"https://api.github.com/users/jamesqo/gists{/gist_id}","starred_url":"https://api.github.com/users/jamesqo/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/jamesqo/subscriptions","organizations_url":"https://api.github.com/users/jamesqo/orgs","repos_url":"https://api.github.com/users/jamesqo/repos","events_url":"https://api.github.com/users/jamesqo/events{/privacy}","received_events_url":"https://api.github.com/users/jamesqo/received_events","type":"User","site_admin":false},"repo":{"id":37690478,"name":"coreclr","full_name":"jamesqo/coreclr","owner":{"login":"jamesqo","id":9159214,"avatar_url":"https://avatars.githubusercontent.com/u/9159214?v=3","gravatar_id":"","url":"https://api.github.com/users/jamesqo","html_url":"https://github.com/jamesqo","followers_url":"https://api.github.com/users/jamesqo/followers","following_url":"https://api.github.com/users/jamesqo/following{/other_user}","gists_url":"https://api.github.com/users/jamesqo/gists{/gist_id}","starred_url":"https://api.github.com/users/jamesqo/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/jamesqo/subscriptions","organizations_url":"https://api.github.com/users/jamesqo/orgs","repos_url":"https://api.github.com/users/jamesqo/repos","events_url":"https://api.github.com/users/jamesqo/events{/privacy}","received_events_url":"https://api.github.com/users/jamesqo/received_events","type":"User","site_admin":false},"private":false,"html_url":"https://github.com/jamesqo/coreclr","description":"This repo contains the .NET Core runtime, called CoreCLR, and the base library, called mscorlib. It includes the garbage collector, JIT compiler, base .NET data types and many low-level classes.","fork":true,"url":"https://api.github.com/repos/jamesqo/coreclr","forks_url":"https://api.github.com/repos/jamesqo/coreclr/forks","keys_url":"https://api.github.com/repos/jamesqo/coreclr/keys{/key_id}","collaborators_url":"https://api.github.com/repos/jamesqo/coreclr/collaborators{/collaborator}","teams_url":"https://api.github.com/repos/jamesqo/coreclr/teams","hooks_url":"https://api.github.com/repos/jamesqo/coreclr/hooks","issue_events_url":"https://api.github.com/repos/jamesqo/coreclr/issues/events{/number}","events_url":"https://api.github.com/repos/jamesqo/coreclr/events","assignees_url":"https://api.github.com/repos/jamesqo/coreclr/assignees{/user}","branches_url":"https://api.github.com/repos/jamesqo/coreclr/branches{/branch}","tags_url":"https://api.github.com/repos/jamesqo/coreclr/tags","blobs_url":"https://api.github.com/repos/jamesqo/coreclr/git/blobs{/sha}","git_tags_url":"https://api.github.com/repos/jamesqo/coreclr/git/tags{/sha}","git_refs_url":"https://api.github.com/repos/jamesqo/coreclr/git/refs{/sha}","trees_url":"https://api.github.com/repos/jamesqo/coreclr/git/trees{/sha}","statuses_url":"https://api.github.com/repos/jamesqo/coreclr/statuses/{sha}","languages_url":"https://api.github.com/repos/jamesqo/coreclr/languages","stargazers_url":"https://api.github.com/repos/jamesqo/coreclr/stargazers","contributors_url":"https://api.github.com/repos/jamesqo/coreclr/contributors","subscribers_url":"https://api.github.com/repos/jamesqo/coreclr/subscribers","subscription_url":"https://api.github.com/repos/jamesqo/coreclr/subscription","commits_url":"https://api.github.com/repos/jamesqo/coreclr/commits{/sha}","git_commits_url":"https://api.github.com/repos/jamesqo/coreclr/git/commits{/sha}","comments_url":"https://api.github.com/repos/jamesqo/coreclr/comments{/number}","issue_comment_url":"https://api.github.com/repos/jamesqo/coreclr/issues/comments{/number}","contents_url":"https://api.github.com/repos/jamesqo/coreclr/contents/{+path}","compare_url":"https://api.github.com/repos/jamesqo/coreclr/compare/{base}...{head}","merges_url":"https://api.github.com/repos/jamesqo/coreclr/merges","archive_url":"https://api.github.com/repos/jamesqo/coreclr/{archive_format}{/ref}","downloads_url":"https://api.github.com/repos/jamesqo/coreclr/downloads","issues_url":"https://api.github.com/repos/jamesqo/coreclr/issues{/number}","pulls_url":"https://api.github.com/repos/jamesqo/coreclr/pulls{/number}","milestones_url":"https://api.github.com/repos/jamesqo/coreclr/milestones{/number}","notifications_url":"https://api.github.com/repos/jamesqo/coreclr/notifications{?since,all,participating}","labels_url":"https://api.github.com/repos/jamesqo/coreclr/labels{/name}","releases_url":"https://api.github.com/repos/jamesqo/coreclr/releases{/id}","deployments_url":"https://api.github.com/repos/jamesqo/coreclr/deployments","created_at":"2015-06-18T23:12:00Z","updated_at":"2016-07-30T03:18:02Z","pushed_at":"2016-08-30T23:15:27Z","git_url":"git://github.com/jamesqo/coreclr.git","ssh_url":"git@github.com:jamesqo/coreclr.git","clone_url":"https://github.com/jamesqo/coreclr.git","svn_url":"https://github.com/jamesqo/coreclr","homepage":"http://dotnet.github.io/core/","size":101875,"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":"473d6f1e7e30b56aaa7677da45163bc567210a62","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":30092893,"name":"coreclr","full_name":"dotnet/coreclr","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/coreclr","description":"This repo contains the .NET Core runtime, called CoreCLR, and the base library, called mscorlib. It includes the garbage collector, JIT compiler, base .NET data types and many low-level classes.","fork":false,"url":"https://api.github.com/repos/dotnet/coreclr","forks_url":"https://api.github.com/repos/dotnet/coreclr/forks","keys_url":"https://api.github.com/repos/dotnet/coreclr/keys{/key_id}","collaborators_url":"https://api.github.com/repos/dotnet/coreclr/collaborators{/collaborator}","teams_url":"https://api.github.com/repos/dotnet/coreclr/teams","hooks_url":"https://api.github.com/repos/dotnet/coreclr/hooks","issue_events_url":"https://api.github.com/repos/dotnet/coreclr/issues/events{/number}","events_url":"https://api.github.com/repos/dotnet/coreclr/events","assignees_url":"https://api.github.com/repos/dotnet/coreclr/assignees{/user}","branches_url":"https://api.github.com/repos/dotnet/coreclr/branches{/branch}","tags_url":"https://api.github.com/repos/dotnet/coreclr/tags","blobs_url":"https://api.github.com/repos/dotnet/coreclr/git/blobs{/sha}","git_tags_url":"https://api.github.com/repos/dotnet/coreclr/git/tags{/sha}","git_refs_url":"https://api.github.com/repos/dotnet/coreclr/git/refs{/sha}","trees_url":"https://api.github.com/repos/dotnet/coreclr/git/trees{/sha}","statuses_url":"https://api.github.com/repos/dotnet/coreclr/statuses/{sha}","languages_url":"https://api.github.com/repos/dotnet/coreclr/languages","stargazers_url":"https://api.github.com/repos/dotnet/coreclr/stargazers","contributors_url":"https://api.github.com/repos/dotnet/coreclr/contributors","subscribers_url":"https://api.github.com/repos/dotnet/coreclr/subscribers","subscription_url":"https://api.github.com/repos/dotnet/coreclr/subscription","commits_url":"https://api.github.com/repos/dotnet/coreclr/commits{/sha}","git_commits_url":"https://api.github.com/repos/dotnet/coreclr/git/commits{/sha}","comments_url":"https://api.github.com/repos/dotnet/coreclr/comments{/number}","issue_comment_url":"https://api.github.com/repos/dotnet/coreclr/issues/comments{/number}","contents_url":"https://api.github.com/repos/dotnet/coreclr/contents/{+path}","compare_url":"https://api.github.com/repos/dotnet/coreclr/compare/{base}...{head}","merges_url":"https://api.github.com/repos/dotnet/coreclr/merges","archive_url":"https://api.github.com/repos/dotnet/coreclr/{archive_format}{/ref}","downloads_url":"https://api.github.com/repos/dotnet/coreclr/downloads","issues_url":"https://api.github.com/repos/dotnet/coreclr/issues{/number}","pulls_url":"https://api.github.com/repos/dotnet/coreclr/pulls{/number}","milestones_url":"https://api.github.com/repos/dotnet/coreclr/milestones{/number}","notifications_url":"https://api.github.com/repos/dotnet/coreclr/notifications{?since,all,participating}","labels_url":"https://api.github.com/repos/dotnet/coreclr/labels{/name}","releases_url":"https://api.github.com/repos/dotnet/coreclr/releases{/id}","deployments_url":"https://api.github.com/repos/dotnet/coreclr/deployments","created_at":"2015-01-30T22:10:02Z","updated_at":"2016-08-30T20:55:33Z","pushed_at":"2016-08-31T01:28:37Z","git_url":"git://github.com/dotnet/coreclr.git","ssh_url":"git@github.com:dotnet/coreclr.git","clone_url":"https://github.com/dotnet/coreclr.git","svn_url":"https://github.com/dotnet/coreclr","homepage":"https://docs.microsoft.com/dotnet/","size":116334,"stargazers_count":6842,"watchers_count":6842,"language":"C#","has_issues":true,"has_downloads":true,"has_wiki":true,"has_pages":false,"forks_count":1622,"mirror_url":null,"open_issues_count":956,"forks":1622,"open_issues":956,"watchers":6842,"default_branch":"master"}},"_links":{"self":{"href":"https://api.github.com/repos/dotnet/coreclr/pulls/6789"},"html":{"href":"https://github.com/dotnet/coreclr/pull/6789"},"issue":{"href":"https://api.github.com/repos/dotnet/coreclr/issues/6789"},"comments":{"href":"https://api.github.com/repos/dotnet/coreclr/issues/6789/comments"},"review_comments":{"href":"https://api.github.com/repos/dotnet/coreclr/pulls/6789/comments"},"review_comment":{"href":"https://api.github.com/repos/dotnet/coreclr/pulls/comments{/number}"},"commits":{"href":"https://api.github.com/repos/dotnet/coreclr/pulls/6789/commits"},"statuses":{"href":"https://api.github.com/repos/dotnet/coreclr/statuses/c61b9244cd432ceb1c2e4cb428a92c5d84797a43"}}}}
{"actor":{"display_login":"jamesqo"}}