{"action":"created","comment":{"url":"https://api.github.com/repos/bbatsov/rubocop/pulls/comments/37537872","id":37537872,"diff_hunk":"@@ -0,0 +1,132 @@\n+# encoding: utf-8\n+\n+module RuboCop\n+  module Cop\n+    module Performance\n+      # Place `when` conditions that use splat at the end\n+      # of the list of `when` branches.\n+      #\n+      # Ruby has to allocate memory for the splat expansion every time\n+      # that the `case` `when` statement is run. Since Ruby does not support\n+      # fall through inside of `case` `when`, like some other languages do,\n+      # the order of the `when` branches does not matter. By ordering any\n+      # splat expansions at the end of the list of `when` branches we will\n+      # reduce the number of times that memory has to be allocated for\n+      # the expansion.\n+      #\n+      # This is not a guaranteed performance improvement. If the data being\n+      # processed by the `case` condition is normalized in a manor that favors\n+      # hitting a condition in the splat expansion, it is possible that the","path":"lib/rubocop/cop/performance/case_when_splat.rb","position":19,"original_position":19,"commit_id":"1585ae1f3b92b624c02419d95e2a28d498b126f8","original_commit_id":"1585ae1f3b92b624c02419d95e2a28d498b126f8","user":{"login":"bbatsov","id":103882,"avatar_url":"https://avatars.githubusercontent.com/u/103882?v=3","gravatar_id":"","url":"https://api.github.com/users/bbatsov","html_url":"https://github.com/bbatsov","followers_url":"https://api.github.com/users/bbatsov/followers","following_url":"https://api.github.com/users/bbatsov/following{/other_user}","gists_url":"https://api.github.com/users/bbatsov/gists{/gist_id}","starred_url":"https://api.github.com/users/bbatsov/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/bbatsov/subscriptions","organizations_url":"https://api.github.com/users/bbatsov/orgs","repos_url":"https://api.github.com/users/bbatsov/repos","events_url":"https://api.github.com/users/bbatsov/events{/privacy}","received_events_url":"https://api.github.com/users/bbatsov/received_events","type":"User","site_admin":false},"body":"that the -> that","created_at":"2015-08-20T14:50:14Z","updated_at":"2015-08-20T14:50:14Z","html_url":"https://github.com/bbatsov/rubocop/pull/2143#discussion_r37537872","pull_request_url":"https://api.github.com/repos/bbatsov/rubocop/pulls/2143","_links":{"self":{"href":"https://api.github.com/repos/bbatsov/rubocop/pulls/comments/37537872"},"html":{"href":"https://github.com/bbatsov/rubocop/pull/2143#discussion_r37537872"},"pull_request":{"href":"https://api.github.com/repos/bbatsov/rubocop/pulls/2143"}}},"pull_request":{"url":"https://api.github.com/repos/bbatsov/rubocop/pulls/2143","id":42420505,"html_url":"https://github.com/bbatsov/rubocop/pull/2143","diff_url":"https://github.com/bbatsov/rubocop/pull/2143.diff","patch_url":"https://github.com/bbatsov/rubocop/pull/2143.patch","issue_url":"https://api.github.com/repos/bbatsov/rubocop/issues/2143","number":2143,"state":"open","locked":false,"title":"Case when splat","user":{"login":"rrosenblum","id":1528852,"avatar_url":"https://avatars.githubusercontent.com/u/1528852?v=3","gravatar_id":"","url":"https://api.github.com/users/rrosenblum","html_url":"https://github.com/rrosenblum","followers_url":"https://api.github.com/users/rrosenblum/followers","following_url":"https://api.github.com/users/rrosenblum/following{/other_user}","gists_url":"https://api.github.com/users/rrosenblum/gists{/gist_id}","starred_url":"https://api.github.com/users/rrosenblum/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/rrosenblum/subscriptions","organizations_url":"https://api.github.com/users/rrosenblum/orgs","repos_url":"https://api.github.com/users/rrosenblum/repos","events_url":"https://api.github.com/users/rrosenblum/events{/privacy}","received_events_url":"https://api.github.com/users/rrosenblum/received_events","type":"User","site_admin":false},"body":"This is part 1 of memory performance improvements.\r\n\r\nThere is a slight risk in the auto-correct. If more than one `when` condition could apply to the same input, and the earlier condition is used as a short circuiting, then auto-correct could change the code to do the wrong thing. I do not think this is a large concern. If somebody thinks otherwise, I will gladly disable auto-correct by default. I also wasn't sure if I should document this risk inside of the description, class, or not at all.\r\n\r\nExample\r\n```ruby\r\ncase foo\r\nwhen 2\r\n  puts 'special'\r\nwhen *[2, 4, 6]\r\n  puts 'even'\r\nend\r\n\r\n# auto-corrected\r\ncase foo\r\nwhen *[2, 4, 6]\r\n  puts 'even'\r\nwhen 2\r\n  puts 'special'\r\nend\r\n```\r\n\r\nWhile running [memory_profiler](https://github.com/SamSaffron/memory_profiler) on RuboCop. The sample for the data came from running RuboCop against `lib/rubocop/cop/performance`, `lib/rubocop/cop/rails`, and `lib/rubocop/cop/lint`. I could not sample running against the entire project because of the time and resources needed to analyze that much memory.\r\n\r\nTotal memory consumption dropped by about 2%\r\nThe memory allocation for `variable_force.rb` dropped by 30%.\r\nThere was little impact on `locatable.rb`, and `safe_assignment.rb` didn't fall into the top 50 most memory consuming files.","created_at":"2015-08-14T03:06:23Z","updated_at":"2015-08-20T14:50:15Z","closed_at":null,"merged_at":null,"merge_commit_sha":"fccdfcce9a68d66781d81c9651dc773a5397d377","assignee":null,"milestone":null,"commits_url":"https://api.github.com/repos/bbatsov/rubocop/pulls/2143/commits","review_comments_url":"https://api.github.com/repos/bbatsov/rubocop/pulls/2143/comments","review_comment_url":"https://api.github.com/repos/bbatsov/rubocop/pulls/comments{/number}","comments_url":"https://api.github.com/repos/bbatsov/rubocop/issues/2143/comments","statuses_url":"https://api.github.com/repos/bbatsov/rubocop/statuses/1585ae1f3b92b624c02419d95e2a28d498b126f8","head":{"label":"rrosenblum:case_when_splat","ref":"case_when_splat","sha":"1585ae1f3b92b624c02419d95e2a28d498b126f8","user":{"login":"rrosenblum","id":1528852,"avatar_url":"https://avatars.githubusercontent.com/u/1528852?v=3","gravatar_id":"","url":"https://api.github.com/users/rrosenblum","html_url":"https://github.com/rrosenblum","followers_url":"https://api.github.com/users/rrosenblum/followers","following_url":"https://api.github.com/users/rrosenblum/following{/other_user}","gists_url":"https://api.github.com/users/rrosenblum/gists{/gist_id}","starred_url":"https://api.github.com/users/rrosenblum/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/rrosenblum/subscriptions","organizations_url":"https://api.github.com/users/rrosenblum/orgs","repos_url":"https://api.github.com/users/rrosenblum/repos","events_url":"https://api.github.com/users/rrosenblum/events{/privacy}","received_events_url":"https://api.github.com/users/rrosenblum/received_events","type":"User","site_admin":false},"repo":{"id":28112474,"name":"rubocop","full_name":"rrosenblum/rubocop","owner":{"login":"rrosenblum","id":1528852,"avatar_url":"https://avatars.githubusercontent.com/u/1528852?v=3","gravatar_id":"","url":"https://api.github.com/users/rrosenblum","html_url":"https://github.com/rrosenblum","followers_url":"https://api.github.com/users/rrosenblum/followers","following_url":"https://api.github.com/users/rrosenblum/following{/other_user}","gists_url":"https://api.github.com/users/rrosenblum/gists{/gist_id}","starred_url":"https://api.github.com/users/rrosenblum/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/rrosenblum/subscriptions","organizations_url":"https://api.github.com/users/rrosenblum/orgs","repos_url":"https://api.github.com/users/rrosenblum/repos","events_url":"https://api.github.com/users/rrosenblum/events{/privacy}","received_events_url":"https://api.github.com/users/rrosenblum/received_events","type":"User","site_admin":false},"private":false,"html_url":"https://github.com/rrosenblum/rubocop","description":"A Ruby static code analyzer, based on the community Ruby style guide.","fork":true,"url":"https://api.github.com/repos/rrosenblum/rubocop","forks_url":"https://api.github.com/repos/rrosenblum/rubocop/forks","keys_url":"https://api.github.com/repos/rrosenblum/rubocop/keys{/key_id}","collaborators_url":"https://api.github.com/repos/rrosenblum/rubocop/collaborators{/collaborator}","teams_url":"https://api.github.com/repos/rrosenblum/rubocop/teams","hooks_url":"https://api.github.com/repos/rrosenblum/rubocop/hooks","issue_events_url":"https://api.github.com/repos/rrosenblum/rubocop/issues/events{/number}","events_url":"https://api.github.com/repos/rrosenblum/rubocop/events","assignees_url":"https://api.github.com/repos/rrosenblum/rubocop/assignees{/user}","branches_url":"https://api.github.com/repos/rrosenblum/rubocop/branches{/branch}","tags_url":"https://api.github.com/repos/rrosenblum/rubocop/tags","blobs_url":"https://api.github.com/repos/rrosenblum/rubocop/git/blobs{/sha}","git_tags_url":"https://api.github.com/repos/rrosenblum/rubocop/git/tags{/sha}","git_refs_url":"https://api.github.com/repos/rrosenblum/rubocop/git/refs{/sha}","trees_url":"https://api.github.com/repos/rrosenblum/rubocop/git/trees{/sha}","statuses_url":"https://api.github.com/repos/rrosenblum/rubocop/statuses/{sha}","languages_url":"https://api.github.com/repos/rrosenblum/rubocop/languages","stargazers_url":"https://api.github.com/repos/rrosenblum/rubocop/stargazers","contributors_url":"https://api.github.com/repos/rrosenblum/rubocop/contributors","subscribers_url":"https://api.github.com/repos/rrosenblum/rubocop/subscribers","subscription_url":"https://api.github.com/repos/rrosenblum/rubocop/subscription","commits_url":"https://api.github.com/repos/rrosenblum/rubocop/commits{/sha}","git_commits_url":"https://api.github.com/repos/rrosenblum/rubocop/git/commits{/sha}","comments_url":"https://api.github.com/repos/rrosenblum/rubocop/comments{/number}","issue_comment_url":"https://api.github.com/repos/rrosenblum/rubocop/issues/comments{/number}","contents_url":"https://api.github.com/repos/rrosenblum/rubocop/contents/{+path}","compare_url":"https://api.github.com/repos/rrosenblum/rubocop/compare/{base}...{head}","merges_url":"https://api.github.com/repos/rrosenblum/rubocop/merges","archive_url":"https://api.github.com/repos/rrosenblum/rubocop/{archive_format}{/ref}","downloads_url":"https://api.github.com/repos/rrosenblum/rubocop/downloads","issues_url":"https://api.github.com/repos/rrosenblum/rubocop/issues{/number}","pulls_url":"https://api.github.com/repos/rrosenblum/rubocop/pulls{/number}","milestones_url":"https://api.github.com/repos/rrosenblum/rubocop/milestones{/number}","notifications_url":"https://api.github.com/repos/rrosenblum/rubocop/notifications{?since,all,participating}","labels_url":"https://api.github.com/repos/rrosenblum/rubocop/labels{/name}","releases_url":"https://api.github.com/repos/rrosenblum/rubocop/releases{/id}","created_at":"2014-12-16T23:54:29Z","updated_at":"2015-05-06T15:38:55Z","pushed_at":"2015-08-20T12:29:38Z","git_url":"git://github.com/rrosenblum/rubocop.git","ssh_url":"git@github.com:rrosenblum/rubocop.git","clone_url":"https://github.com/rrosenblum/rubocop.git","svn_url":"https://github.com/rrosenblum/rubocop","homepage":"","size":10771,"stargazers_count":0,"watchers_count":0,"language":"Ruby","has_issues":false,"has_downloads":true,"has_wiki":true,"has_pages":true,"forks_count":0,"mirror_url":null,"open_issues_count":0,"forks":0,"open_issues":0,"watchers":0,"default_branch":"master"}},"base":{"label":"bbatsov:master","ref":"master","sha":"fd56bf5c72030f6c2f1ea5072b18a55501a79f68","user":{"login":"bbatsov","id":103882,"avatar_url":"https://avatars.githubusercontent.com/u/103882?v=3","gravatar_id":"","url":"https://api.github.com/users/bbatsov","html_url":"https://github.com/bbatsov","followers_url":"https://api.github.com/users/bbatsov/followers","following_url":"https://api.github.com/users/bbatsov/following{/other_user}","gists_url":"https://api.github.com/users/bbatsov/gists{/gist_id}","starred_url":"https://api.github.com/users/bbatsov/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/bbatsov/subscriptions","organizations_url":"https://api.github.com/users/bbatsov/orgs","repos_url":"https://api.github.com/users/bbatsov/repos","events_url":"https://api.github.com/users/bbatsov/events{/privacy}","received_events_url":"https://api.github.com/users/bbatsov/received_events","type":"User","site_admin":false},"repo":{"id":4095287,"name":"rubocop","full_name":"bbatsov/rubocop","owner":{"login":"bbatsov","id":103882,"avatar_url":"https://avatars.githubusercontent.com/u/103882?v=3","gravatar_id":"","url":"https://api.github.com/users/bbatsov","html_url":"https://github.com/bbatsov","followers_url":"https://api.github.com/users/bbatsov/followers","following_url":"https://api.github.com/users/bbatsov/following{/other_user}","gists_url":"https://api.github.com/users/bbatsov/gists{/gist_id}","starred_url":"https://api.github.com/users/bbatsov/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/bbatsov/subscriptions","organizations_url":"https://api.github.com/users/bbatsov/orgs","repos_url":"https://api.github.com/users/bbatsov/repos","events_url":"https://api.github.com/users/bbatsov/events{/privacy}","received_events_url":"https://api.github.com/users/bbatsov/received_events","type":"User","site_admin":false},"private":false,"html_url":"https://github.com/bbatsov/rubocop","description":"A Ruby static code analyzer, based on the community Ruby style guide.","fork":false,"url":"https://api.github.com/repos/bbatsov/rubocop","forks_url":"https://api.github.com/repos/bbatsov/rubocop/forks","keys_url":"https://api.github.com/repos/bbatsov/rubocop/keys{/key_id}","collaborators_url":"https://api.github.com/repos/bbatsov/rubocop/collaborators{/collaborator}","teams_url":"https://api.github.com/repos/bbatsov/rubocop/teams","hooks_url":"https://api.github.com/repos/bbatsov/rubocop/hooks","issue_events_url":"https://api.github.com/repos/bbatsov/rubocop/issues/events{/number}","events_url":"https://api.github.com/repos/bbatsov/rubocop/events","assignees_url":"https://api.github.com/repos/bbatsov/rubocop/assignees{/user}","branches_url":"https://api.github.com/repos/bbatsov/rubocop/branches{/branch}","tags_url":"https://api.github.com/repos/bbatsov/rubocop/tags","blobs_url":"https://api.github.com/repos/bbatsov/rubocop/git/blobs{/sha}","git_tags_url":"https://api.github.com/repos/bbatsov/rubocop/git/tags{/sha}","git_refs_url":"https://api.github.com/repos/bbatsov/rubocop/git/refs{/sha}","trees_url":"https://api.github.com/repos/bbatsov/rubocop/git/trees{/sha}","statuses_url":"https://api.github.com/repos/bbatsov/rubocop/statuses/{sha}","languages_url":"https://api.github.com/repos/bbatsov/rubocop/languages","stargazers_url":"https://api.github.com/repos/bbatsov/rubocop/stargazers","contributors_url":"https://api.github.com/repos/bbatsov/rubocop/contributors","subscribers_url":"https://api.github.com/repos/bbatsov/rubocop/subscribers","subscription_url":"https://api.github.com/repos/bbatsov/rubocop/subscription","commits_url":"https://api.github.com/repos/bbatsov/rubocop/commits{/sha}","git_commits_url":"https://api.github.com/repos/bbatsov/rubocop/git/commits{/sha}","comments_url":"https://api.github.com/repos/bbatsov/rubocop/comments{/number}","issue_comment_url":"https://api.github.com/repos/bbatsov/rubocop/issues/comments{/number}","contents_url":"https://api.github.com/repos/bbatsov/rubocop/contents/{+path}","compare_url":"https://api.github.com/repos/bbatsov/rubocop/compare/{base}...{head}","merges_url":"https://api.github.com/repos/bbatsov/rubocop/merges","archive_url":"https://api.github.com/repos/bbatsov/rubocop/{archive_format}{/ref}","downloads_url":"https://api.github.com/repos/bbatsov/rubocop/downloads","issues_url":"https://api.github.com/repos/bbatsov/rubocop/issues{/number}","pulls_url":"https://api.github.com/repos/bbatsov/rubocop/pulls{/number}","milestones_url":"https://api.github.com/repos/bbatsov/rubocop/milestones{/number}","notifications_url":"https://api.github.com/repos/bbatsov/rubocop/notifications{?since,all,participating}","labels_url":"https://api.github.com/repos/bbatsov/rubocop/labels{/name}","releases_url":"https://api.github.com/repos/bbatsov/rubocop/releases{/id}","created_at":"2012-04-21T10:09:58Z","updated_at":"2015-08-20T02:30:59Z","pushed_at":"2015-08-20T13:21:50Z","git_url":"git://github.com/bbatsov/rubocop.git","ssh_url":"git@github.com:bbatsov/rubocop.git","clone_url":"https://github.com/bbatsov/rubocop.git","svn_url":"https://github.com/bbatsov/rubocop","homepage":"","size":21420,"stargazers_count":4972,"watchers_count":4972,"language":"Ruby","has_issues":true,"has_downloads":true,"has_wiki":true,"has_pages":true,"forks_count":566,"mirror_url":null,"open_issues_count":111,"forks":566,"open_issues":111,"watchers":4972,"default_branch":"master"}},"_links":{"self":{"href":"https://api.github.com/repos/bbatsov/rubocop/pulls/2143"},"html":{"href":"https://github.com/bbatsov/rubocop/pull/2143"},"issue":{"href":"https://api.github.com/repos/bbatsov/rubocop/issues/2143"},"comments":{"href":"https://api.github.com/repos/bbatsov/rubocop/issues/2143/comments"},"review_comments":{"href":"https://api.github.com/repos/bbatsov/rubocop/pulls/2143/comments"},"review_comment":{"href":"https://api.github.com/repos/bbatsov/rubocop/pulls/comments{/number}"},"commits":{"href":"https://api.github.com/repos/bbatsov/rubocop/pulls/2143/commits"},"statuses":{"href":"https://api.github.com/repos/bbatsov/rubocop/statuses/1585ae1f3b92b624c02419d95e2a28d498b126f8"}}}}