Skip to content

std: Stabilize Clone::clone_from #24215

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

Merged
merged 1 commit into from
Apr 9, 2015

Conversation

alexcrichton
Copy link
Member

This method hasn't really changed since is inception, and it can often be a
nice performance win for some situations. This method also imposes no burden on
implementors or users of Clone as it's just a default method on the side.

This method hasn't really changed since is inception, and it can often be a
nice performance win for some situations. This method also imposes no burden on
implementors or users of `Clone` as it's just a default method on the side.
@alexcrichton
Copy link
Member Author

r? @aturon

@rust-highfive rust-highfive assigned aturon and unassigned nikomatsakis Apr 8, 2015
@rust-highfive
Copy link
Contributor

r? @nikomatsakis

(rust_highfive has picked a reviewer for you, use r? to override)

@aturon
Copy link
Member

aturon commented Apr 8, 2015

@bors: r+

It's time.

@bors
Copy link
Collaborator

bors commented Apr 8, 2015

📌 Commit 6b32072 has been approved by aturon

@sfackler
Copy link
Member

sfackler commented Apr 9, 2015

Out of curiosity, are there any consumers of clone_from? I've never seen one.

Manishearth added a commit to Manishearth/rust that referenced this pull request Apr 9, 2015
…r=aturon

 This method hasn't really changed since is inception, and it can often be a
nice performance win for some situations. This method also imposes no burden on
implementors or users of `Clone` as it's just a default method on the side.
@alexcrichton
Copy link
Member Author

@sfackler none that I'm personally aware of, no

@aturon
Copy link
Member

aturon commented Apr 9, 2015

@alexcrichton I thought this was instigated because of a request for stabilization by someone who needed it for performance?

@alexcrichton
Copy link
Member Author

The original request came from @mzabaluev. @mzabaluev perhaps you could shed some light on your thoughts here?

Manishearth added a commit to Manishearth/rust that referenced this pull request Apr 9, 2015
…r=aturon

 This method hasn't really changed since is inception, and it can often be a
nice performance win for some situations. This method also imposes no burden on
implementors or users of `Clone` as it's just a default method on the side.
@bors bors merged commit 6b32072 into rust-lang:master Apr 9, 2015
@mzabaluev
Copy link
Contributor

An implementation of a type that encapsulates pointers to allocated or refcounted data could implement clone_from to avoid copying or other costly operations, if the same data is already aliased between the source and the destination.

The user of Clone needs to be aware of the possible optimisation, to prefer clone_from to reassigning a lvalue with the result of clone (which is the default unoptimized implementation of clone_from). A lint could be added in the future to recognize the pattern and suggest clone_from as an optimisation.

@alexcrichton alexcrichton deleted the stabilize-clone-from branch April 30, 2015 02:12
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

7 participants