Skip to content

Conversation

@Rush
Copy link
Contributor

@Rush Rush commented Aug 27, 2016

@mbroadst I had a lazy evening and a crazy idea to use weak pointers instead of NLVObjectPtr. Note: enable_shared_from_this is probably not necessary but I wanted you to see this branch earlier rather than later to get some comments.


void ClearChildren() {
for (auto& ptr: children_) {
if (auto object = ptr.lock()) {
Copy link
Contributor Author

Choose a reason for hiding this comment

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

@mbroadst this is the reward, ability to see if those weak pointers are stil valid.

@mbroadst
Copy link
Contributor

yeah definitely now that we've committed to c++11, smart pointers are of course the way to go :)

HandleType handle_;
NLVObjectBasePtr* parentReference_;

std::unique_ptr<HandleValue, decltype(&CleanupHandler::cleanup)> handle_;
Copy link
Contributor

Choose a reason for hiding this comment

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

nice

@mbroadst
Copy link
Contributor

@Rush I left a few comments. I really like the direction this is taking, but I wonder if we can't split the single commit into at least two:

  • one for the move to std::unique_ptr + all of the handle_ => handle() changes
  • one for your idea with std::shared_ptr

It's a bit hard to review this mono-commit version because of all the handle_ => handle() noise, and frankly I would merge that one right in because it's pretty straightforward and obviously the better solution.

Thoughts?

@Rush
Copy link
Contributor Author

Rush commented Aug 27, 2016

Sure, I'll split it later this evening probably. Thanks for leaving the comments.

@Rush Rush force-pushed the refactor/smart-pointers branch from 9794cfe to a8051f8 Compare August 27, 2016 18:46
src/nlv_object.h Outdated
HandleType handle() const {
return handle_;
}
const HandleType handle() const {
Copy link
Contributor

Choose a reason for hiding this comment

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

as a purely informational refactor, do you think it would be a good idea to rename this to virHandle() so we avoid mental collisions with v8's handle() ?

Copy link
Contributor

Choose a reason for hiding this comment

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

otherwise I have no issues with this commit, I'll just cherry-pick it right in

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Good idea. Do you have the time to rename it yourself?

@mbroadst mbroadst force-pushed the refactor/smart-pointers branch from a8051f8 to 925e37e Compare August 27, 2016 19:29
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

3 participants