{"action":"created","comment":{"url":"https://api.github.com/repos/elixir-lang/elixir/pulls/comments/71068912","id":71068912,"diff_hunk":"@@ -1941,39 +1977,46 @@ defmodule Enum do\n \n   \"\"\"\n   @spec slice(t, integer, non_neg_integer) :: list\n+  def slice(enumerable, start, n) when is_integer(start) and is_integer(n) and n >= 0,\n+    do: do_slice(enumerable, start, n)\n \n-  def slice(_enumerable, start, 0) when is_integer(start), do: []\n+  defp do_slice(_enumerable, _start, 0),\n+    do: []\n \n-  def slice(enumerable, start, count)\n-      when is_integer(start) and start < 0 and is_integer(count) and count >= 0 do\n-    {list, new_start} = enumerate_and_count(enumerable, start)\n-    if new_start >= 0 do\n-      slice(list, new_start, count)\n-    else\n-      []\n+  defp do_slice(enumerable, start, n) when start < 0 do\n+    case get_size_index(enumerable, start) do","path":"lib/elixir/lib/enum.ex","position":118,"original_position":118,"commit_id":"2d9fd16e19212d959022becf1e639dc65c9a6acc","original_commit_id":"2d9fd16e19212d959022becf1e639dc65c9a6acc","user":{"login":"josevalim","id":9582,"avatar_url":"https://avatars.githubusercontent.com/u/9582?v=3","gravatar_id":"","url":"https://api.github.com/users/josevalim","html_url":"https://github.com/josevalim","followers_url":"https://api.github.com/users/josevalim/followers","following_url":"https://api.github.com/users/josevalim/following{/other_user}","gists_url":"https://api.github.com/users/josevalim/gists{/gist_id}","starred_url":"https://api.github.com/users/josevalim/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/josevalim/subscriptions","organizations_url":"https://api.github.com/users/josevalim/orgs","repos_url":"https://api.github.com/users/josevalim/repos","events_url":"https://api.github.com/users/josevalim/events{/privacy}","received_events_url":"https://api.github.com/users/josevalim/received_events","type":"User","site_admin":false},"body":"The `do_slice/2` above could be rewritten similarly.","created_at":"2016-07-16T17:04:50Z","updated_at":"2016-07-16T17:04:50Z","html_url":"https://github.com/elixir-lang/elixir/pull/5017#discussion_r71068912","pull_request_url":"https://api.github.com/repos/elixir-lang/elixir/pulls/5017","_links":{"self":{"href":"https://api.github.com/repos/elixir-lang/elixir/pulls/comments/71068912"},"html":{"href":"https://github.com/elixir-lang/elixir/pull/5017#discussion_r71068912"},"pull_request":{"href":"https://api.github.com/repos/elixir-lang/elixir/pulls/5017"}}},"pull_request":{"url":"https://api.github.com/repos/elixir-lang/elixir/pulls/5017","id":77712740,"html_url":"https://github.com/elixir-lang/elixir/pull/5017","diff_url":"https://github.com/elixir-lang/elixir/pull/5017.diff","patch_url":"https://github.com/elixir-lang/elixir/pull/5017.patch","issue_url":"https://api.github.com/repos/elixir-lang/elixir/issues/5017","number":5017,"state":"open","locked":false,"title":"Enum.slice/2 and Enum.slice/3 rewrite","user":{"login":"eksperimental","id":9133420,"avatar_url":"https://avatars.githubusercontent.com/u/9133420?v=3","gravatar_id":"","url":"https://api.github.com/users/eksperimental","html_url":"https://github.com/eksperimental","followers_url":"https://api.github.com/users/eksperimental/followers","following_url":"https://api.github.com/users/eksperimental/following{/other_user}","gists_url":"https://api.github.com/users/eksperimental/gists{/gist_id}","starred_url":"https://api.github.com/users/eksperimental/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/eksperimental/subscriptions","organizations_url":"https://api.github.com/users/eksperimental/orgs","repos_url":"https://api.github.com/users/eksperimental/repos","events_url":"https://api.github.com/users/eksperimental/events{/privacy}","received_events_url":"https://api.github.com/users/eksperimental/received_events","type":"User","site_admin":false},"body":"slice/2,3 have been rewritten changing the approach.\r\nPrevious approach was based on count (now named \"n\") number of elements to be fetched,\r\nand slice/2 would call slice/3.\r\nThis leads to the problem of having to recalculate the amount of elements in the enumerable\r\nwhen dealing with negative indexes.\r\nThe new aproach uses slice/2 as the main funtion, and deal with start and finish indexes.\r\nWhen a negative index is needed, we determine the number of elements, and we convert it to indexes.\r\n\r\nBenchmarks for the new implemetation can be seen here:\r\n\r\nRuning time: https://gist.github.com/eksperimental/e7cda7722d42e43c4c2f69825149c7df#file-enum_slice_benchmarking_report_new-txt-L773\r\n\r\nComparison: https://gist.github.com/eksperimental/e7cda7722d42e43c4c2f69825149c7df#file-enum_slice_benchmarking_report_new-txt-L1540","created_at":"2016-07-16T15:57:03Z","updated_at":"2016-07-16T17:04:50Z","closed_at":null,"merged_at":null,"merge_commit_sha":"e56246d09515ee7490a6447eb78645d3e14b122b","assignee":null,"assignees":[],"milestone":null,"commits_url":"https://api.github.com/repos/elixir-lang/elixir/pulls/5017/commits","review_comments_url":"https://api.github.com/repos/elixir-lang/elixir/pulls/5017/comments","review_comment_url":"https://api.github.com/repos/elixir-lang/elixir/pulls/comments{/number}","comments_url":"https://api.github.com/repos/elixir-lang/elixir/issues/5017/comments","statuses_url":"https://api.github.com/repos/elixir-lang/elixir/statuses/2d9fd16e19212d959022becf1e639dc65c9a6acc","head":{"label":"eksperimental:enum-slice-rewrite","ref":"enum-slice-rewrite","sha":"2d9fd16e19212d959022becf1e639dc65c9a6acc","user":{"login":"eksperimental","id":9133420,"avatar_url":"https://avatars.githubusercontent.com/u/9133420?v=3","gravatar_id":"","url":"https://api.github.com/users/eksperimental","html_url":"https://github.com/eksperimental","followers_url":"https://api.github.com/users/eksperimental/followers","following_url":"https://api.github.com/users/eksperimental/following{/other_user}","gists_url":"https://api.github.com/users/eksperimental/gists{/gist_id}","starred_url":"https://api.github.com/users/eksperimental/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/eksperimental/subscriptions","organizations_url":"https://api.github.com/users/eksperimental/orgs","repos_url":"https://api.github.com/users/eksperimental/repos","events_url":"https://api.github.com/users/eksperimental/events{/privacy}","received_events_url":"https://api.github.com/users/eksperimental/received_events","type":"User","site_admin":false},"repo":{"id":25033185,"name":"elixir","full_name":"eksperimental/elixir","owner":{"login":"eksperimental","id":9133420,"avatar_url":"https://avatars.githubusercontent.com/u/9133420?v=3","gravatar_id":"","url":"https://api.github.com/users/eksperimental","html_url":"https://github.com/eksperimental","followers_url":"https://api.github.com/users/eksperimental/followers","following_url":"https://api.github.com/users/eksperimental/following{/other_user}","gists_url":"https://api.github.com/users/eksperimental/gists{/gist_id}","starred_url":"https://api.github.com/users/eksperimental/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/eksperimental/subscriptions","organizations_url":"https://api.github.com/users/eksperimental/orgs","repos_url":"https://api.github.com/users/eksperimental/repos","events_url":"https://api.github.com/users/eksperimental/events{/privacy}","received_events_url":"https://api.github.com/users/eksperimental/received_events","type":"User","site_admin":false},"private":false,"html_url":"https://github.com/eksperimental/elixir","description":"Elixir is a dynamic, functional language designed for building scalable and maintainable applications","fork":true,"url":"https://api.github.com/repos/eksperimental/elixir","forks_url":"https://api.github.com/repos/eksperimental/elixir/forks","keys_url":"https://api.github.com/repos/eksperimental/elixir/keys{/key_id}","collaborators_url":"https://api.github.com/repos/eksperimental/elixir/collaborators{/collaborator}","teams_url":"https://api.github.com/repos/eksperimental/elixir/teams","hooks_url":"https://api.github.com/repos/eksperimental/elixir/hooks","issue_events_url":"https://api.github.com/repos/eksperimental/elixir/issues/events{/number}","events_url":"https://api.github.com/repos/eksperimental/elixir/events","assignees_url":"https://api.github.com/repos/eksperimental/elixir/assignees{/user}","branches_url":"https://api.github.com/repos/eksperimental/elixir/branches{/branch}","tags_url":"https://api.github.com/repos/eksperimental/elixir/tags","blobs_url":"https://api.github.com/repos/eksperimental/elixir/git/blobs{/sha}","git_tags_url":"https://api.github.com/repos/eksperimental/elixir/git/tags{/sha}","git_refs_url":"https://api.github.com/repos/eksperimental/elixir/git/refs{/sha}","trees_url":"https://api.github.com/repos/eksperimental/elixir/git/trees{/sha}","statuses_url":"https://api.github.com/repos/eksperimental/elixir/statuses/{sha}","languages_url":"https://api.github.com/repos/eksperimental/elixir/languages","stargazers_url":"https://api.github.com/repos/eksperimental/elixir/stargazers","contributors_url":"https://api.github.com/repos/eksperimental/elixir/contributors","subscribers_url":"https://api.github.com/repos/eksperimental/elixir/subscribers","subscription_url":"https://api.github.com/repos/eksperimental/elixir/subscription","commits_url":"https://api.github.com/repos/eksperimental/elixir/commits{/sha}","git_commits_url":"https://api.github.com/repos/eksperimental/elixir/git/commits{/sha}","comments_url":"https://api.github.com/repos/eksperimental/elixir/comments{/number}","issue_comment_url":"https://api.github.com/repos/eksperimental/elixir/issues/comments{/number}","contents_url":"https://api.github.com/repos/eksperimental/elixir/contents/{+path}","compare_url":"https://api.github.com/repos/eksperimental/elixir/compare/{base}...{head}","merges_url":"https://api.github.com/repos/eksperimental/elixir/merges","archive_url":"https://api.github.com/repos/eksperimental/elixir/{archive_format}{/ref}","downloads_url":"https://api.github.com/repos/eksperimental/elixir/downloads","issues_url":"https://api.github.com/repos/eksperimental/elixir/issues{/number}","pulls_url":"https://api.github.com/repos/eksperimental/elixir/pulls{/number}","milestones_url":"https://api.github.com/repos/eksperimental/elixir/milestones{/number}","notifications_url":"https://api.github.com/repos/eksperimental/elixir/notifications{?since,all,participating}","labels_url":"https://api.github.com/repos/eksperimental/elixir/labels{/name}","releases_url":"https://api.github.com/repos/eksperimental/elixir/releases{/id}","deployments_url":"https://api.github.com/repos/eksperimental/elixir/deployments","created_at":"2014-10-10T11:48:55Z","updated_at":"2016-04-07T15:37:38Z","pushed_at":"2016-07-16T16:33:11Z","git_url":"git://github.com/eksperimental/elixir.git","ssh_url":"git@github.com:eksperimental/elixir.git","clone_url":"https://github.com/eksperimental/elixir.git","svn_url":"https://github.com/eksperimental/elixir","homepage":"http://elixir-lang.org/","size":35257,"stargazers_count":0,"watchers_count":0,"language":"Elixir","has_issues":true,"has_downloads":true,"has_wiki":true,"has_pages":false,"forks_count":0,"mirror_url":null,"open_issues_count":4,"forks":0,"open_issues":4,"watchers":0,"default_branch":"master"}},"base":{"label":"elixir-lang:master","ref":"master","sha":"49d12da4dd0ca686bc4b1dcb9699daa5ac6975e0","user":{"login":"elixir-lang","id":1481354,"avatar_url":"https://avatars.githubusercontent.com/u/1481354?v=3","gravatar_id":"","url":"https://api.github.com/users/elixir-lang","html_url":"https://github.com/elixir-lang","followers_url":"https://api.github.com/users/elixir-lang/followers","following_url":"https://api.github.com/users/elixir-lang/following{/other_user}","gists_url":"https://api.github.com/users/elixir-lang/gists{/gist_id}","starred_url":"https://api.github.com/users/elixir-lang/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/elixir-lang/subscriptions","organizations_url":"https://api.github.com/users/elixir-lang/orgs","repos_url":"https://api.github.com/users/elixir-lang/repos","events_url":"https://api.github.com/users/elixir-lang/events{/privacy}","received_events_url":"https://api.github.com/users/elixir-lang/received_events","type":"Organization","site_admin":false},"repo":{"id":1234714,"name":"elixir","full_name":"elixir-lang/elixir","owner":{"login":"elixir-lang","id":1481354,"avatar_url":"https://avatars.githubusercontent.com/u/1481354?v=3","gravatar_id":"","url":"https://api.github.com/users/elixir-lang","html_url":"https://github.com/elixir-lang","followers_url":"https://api.github.com/users/elixir-lang/followers","following_url":"https://api.github.com/users/elixir-lang/following{/other_user}","gists_url":"https://api.github.com/users/elixir-lang/gists{/gist_id}","starred_url":"https://api.github.com/users/elixir-lang/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/elixir-lang/subscriptions","organizations_url":"https://api.github.com/users/elixir-lang/orgs","repos_url":"https://api.github.com/users/elixir-lang/repos","events_url":"https://api.github.com/users/elixir-lang/events{/privacy}","received_events_url":"https://api.github.com/users/elixir-lang/received_events","type":"Organization","site_admin":false},"private":false,"html_url":"https://github.com/elixir-lang/elixir","description":"Elixir is a dynamic, functional language designed for building scalable and maintainable applications","fork":false,"url":"https://api.github.com/repos/elixir-lang/elixir","forks_url":"https://api.github.com/repos/elixir-lang/elixir/forks","keys_url":"https://api.github.com/repos/elixir-lang/elixir/keys{/key_id}","collaborators_url":"https://api.github.com/repos/elixir-lang/elixir/collaborators{/collaborator}","teams_url":"https://api.github.com/repos/elixir-lang/elixir/teams","hooks_url":"https://api.github.com/repos/elixir-lang/elixir/hooks","issue_events_url":"https://api.github.com/repos/elixir-lang/elixir/issues/events{/number}","events_url":"https://api.github.com/repos/elixir-lang/elixir/events","assignees_url":"https://api.github.com/repos/elixir-lang/elixir/assignees{/user}","branches_url":"https://api.github.com/repos/elixir-lang/elixir/branches{/branch}","tags_url":"https://api.github.com/repos/elixir-lang/elixir/tags","blobs_url":"https://api.github.com/repos/elixir-lang/elixir/git/blobs{/sha}","git_tags_url":"https://api.github.com/repos/elixir-lang/elixir/git/tags{/sha}","git_refs_url":"https://api.github.com/repos/elixir-lang/elixir/git/refs{/sha}","trees_url":"https://api.github.com/repos/elixir-lang/elixir/git/trees{/sha}","statuses_url":"https://api.github.com/repos/elixir-lang/elixir/statuses/{sha}","languages_url":"https://api.github.com/repos/elixir-lang/elixir/languages","stargazers_url":"https://api.github.com/repos/elixir-lang/elixir/stargazers","contributors_url":"https://api.github.com/repos/elixir-lang/elixir/contributors","subscribers_url":"https://api.github.com/repos/elixir-lang/elixir/subscribers","subscription_url":"https://api.github.com/repos/elixir-lang/elixir/subscription","commits_url":"https://api.github.com/repos/elixir-lang/elixir/commits{/sha}","git_commits_url":"https://api.github.com/repos/elixir-lang/elixir/git/commits{/sha}","comments_url":"https://api.github.com/repos/elixir-lang/elixir/comments{/number}","issue_comment_url":"https://api.github.com/repos/elixir-lang/elixir/issues/comments{/number}","contents_url":"https://api.github.com/repos/elixir-lang/elixir/contents/{+path}","compare_url":"https://api.github.com/repos/elixir-lang/elixir/compare/{base}...{head}","merges_url":"https://api.github.com/repos/elixir-lang/elixir/merges","archive_url":"https://api.github.com/repos/elixir-lang/elixir/{archive_format}{/ref}","downloads_url":"https://api.github.com/repos/elixir-lang/elixir/downloads","issues_url":"https://api.github.com/repos/elixir-lang/elixir/issues{/number}","pulls_url":"https://api.github.com/repos/elixir-lang/elixir/pulls{/number}","milestones_url":"https://api.github.com/repos/elixir-lang/elixir/milestones{/number}","notifications_url":"https://api.github.com/repos/elixir-lang/elixir/notifications{?since,all,participating}","labels_url":"https://api.github.com/repos/elixir-lang/elixir/labels{/name}","releases_url":"https://api.github.com/repos/elixir-lang/elixir/releases{/id}","deployments_url":"https://api.github.com/repos/elixir-lang/elixir/deployments","created_at":"2011-01-09T08:43:57Z","updated_at":"2016-07-16T16:05:37Z","pushed_at":"2016-07-16T16:33:12Z","git_url":"git://github.com/elixir-lang/elixir.git","ssh_url":"git@github.com:elixir-lang/elixir.git","clone_url":"https://github.com/elixir-lang/elixir.git","svn_url":"https://github.com/elixir-lang/elixir","homepage":"http://elixir-lang.org/","size":44672,"stargazers_count":7607,"watchers_count":7607,"language":"Elixir","has_issues":true,"has_downloads":true,"has_wiki":true,"has_pages":false,"forks_count":1034,"mirror_url":null,"open_issues_count":21,"forks":1034,"open_issues":21,"watchers":7607,"default_branch":"master"}},"_links":{"self":{"href":"https://api.github.com/repos/elixir-lang/elixir/pulls/5017"},"html":{"href":"https://github.com/elixir-lang/elixir/pull/5017"},"issue":{"href":"https://api.github.com/repos/elixir-lang/elixir/issues/5017"},"comments":{"href":"https://api.github.com/repos/elixir-lang/elixir/issues/5017/comments"},"review_comments":{"href":"https://api.github.com/repos/elixir-lang/elixir/pulls/5017/comments"},"review_comment":{"href":"https://api.github.com/repos/elixir-lang/elixir/pulls/comments{/number}"},"commits":{"href":"https://api.github.com/repos/elixir-lang/elixir/pulls/5017/commits"},"statuses":{"href":"https://api.github.com/repos/elixir-lang/elixir/statuses/2d9fd16e19212d959022becf1e639dc65c9a6acc"}}}}
{"actor":{"display_login":"josevalim"}}