Skip to content

mon/MDSMonitor.cc: use std::move on strings - #10695

Closed
stiopaa1 wants to merge 1 commit into
ceph:masterfrom
stiopaa1:mon_mdsmonitor_addMove
Closed

stiopaa1 wants to merge 1 commit into
ceph:masterfrom
stiopaa1:mon_mdsmonitor_addMove

Conversation

@stiopaa1

Copy link
Copy Markdown
Contributor

Signed-off-by: Michal Jarzabek [email protected]

@gregsfortytwo

Copy link
Copy Markdown
Member

This looks fine, but should we be pushing it farther up the stack as well? (Or just using const refs? I don't remember how they're used.)

@stiopaa1

Copy link
Copy Markdown
Contributor Author

@gregsfortytwo
You are talking about cmd_get val, right?
Using std::move here avoids one copy, but as we don't need store value of string anywhere changing cmd_get_val to take const string& would be even better option(avoids moving). I have removed it from this commit and will change it to const string& in a different one.

@stiopaa1
stiopaa1 force-pushed the mon_mdsmonitor_addMove branch from 7e3c658 to 49a594d Compare August 13, 2016 08:08
@stiopaa1

Copy link
Copy Markdown
Contributor Author

I have also added std::move in PaxosService.h

@gregsfortytwo

Copy link
Copy Markdown
Member

Okay, I don't like this new version. Constructors on PaxosService and MDSMonitor are rarely invoked and any confusion about ownership isn't worth it if somebody ends up passing re-used strings or something. I think just using const string& will capture the important bits.

@stiopaa1

Copy link
Copy Markdown
Contributor Author

@gregsfortytwo
This is a pretty common way of doing this, which is also used in a different places of the code base, so im not sure why there should be any confusion? could you please elaborate?

@gregsfortytwo

Copy link
Copy Markdown
Member

The MDSMonitor constructor is only called once per mon process and the parent PaxosService is called maybe 5 times per process, all at startup. There's very little point in optimizing them like this if there is any chance of that causing bugs in the future. It's not likely to cause trouble, but stealing string values can do so in some cases if they're reused (which we do with other initialization strings from time to time). So let's skip this one.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants