Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Avoid an unecessary clone in LookAheadMethods::children #1200

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions juniper/CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,7 @@ All user visible changes to `juniper` crate will be documented in this file. Thi
- Removed `scalar-naivetime` [Cargo feature].
- Removed lifetime parameter from `ParseError`, `GraphlQLError`, `GraphQLBatchRequest` and `GraphQLRequest`. ([#1081], [#528])
- Upgraded [GraphiQL] to 3.0.8 version (requires new [`graphql-transport-ws` GraphQL over WebSocket Protocol] integration on server, see `juniper_warp/examples/subscription.rs`). ([#1188], [#1193], [#1203])
- Made `LookAheadMethods::children()` method to return slice instead of `Vec`. ([#1200])

### Added

Expand Down Expand Up @@ -128,6 +129,7 @@ All user visible changes to `juniper` crate will be documented in this file. Thi
[#1190]: /../../pull/1190
[#1193]: /../../pull/1193
[#1199]: /../../pull/1199
[#1200]: /../../pull/1200
[#1203]: /../../pull/1203
[ba1ed85b]: /../../commit/ba1ed85b3c3dd77fbae7baf6bc4e693321a94083
[CVE-2022-31173]: /../../security/advisories/GHSA-4rx6-g5vg-5f3j
Expand Down
12 changes: 7 additions & 5 deletions juniper/src/executor/look_ahead.rs
Original file line number Diff line number Diff line change
Expand Up @@ -372,7 +372,9 @@ pub trait LookAheadMethods<'sel, S> {
fn child_names(&self) -> Vec<&'sel str>;

/// Returns an [`Iterator`] over the children from the current selection.
fn children(&self) -> Vec<&Self>;
fn children(&self) -> &[Self]
where
Self: Sized;

/// Returns the parent type, in case there is any for the current selection.
fn applies_for(&self) -> Option<&str>;
Expand Down Expand Up @@ -411,8 +413,8 @@ impl<'a, S> LookAheadMethods<'a, S> for ConcreteLookAheadSelection<'a, S> {
!self.children.is_empty()
}

fn children(&self) -> Vec<&Self> {
self.children.iter().collect()
fn children(&self) -> &[Self] {
&self.children
}

fn applies_for(&self) -> Option<&str> {
Expand Down Expand Up @@ -456,8 +458,8 @@ impl<'a, S> LookAheadMethods<'a, S> for LookAheadSelection<'a, S> {
!self.children.is_empty()
}

fn children(&self) -> Vec<&Self> {
self.children.iter().collect()
fn children(&self) -> &[Self] {
&self.children
}

fn applies_for(&self) -> Option<&str> {
Expand Down