Join GitHub today
GitHub is home to over 50 million developers working together to host and review code, manage projects, and build software together.
Sign upFavor the function over the method syntax when cloning a reference counted pointer. #1037
Conversation
|
r? @kvark |
| @@ -709,7 +709,7 @@ impl ResourceCache { | |||
| is_opaque: image_descriptor.is_opaque, | |||
| } | |||
| } else { | |||
| image_template.descriptor.clone() | |||
| image_template.descriptor | |||
This comment has been minimized.
This comment has been minimized.
nox
Mar 30, 2017
•
Member
This change is not related to what the PR describes, please remove or put in its own commit.
This comment has been minimized.
This comment has been minimized.
kvark
Mar 30, 2017
•
Member
@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. |
|
|
|
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+ |
|
|
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 -->
|
|
nical commentedMar 30, 2017
•
edited by larsbergstrom
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