-
Notifications
You must be signed in to change notification settings - Fork 279
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
Favor the function over the method syntax when cloning a reference counted pointer. #1037
Conversation
r? @kvark |
webrender/src/resource_cache.rs
Outdated
@@ -709,7 +709,7 @@ impl ResourceCache { | |||
is_opaque: image_descriptor.is_opaque, | |||
} | |||
} else { | |||
image_template.descriptor.clone() | |||
image_template.descriptor |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This change is not related to what the PR describes, please remove or put in its own commit.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@nox I think you are overly sensitive here. It doesn't appear to me that the change bears any danger, and it's a bit related to the clone()
refactor.
@nical I see where you are coming from, and the change looks clean. |
☔ The latest upstream changes (presumably #997) made this pull request unmergeable. Please resolve the merge conflicts. |
I really like this idea. |
I did a last rebase before I disappear for 2 weeks. Don't hesitate to re-submit this in my place if a consensus is approached while I'm away. |
I'm not going to block this. @glennw please proceed if you are happy about it. |
OK, let's merge it. We can always change back if we decide it's not worthwhile. Thanks! |
@bors-servo r+ |
📌 Commit 45a2fa8 has been approved by |
Favor the function over the method syntax when cloning a reference counted pointer. ```data.clone()``` reads like performance hazard, due to the vague definition of Clone, which can be either very expensive if data is an uniquely owned large resource or very cheap if it is a reference counted pointer to such a resource. This has already confused people reading the code and even code reviews several times in webrender, so I would like to work around this unfortunate ambiguity. I first tried to address this at the [standard library level](rust-lang/rfcs#1954) but the decision of the rust team appears to be that we should use the function syntax instead of the method syntax to address the problem. See also the [clippy issue](https://github.com/Manishearth/rust-clippy/issues/1645) about providing a lint for this. I decided to take a systematic approach and use the function call syntax for all of the outstanding reference counted pointer clones that I came across (I would not be surprised that I missed some of them). Rather than try to separate the obvious from the ambiguous ones. I would rather make this a default policy than have to debate about where the line is in each code review. The three commits are independent and can be reviewed separately (although they are small and simple enough to look at as one diff if you prefer). <!-- Reviewable:start --> --- This change is [<img src="https://reviewable.io/review_button.svg" height="34" align="absmiddle" alt="Reviewable"/>](https://reviewable.io/reviews/servo/webrender/1037) <!-- Reviewable:end -->
☀️ Test successful - status-travis |
data.clone()
reads like performance hazard, due to the vague definition of Clone, which can be either very expensive if data is an uniquely owned large resource or very cheap if it is a reference counted pointer to such a resource. This has already confused people reading the code and even code reviews several times in webrender, so I would like to work around this unfortunate ambiguity.I first tried to address this at the standard library level but the decision of the rust team appears to be that we should use the function syntax instead of the method syntax to address the problem.
See also the clippy issue about providing a lint for this.
I decided to take a systematic approach and use the function call syntax for all of the outstanding reference counted pointer clones that I came across (I would not be surprised that I missed some of them). Rather than try to separate the obvious from the ambiguous ones. I would rather make this a default policy than have to debate about where the line is in each code review.
The three commits are independent and can be reviewed separately (although they are small and simple enough to look at as one diff if you prefer).
This change is