{"action":"created","issue":{"url":"https://api.github.com/repos/ellismg/coreclr/issues/6","labels_url":"https://api.github.com/repos/ellismg/coreclr/issues/6/labels{/name}","comments_url":"https://api.github.com/repos/ellismg/coreclr/issues/6/comments","events_url":"https://api.github.com/repos/ellismg/coreclr/issues/6/events","html_url":"https://github.com/ellismg/coreclr/pull/6","id":105467313,"number":6,"title":"Don't use StringBuilderCache for casing","user":{"login":"ellismg","id":9602953,"avatar_url":"https://avatars.githubusercontent.com/u/9602953?v=3","gravatar_id":"","url":"https://api.github.com/users/ellismg","html_url":"https://github.com/ellismg","followers_url":"https://api.github.com/users/ellismg/followers","following_url":"https://api.github.com/users/ellismg/following{/other_user}","gists_url":"https://api.github.com/users/ellismg/gists{/gist_id}","starred_url":"https://api.github.com/users/ellismg/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/ellismg/subscriptions","organizations_url":"https://api.github.com/users/ellismg/orgs","repos_url":"https://api.github.com/users/ellismg/repos","events_url":"https://api.github.com/users/ellismg/events{/privacy}","received_events_url":"https://api.github.com/users/ellismg/received_events","type":"User","site_admin":false},"labels":[],"state":"open","locked":false,"assignee":null,"milestone":null,"comments":3,"created_at":"2015-09-08T20:55:36Z","updated_at":"2015-09-08T21:06:28Z","closed_at":null,"pull_request":{"url":"https://api.github.com/repos/ellismg/coreclr/pulls/6","html_url":"https://github.com/ellismg/coreclr/pull/6","diff_url":"https://github.com/ellismg/coreclr/pull/6.diff","patch_url":"https://github.com/ellismg/coreclr/pull/6.patch"},"body":"During code review, Steve proposed we moved to using StringBuilderCache\r\nto the allocation of the temporary char[] array during casing\r\noperations. I made the change but later realized that this caused a few\r\nissues.\r\n\r\n- The native layer operates on UChar/length pairs, not null terminated\r\n  strings.  Because of this, we don't actually write a terminating null\r\n  into the destination buffer (since we just do a 1:1 casing operation\r\n  on the input and never see the null terminator). However, the\r\n  marshalling code for StringBuilder assumes the buffer will be null\r\n  terminated and uses that to compute the new length value after a\r\n  marshalling call. Because there can be left over data from previous\r\n  calls in the buffer the string length calculation will be incorrect\r\n  and we will end up leaking in extra data into the cased string.\r\n\r\n- The StringBuilder marshalling as a whole won't work if we have\r\n  embdedded nulls in a string (we'll end up dropping characters on the\r\n  transition from native back to managed) but that's something that we\r\n  need to be able to handle.\r\n\r\nIdeally there would be a way to construct a mutable string, case into\r\nits buffer and the freeze the string, but we don't have a way to do that\r\ntoday, so we need to stick with this allocation."},"comment":{"url":"https://api.github.com/repos/ellismg/coreclr/issues/comments/138699784","html_url":"https://github.com/ellismg/coreclr/pull/6#issuecomment-138699784","issue_url":"https://api.github.com/repos/ellismg/coreclr/issues/6","id":138699784,"user":{"login":"eerhardt","id":8291187,"avatar_url":"https://avatars.githubusercontent.com/u/8291187?v=3","gravatar_id":"","url":"https://api.github.com/users/eerhardt","html_url":"https://github.com/eerhardt","followers_url":"https://api.github.com/users/eerhardt/followers","following_url":"https://api.github.com/users/eerhardt/following{/other_user}","gists_url":"https://api.github.com/users/eerhardt/gists{/gist_id}","starred_url":"https://api.github.com/users/eerhardt/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/eerhardt/subscriptions","organizations_url":"https://api.github.com/users/eerhardt/orgs","repos_url":"https://api.github.com/users/eerhardt/repos","events_url":"https://api.github.com/users/eerhardt/events{/privacy}","received_events_url":"https://api.github.com/users/eerhardt/received_events","type":"User","site_admin":false},"created_at":"2015-09-08T21:06:28Z","updated_at":"2015-09-08T21:06:28Z","body":"LGTM."}}