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

Make item_location copyable #31743

Merged

Conversation

jbytheway
Copy link
Contributor

Summary

SUMMARY: None

Purpose of change

The copy constructor for item_location was deleted. I think this dated from a time when it was implemented via unique_ptr, but now it uses shared_ptr and has a clone method.

This only serves to make code unnecessarily complex.

Describe the solution

Reinstate the copy constructor (doing the same thing as clone), remove clone, and update other code accordingly.

In particular, this dramatically simplifies parts of player_activity and inventory_entry, since they can now have default copy construction and assignment.

Additional context

A necessary diversion during my work towards repairing some of the unsafety of item_location.

The copy constructor for item_location was deleted.  I think this dated
from a time when it was implemented via unique_ptr, but now it uses
shared_ptr and has a clone method.

This only serves to make code unnecessarily complex.  Reinstate the copy
constructor (doing the same thing as clone), remove clone, and update
other code accordingly.

In particular, this dramatically simplifies parts of player_activity and
inventory_entry, since they can now have default copy construction and
assignment.
@ifreund ifreund added [C++] Changes (can be) made in C++. Previously named `Code` Code: Infrastructure / Style / Static Analysis Code internal infrastructure and style Inventory / AIM / Zones Inventory, Advanced Inventory Management or Zones labels Jun 22, 2019
Copy link
Contributor

@ifreund ifreund left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

All looks good to me, thanks for doing this.

I'd guess there are now some unnecessary moves of item_locations lingering, but I'm not sure how we could catch all of those.

@jbytheway
Copy link
Contributor Author

Move is still faster than copy, and a reasonable choice when semantically logical. They will do no harm.

@ifreund
Copy link
Contributor

ifreund commented Jun 22, 2019

I believe there are some cases where we don't want to move (see this article) but I agree it's really not a big deal, and probably beneficial in most cases.

@jbytheway
Copy link
Contributor Author

As that article points out, such uses can be found via compiler warnings. We can catch them when we start using gcc 9 at some point :).

@ZhilkinSerg ZhilkinSerg self-assigned this Jun 23, 2019
@ZhilkinSerg ZhilkinSerg merged commit 2d4e7a3 into CleverRaven:master Jun 23, 2019
@ZhilkinSerg ZhilkinSerg removed their assignment Jun 23, 2019
@jbytheway jbytheway deleted the item_location_copy_constructor branch June 23, 2019 09:14
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
[C++] Changes (can be) made in C++. Previously named `Code` Code: Infrastructure / Style / Static Analysis Code internal infrastructure and style Inventory / AIM / Zones Inventory, Advanced Inventory Management or Zones
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants