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

Refactor[MWC]: explicit operator= in mwcc containers #372

Merged
merged 2 commits into from
Jul 24, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 12 additions & 0 deletions src/groups/mwc/mwcc/mwcc_orderedhashmap.h
Original file line number Diff line number Diff line change
Expand Up @@ -296,6 +296,9 @@ class OrderedHashMap_SequentialIterator {

// MANIPULATORS

/// Assign to this object the value of the specified `rhs` object.
OrderedHashMap_SequentialIterator& operator=(const NcIter& rhs);

/// Advance this iterator to the next element in the sequential list and
/// return its new value. The behavior is undefined unless this
/// iterator is in the range `[begin() .. end())` (i.e., the iterator is
Expand Down Expand Up @@ -885,6 +888,15 @@ inline OrderedHashMap_SequentialIterator<
}

// MANIPULATORS

template <class VALUE>
inline OrderedHashMap_SequentialIterator<VALUE>&
OrderedHashMap_SequentialIterator<VALUE>::operator=(const NcIter& rhs)
{
d_link_p = rhs.d_link_p;
Copy link
Collaborator Author

Choose a reason for hiding this comment

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

Note that I decided to not to add checks for self-assignment, since we don't assign many fields, and just assign will be much faster than if-branch.

We don't check for self-assignment for some small classes, for example

template <class VALUE>
inline WeakMemFnResult<VALUE>&
WeakMemFnResult<VALUE>::operator=(const WeakMemFnResult& original)
{
    d_value.object() = original.d_value.object();
    return *this;
}

Copy link
Collaborator

Choose a reason for hiding this comment

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

This makes sense, this is such a cheap object that we shouldn't worry about self-assignment.

return *this;
}

template <class VALUE>
inline OrderedHashMap_SequentialIterator<VALUE>&
OrderedHashMap_SequentialIterator<VALUE>::operator++()
Expand Down
12 changes: 12 additions & 0 deletions src/groups/mwc/mwcc/mwcc_orderedhashmapwithhistory.h
Original file line number Diff line number Diff line change
Expand Up @@ -108,6 +108,9 @@ class OrderedHashMapWithHistory_Iterator {

// MANIPULATORS

/// Assign to this object the value of the specified `rhs` object.
OrderedHashMapWithHistory_Iterator& operator=(const NcIter& rhs);

/// Advance this iterator to the next element in the sequential list and
/// return its new value. The behavior is undefined unless this
/// iterator is in the range `[begin() .. end())` (i.e., the iterator is
Expand Down Expand Up @@ -386,6 +389,15 @@ inline OrderedHashMapWithHistory_Iterator<
}

// MANIPULATORS

template <class VALUE>
inline OrderedHashMapWithHistory_Iterator<VALUE>&
OrderedHashMapWithHistory_Iterator<VALUE>::operator=(const NcIter& rhs)
{
d_baseIterator = rhs.d_baseIterator;
return *this;
}

template <class VALUE>
inline OrderedHashMapWithHistory_Iterator<VALUE>&
OrderedHashMapWithHistory_Iterator<VALUE>::operator++()
Expand Down
Loading