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

Issue 598: Refactoring List class #702

Closed
wants to merge 17 commits into from

Conversation

veronikaro
Copy link

@veronikaro veronikaro commented Feb 19, 2024

Solves #598.

@github-actions github-actions bot added the work in progress Pull request is still in progress and changing label Feb 19, 2024
Copy link

🤖 Upon creation, pull request description does not have a link to an issue. If there is a related issue, please add it to the description using any of the supported formats.

@gavv gavv added the contribution A pull-request by someone else except maintainers label Feb 20, 2024
@veronikaro veronikaro changed the title Refactoring List class Issue 598: Refactoring List class Feb 25, 2024
@veronikaro
Copy link
Author

@gavv I would appreciate your feedback to this PR. Thanks!

@veronikaro veronikaro marked this pull request as ready for review February 25, 2024 23:08
@github-actions github-actions bot added ready for review Pull request can be reviewed and removed work in progress Pull request is still in progress and changing labels Feb 25, 2024
@gavv
Copy link
Member

gavv commented Feb 28, 2024

Hi, thanks for PR!

A few comments:

  1. Please fix CI. There is a crash in tests reported by several jobs. (You can reproduce it locally by using --sanitizers option).

  2. Some ListImpl methods use ListNodeData, and some use ListNode. For consistency, I suggest to use ListNodeData everywhere.

  3. I think we could keep container_of_() in template class, after all ListImpl methods will switch to ListNodeData.

  4. ListImpl::is_empty() can be removed. We can implement List::is_empty() using ListImpl.size().

  5. We can simplify ~List() to something like (see below why):

    while (!is_empty()) {
        pop_front();
    }
  6. Also we can move impl_.head.list = NULL; from ~List() to ~ListImpl(). Since ListImpl is responsible to initialize head, it's logical that it's also responsible to deinitialize it.

  7. After these changes we can make check_is_member() a private method of ListImpl.

  8. Since ListImpl is a class with methods, not a C-like struct, for consistency I suggest to make head field private and add a public getter ListNodeData& head().

@gavv gavv added needs revision Pull request should be revised by its author and removed ready for review Pull request can be reviewed labels Feb 28, 2024
@gavv gavv added ready for review Pull request can be reviewed and removed needs revision Pull request should be revised by its author labels Mar 4, 2024
…NodeData, change deconstructor of List, make head private and add getter, nulling list of head in ListImpl, making check_is_member private
@veronikaro
Copy link
Author

Hi @gavv,
sorry for the delay.
I addressed all your comments, thank you very much for the feedback.

8. Since ListImpl is a class with methods, not a C-like struct, for consistency I suggest to make head field private and add a public getter `ListNodeData& head()`.

I did this at the cost of implementing push_back as a function of ListImpl level. The reason for this is that push_back requires a pointer to the head.

I would appreciate your review!

Copy link
Member

@gavv gavv left a comment

Choose a reason for hiding this comment

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

Thanks for update! Some final comments.

}

head_.list = NULL;
impl_.~ListImpl();
Copy link
Member

Choose a reason for hiding this comment

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

This way impl dtor is called twice. There is no need to call it explicitly, you can just remove this line.

Comment on lines +205 to 209
if (data)
return static_cast<T*>(data->container_of());
else
return NULL;
}
Copy link
Member

Choose a reason for hiding this comment

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

Please always use {}.

Comment on lines +88 to +89
//! Get head of list
ListNode::ListNodeData head() const;
Copy link
Member

Choose a reason for hiding this comment

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

I guess we should return a reference or a pointer here. It's expected that you can take address of any node in list.

private:
size_t size_;
//! Head of list
ListNode::ListNodeData _head;
Copy link
Member

Choose a reason for hiding this comment

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

nit: _head => head_

Comment on lines +95 to +96
//! Check if list node data is registered in this list.
static void check_is_member(const ListNode::ListNodeData* data, const ListImpl* list);
Copy link
Member

Choose a reason for hiding this comment

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

nit: check_is_member => check_is_member_ (because it's private)

Comment on lines +128 to +130
impl_.push_back(element.list_node_data());

OwnershipPolicy<T>::acquire(element);
Copy link
Member

Choose a reason for hiding this comment

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

impl_.insert(element.list_node_data(), &impl_.head());

this should work (if you'll return a reference from head()) - and impl.push_back won't be needed.

@gavv gavv added needs revision Pull request should be revised by its author and removed ready for review Pull request can be reviewed labels Apr 9, 2024
Copy link

🤖 The latest upstream change made this pull request unmergeable. Please resolve the merge conflicts.

@github-actions github-actions bot added the needs rebase Pull request has conflicts and should be rebased label May 14, 2024
gavv added a commit to gavv/roc-toolkit that referenced this pull request May 15, 2024
Ported from roc-streaminggh-702

Co-authored-by: Veronika Rovnik <veronikarovnik@gmail.com>
@gavv
Copy link
Member

gavv commented May 15, 2024

@veronikaro Hi, my recent commit (2510edd) introduced lots of conflicts with this patch, so I ported your code to the new version and finished remaining issues: bef7210

Thanks!

@gavv gavv closed this May 15, 2024
@gavv gavv added merged manually and removed needs revision Pull request should be revised by its author labels May 15, 2024
@github-actions github-actions bot removed the needs rebase Pull request has conflicts and should be rebased label May 15, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
contribution A pull-request by someone else except maintainers merged manually
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

2 participants