{"action":"created","comment":{"url":"https://api.github.com/repos/rust-lang/rust/pulls/comments/225010521","pull_request_review_id":164516368,"id":225010521,"node_id":"MDI0OlB1bGxSZXF1ZXN0UmV2aWV3Q29tbWVudDIyNTAxMDUyMQ==","diff_hunk":"@@ -2074,6 +2074,85 @@ impl<T> [T] {\n              from_raw_parts_mut(mut_ptr.add(rest.len() - ts_len), ts_len))\n         }\n     }\n+\n+    /// Checks if the elements of this slice are sorted.\n+    ///\n+    /// That is, for each element `a` and its following element `b`, `a <= b` must hold. If the\n+    /// slice yields exactly zero or one element, `true` is returned.\n+    ///\n+    /// Note that if `Self::Item` is only `PartialOrd`, but not `Ord`, the above definition\n+    /// implies that this function returns `false` if any two consecutive items are not\n+    /// comparable.\n+    ///\n+    /// # Examples\n+    ///\n+    /// ```\n+    /// #![feature(is_sorted)]\n+    /// let empty: [i32; 0] = [];\n+    ///\n+    /// assert!([1, 2, 2, 9].is_sorted());\n+    /// assert!(![1, 3, 2, 4].is_sorted());\n+    /// assert!([0].is_sorted());\n+    /// assert!(empty.is_sorted());\n+    /// assert!(![0.0, 1.0, std::f32::NAN].is_sorted());\n+    /// ```\n+    #[inline]\n+    #[unstable(feature = \"is_sorted\", reason = \"new API\", issue = \"53485\")]\n+    pub fn is_sorted(&self) -> bool\n+    where\n+        T: PartialOrd,\n+    {\n+        self.is_sorted_by(|a, b| a.partial_cmp(b))\n+    }\n+\n+    /// Checks if the elements of this slice are sorted using the given comparator function.\n+    ///\n+    /// Instead of using `PartialOrd::partial_cmp`, this function uses the given `compare`\n+    /// function to determine the ordering of two elements. Apart from that, it's equivalent to\n+    /// `is_sorted`; see its documentation for more information.\n+    #[unstable(feature = \"is_sorted\", reason = \"new API\", issue = \"53485\")]\n+    pub fn is_sorted_by<F>(&self, mut compare: F) -> bool\n+    where\n+        F: FnMut(&T, &T) -> Option<Ordering>\n+    {\n+        let mut last = match self.first() {\n+            Some(e) => e,\n+            None => return true,\n+        };\n+\n+        for curr in &self[1..] {\n+            if compare(&last, &curr).map(|o| o == Ordering::Greater).unwrap_or(true) {\n+                return false;\n+            }\n+            last = &curr;\n+        }","path":"src/libcore/slice/mod.rs","position":65,"original_position":64,"commit_id":"b5ab524ea7b536617d8abc5507a1d97b3e60a42d","original_commit_id":"601e6578b1ae04f7dfb6c733100fe173e323f827","user":{"login":"LukasKalbertodt","id":7419664,"node_id":"MDQ6VXNlcjc0MTk2NjQ=","avatar_url":"https://avatars1.githubusercontent.com/u/7419664?v=4","gravatar_id":"","url":"https://api.github.com/users/LukasKalbertodt","html_url":"https://github.com/LukasKalbertodt","followers_url":"https://api.github.com/users/LukasKalbertodt/followers","following_url":"https://api.github.com/users/LukasKalbertodt/following{/other_user}","gists_url":"https://api.github.com/users/LukasKalbertodt/gists{/gist_id}","starred_url":"https://api.github.com/users/LukasKalbertodt/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/LukasKalbertodt/subscriptions","organizations_url":"https://api.github.com/users/LukasKalbertodt/orgs","repos_url":"https://api.github.com/users/LukasKalbertodt/repos","events_url":"https://api.github.com/users/LukasKalbertodt/events{/privacy}","received_events_url":"https://api.github.com/users/LukasKalbertodt/received_events","type":"User","site_admin":false},"body":"So what \"matters\" is not really the total number of instructions but the ones executed for each element (each loop iteration). It's 6 for [the indexing version](https://rust.godbolt.org/z/ynJIF3) and 7 for [the `windows(2)` version](https://rust.godbolt.org/z/4h4d42).\r\n\r\nBut a few remarks:\r\n- Just counting instructions is not really a reliable way to guess the speed. So by now, we would just have to measure it to say anything about performance.\r\n- All versions are pretty close to the optimum. And I don't expect there to be a huge difference between the versions.\r\n- For small primitive types, we will have a SIMD implementation in the future, so we don't really need to care about that. For bigger types, the time to compare those types will be a significant part of the runtime, so again, this code doesn't matter *that* much.\r\n\r\nSo, I'd say to just take the **most idiomatic solution for now, which IMO is `for v in s.windows(2)`**. We can still build a bunch of benchmarks and improve the code later if it's necessary.","created_at":"2018-10-14T21:50:28Z","updated_at":"2018-10-14T21:50:29Z","html_url":"https://github.com/rust-lang/rust/pull/55045#discussion_r225010521","pull_request_url":"https://api.github.com/repos/rust-lang/rust/pulls/55045","author_association":"CONTRIBUTOR","_links":{"self":{"href":"https://api.github.com/repos/rust-lang/rust/pulls/comments/225010521"},"html":{"href":"https://github.com/rust-lang/rust/pull/55045#discussion_r225010521"},"pull_request":{"href":"https://api.github.com/repos/rust-lang/rust/pulls/55045"}},"in_reply_to_id":224967358},"pull_request":{"url":"https://api.github.com/repos/rust-lang/rust/pulls/55045","id":222662855,"node_id":"MDExOlB1bGxSZXF1ZXN0MjIyNjYyODU1","html_url":"https://github.com/rust-lang/rust/pull/55045","diff_url":"https://github.com/rust-lang/rust/pull/55045.diff","patch_url":"https://github.com/rust-lang/rust/pull/55045.patch","issue_url":"https://api.github.com/repos/rust-lang/rust/issues/55045","number":55045,"state":"open","locked":false,"title":"Add `is_sorted` to `Iterator` and `[T]`","user":{"login":"kleimkuhler","id":4572153,"node_id":"MDQ6VXNlcjQ1NzIxNTM=","avatar_url":"https://avatars2.githubusercontent.com/u/4572153?v=4","gravatar_id":"","url":"https://api.github.com/users/kleimkuhler","html_url":"https://github.com/kleimkuhler","followers_url":"https://api.github.com/users/kleimkuhler/followers","following_url":"https://api.github.com/users/kleimkuhler/following{/other_user}","gists_url":"https://api.github.com/users/kleimkuhler/gists{/gist_id}","starred_url":"https://api.github.com/users/kleimkuhler/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/kleimkuhler/subscriptions","organizations_url":"https://api.github.com/users/kleimkuhler/orgs","repos_url":"https://api.github.com/users/kleimkuhler/repos","events_url":"https://api.github.com/users/kleimkuhler/events{/privacy}","received_events_url":"https://api.github.com/users/kleimkuhler/received_events","type":"User","site_admin":false},"body":"This is an initial implementation for the first step of [RFC 2351](https://github.com/rust-lang/rfcs/blob/master/text/2351-is-sorted.md)\r\n\r\nTracking issue: https://github.com/rust-lang/rust/issues/53485","created_at":"2018-10-13T17:12:45Z","updated_at":"2018-10-14T21:50:29Z","closed_at":null,"merged_at":null,"merge_commit_sha":"201de6b21f94b35854bf4be1fc0e9d4dc472b70a","assignee":null,"assignees":[],"requested_reviewers":[],"requested_teams":[],"labels":[],"milestone":null,"commits_url":"https://api.github.com/repos/rust-lang/rust/pulls/55045/commits","review_comments_url":"https://api.github.com/repos/rust-lang/rust/pulls/55045/comments","review_comment_url":"https://api.github.com/repos/rust-lang/rust/pulls/comments{/number}","comments_url":"https://api.github.com/repos/rust-lang/rust/issues/55045/comments","statuses_url":"https://api.github.com/repos/rust-lang/rust/statuses/b5ab524ea7b536617d8abc5507a1d97b3e60a42d","head":{"label":"kleimkuhler:add-std-is_sorted","ref":"add-std-is_sorted","sha":"b5ab524ea7b536617d8abc5507a1d97b3e60a42d","user":{"login":"kleimkuhler","id":4572153,"node_id":"MDQ6VXNlcjQ1NzIxNTM=","avatar_url":"https://avatars2.githubusercontent.com/u/4572153?v=4","gravatar_id":"","url":"https://api.github.com/users/kleimkuhler","html_url":"https://github.com/kleimkuhler","followers_url":"https://api.github.com/users/kleimkuhler/followers","following_url":"https://api.github.com/users/kleimkuhler/following{/other_user}","gists_url":"https://api.github.com/users/kleimkuhler/gists{/gist_id}","starred_url":"https://api.github.com/users/kleimkuhler/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/kleimkuhler/subscriptions","organizations_url":"https://api.github.com/users/kleimkuhler/orgs","repos_url":"https://api.github.com/users/kleimkuhler/repos","events_url":"https://api.github.com/users/kleimkuhler/events{/privacy}","received_events_url":"https://api.github.com/users/kleimkuhler/received_events","type":"User","site_admin":false},"repo":{"id":150049113,"node_id":"MDEwOlJlcG9zaXRvcnkxNTAwNDkxMTM=","name":"rust","full_name":"kleimkuhler/rust","private":false,"owner":{"login":"kleimkuhler","id":4572153,"node_id":"MDQ6VXNlcjQ1NzIxNTM=","avatar_url":"https://avatars2.githubusercontent.com/u/4572153?v=4","gravatar_id":"","url":"https://api.github.com/users/kleimkuhler","html_url":"https://github.com/kleimkuhler","followers_url":"https://api.github.com/users/kleimkuhler/followers","following_url":"https://api.github.com/users/kleimkuhler/following{/other_user}","gists_url":"https://api.github.com/users/kleimkuhler/gists{/gist_id}","starred_url":"https://api.github.com/users/kleimkuhler/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/kleimkuhler/subscriptions","organizations_url":"https://api.github.com/users/kleimkuhler/orgs","repos_url":"https://api.github.com/users/kleimkuhler/repos","events_url":"https://api.github.com/users/kleimkuhler/events{/privacy}","received_events_url":"https://api.github.com/users/kleimkuhler/received_events","type":"User","site_admin":false},"html_url":"https://github.com/kleimkuhler/rust","description":"A safe, concurrent, practical language.","fork":true,"url":"https://api.github.com/repos/kleimkuhler/rust","forks_url":"https://api.github.com/repos/kleimkuhler/rust/forks","keys_url":"https://api.github.com/repos/kleimkuhler/rust/keys{/key_id}","collaborators_url":"https://api.github.com/repos/kleimkuhler/rust/collaborators{/collaborator}","teams_url":"https://api.github.com/repos/kleimkuhler/rust/teams","hooks_url":"https://api.github.com/repos/kleimkuhler/rust/hooks","issue_events_url":"https://api.github.com/repos/kleimkuhler/rust/issues/events{/number}","events_url":"https://api.github.com/repos/kleimkuhler/rust/events","assignees_url":"https://api.github.com/repos/kleimkuhler/rust/assignees{/user}","branches_url":"https://api.github.com/repos/kleimkuhler/rust/branches{/branch}","tags_url":"https://api.github.com/repos/kleimkuhler/rust/tags","blobs_url":"https://api.github.com/repos/kleimkuhler/rust/git/blobs{/sha}","git_tags_url":"https://api.github.com/repos/kleimkuhler/rust/git/tags{/sha}","git_refs_url":"https://api.github.com/repos/kleimkuhler/rust/git/refs{/sha}","trees_url":"https://api.github.com/repos/kleimkuhler/rust/git/trees{/sha}","statuses_url":"https://api.github.com/repos/kleimkuhler/rust/statuses/{sha}","languages_url":"https://api.github.com/repos/kleimkuhler/rust/languages","stargazers_url":"https://api.github.com/repos/kleimkuhler/rust/stargazers","contributors_url":"https://api.github.com/repos/kleimkuhler/rust/contributors","subscribers_url":"https://api.github.com/repos/kleimkuhler/rust/subscribers","subscription_url":"https://api.github.com/repos/kleimkuhler/rust/subscription","commits_url":"https://api.github.com/repos/kleimkuhler/rust/commits{/sha}","git_commits_url":"https://api.github.com/repos/kleimkuhler/rust/git/commits{/sha}","comments_url":"https://api.github.com/repos/kleimkuhler/rust/comments{/number}","issue_comment_url":"https://api.github.com/repos/kleimkuhler/rust/issues/comments{/number}","contents_url":"https://api.github.com/repos/kleimkuhler/rust/contents/{+path}","compare_url":"https://api.github.com/repos/kleimkuhler/rust/compare/{base}...{head}","merges_url":"https://api.github.com/repos/kleimkuhler/rust/merges","archive_url":"https://api.github.com/repos/kleimkuhler/rust/{archive_format}{/ref}","downloads_url":"https://api.github.com/repos/kleimkuhler/rust/downloads","issues_url":"https://api.github.com/repos/kleimkuhler/rust/issues{/number}","pulls_url":"https://api.github.com/repos/kleimkuhler/rust/pulls{/number}","milestones_url":"https://api.github.com/repos/kleimkuhler/rust/milestones{/number}","notifications_url":"https://api.github.com/repos/kleimkuhler/rust/notifications{?since,all,participating}","labels_url":"https://api.github.com/repos/kleimkuhler/rust/labels{/name}","releases_url":"https://api.github.com/repos/kleimkuhler/rust/releases{/id}","deployments_url":"https://api.github.com/repos/kleimkuhler/rust/deployments","created_at":"2018-09-24T03:22:04Z","updated_at":"2018-10-14T21:07:44Z","pushed_at":"2018-10-14T21:07:42Z","git_url":"git://github.com/kleimkuhler/rust.git","ssh_url":"git@github.com:kleimkuhler/rust.git","clone_url":"https://github.com/kleimkuhler/rust.git","svn_url":"https://github.com/kleimkuhler/rust","homepage":"https://www.rust-lang.org","size":397521,"stargazers_count":1,"watchers_count":1,"language":"Rust","has_issues":false,"has_projects":true,"has_downloads":true,"has_wiki":false,"has_pages":false,"forks_count":0,"mirror_url":null,"archived":false,"open_issues_count":0,"license":{"key":"other","name":"Other","spdx_id":"NOASSERTION","url":null,"node_id":"MDc6TGljZW5zZTA="},"forks":0,"open_issues":0,"watchers":1,"default_branch":"master"}},"base":{"label":"rust-lang:master","ref":"master","sha":"4699283c5b549d1559c198123a67fef498aa6a44","user":{"login":"rust-lang","id":5430905,"node_id":"MDEyOk9yZ2FuaXphdGlvbjU0MzA5MDU=","avatar_url":"https://avatars1.githubusercontent.com/u/5430905?v=4","gravatar_id":"","url":"https://api.github.com/users/rust-lang","html_url":"https://github.com/rust-lang","followers_url":"https://api.github.com/users/rust-lang/followers","following_url":"https://api.github.com/users/rust-lang/following{/other_user}","gists_url":"https://api.github.com/users/rust-lang/gists{/gist_id}","starred_url":"https://api.github.com/users/rust-lang/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/rust-lang/subscriptions","organizations_url":"https://api.github.com/users/rust-lang/orgs","repos_url":"https://api.github.com/users/rust-lang/repos","events_url":"https://api.github.com/users/rust-lang/events{/privacy}","received_events_url":"https://api.github.com/users/rust-lang/received_events","type":"Organization","site_admin":false},"repo":{"id":724712,"node_id":"MDEwOlJlcG9zaXRvcnk3MjQ3MTI=","name":"rust","full_name":"rust-lang/rust","private":false,"owner":{"login":"rust-lang","id":5430905,"node_id":"MDEyOk9yZ2FuaXphdGlvbjU0MzA5MDU=","avatar_url":"https://avatars1.githubusercontent.com/u/5430905?v=4","gravatar_id":"","url":"https://api.github.com/users/rust-lang","html_url":"https://github.com/rust-lang","followers_url":"https://api.github.com/users/rust-lang/followers","following_url":"https://api.github.com/users/rust-lang/following{/other_user}","gists_url":"https://api.github.com/users/rust-lang/gists{/gist_id}","starred_url":"https://api.github.com/users/rust-lang/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/rust-lang/subscriptions","organizations_url":"https://api.github.com/users/rust-lang/orgs","repos_url":"https://api.github.com/users/rust-lang/repos","events_url":"https://api.github.com/users/rust-lang/events{/privacy}","received_events_url":"https://api.github.com/users/rust-lang/received_events","type":"Organization","site_admin":false},"html_url":"https://github.com/rust-lang/rust","description":"A safe, concurrent, practical language.","fork":false,"url":"https://api.github.com/repos/rust-lang/rust","forks_url":"https://api.github.com/repos/rust-lang/rust/forks","keys_url":"https://api.github.com/repos/rust-lang/rust/keys{/key_id}","collaborators_url":"https://api.github.com/repos/rust-lang/rust/collaborators{/collaborator}","teams_url":"https://api.github.com/repos/rust-lang/rust/teams","hooks_url":"https://api.github.com/repos/rust-lang/rust/hooks","issue_events_url":"https://api.github.com/repos/rust-lang/rust/issues/events{/number}","events_url":"https://api.github.com/repos/rust-lang/rust/events","assignees_url":"https://api.github.com/repos/rust-lang/rust/assignees{/user}","branches_url":"https://api.github.com/repos/rust-lang/rust/branches{/branch}","tags_url":"https://api.github.com/repos/rust-lang/rust/tags","blobs_url":"https://api.github.com/repos/rust-lang/rust/git/blobs{/sha}","git_tags_url":"https://api.github.com/repos/rust-lang/rust/git/tags{/sha}","git_refs_url":"https://api.github.com/repos/rust-lang/rust/git/refs{/sha}","trees_url":"https://api.github.com/repos/rust-lang/rust/git/trees{/sha}","statuses_url":"https://api.github.com/repos/rust-lang/rust/statuses/{sha}","languages_url":"https://api.github.com/repos/rust-lang/rust/languages","stargazers_url":"https://api.github.com/repos/rust-lang/rust/stargazers","contributors_url":"https://api.github.com/repos/rust-lang/rust/contributors","subscribers_url":"https://api.github.com/repos/rust-lang/rust/subscribers","subscription_url":"https://api.github.com/repos/rust-lang/rust/subscription","commits_url":"https://api.github.com/repos/rust-lang/rust/commits{/sha}","git_commits_url":"https://api.github.com/repos/rust-lang/rust/git/commits{/sha}","comments_url":"https://api.github.com/repos/rust-lang/rust/comments{/number}","issue_comment_url":"https://api.github.com/repos/rust-lang/rust/issues/comments{/number}","contents_url":"https://api.github.com/repos/rust-lang/rust/contents/{+path}","compare_url":"https://api.github.com/repos/rust-lang/rust/compare/{base}...{head}","merges_url":"https://api.github.com/repos/rust-lang/rust/merges","archive_url":"https://api.github.com/repos/rust-lang/rust/{archive_format}{/ref}","downloads_url":"https://api.github.com/repos/rust-lang/rust/downloads","issues_url":"https://api.github.com/repos/rust-lang/rust/issues{/number}","pulls_url":"https://api.github.com/repos/rust-lang/rust/pulls{/number}","milestones_url":"https://api.github.com/repos/rust-lang/rust/milestones{/number}","notifications_url":"https://api.github.com/repos/rust-lang/rust/notifications{?since,all,participating}","labels_url":"https://api.github.com/repos/rust-lang/rust/labels{/name}","releases_url":"https://api.github.com/repos/rust-lang/rust/releases{/id}","deployments_url":"https://api.github.com/repos/rust-lang/rust/deployments","created_at":"2010-06-16T20:39:03Z","updated_at":"2018-10-14T20:34:02Z","pushed_at":"2018-10-14T20:56:17Z","git_url":"git://github.com/rust-lang/rust.git","ssh_url":"git@github.com:rust-lang/rust.git","clone_url":"https://github.com/rust-lang/rust.git","svn_url":"https://github.com/rust-lang/rust","homepage":"https://www.rust-lang.org","size":397799,"stargazers_count":31138,"watchers_count":31138,"language":"Rust","has_issues":true,"has_projects":true,"has_downloads":true,"has_wiki":false,"has_pages":false,"forks_count":5236,"mirror_url":null,"archived":false,"open_issues_count":4456,"license":{"key":"other","name":"Other","spdx_id":"NOASSERTION","url":null,"node_id":"MDc6TGljZW5zZTA="},"forks":5236,"open_issues":4456,"watchers":31138,"default_branch":"master"}},"_links":{"self":{"href":"https://api.github.com/repos/rust-lang/rust/pulls/55045"},"html":{"href":"https://github.com/rust-lang/rust/pull/55045"},"issue":{"href":"https://api.github.com/repos/rust-lang/rust/issues/55045"},"comments":{"href":"https://api.github.com/repos/rust-lang/rust/issues/55045/comments"},"review_comments":{"href":"https://api.github.com/repos/rust-lang/rust/pulls/55045/comments"},"review_comment":{"href":"https://api.github.com/repos/rust-lang/rust/pulls/comments{/number}"},"commits":{"href":"https://api.github.com/repos/rust-lang/rust/pulls/55045/commits"},"statuses":{"href":"https://api.github.com/repos/rust-lang/rust/statuses/b5ab524ea7b536617d8abc5507a1d97b3e60a42d"}},"author_association":"NONE"}}
{"actor":{"display_login":"LukasKalbertodt"}}