mirror of
https://github.com/zeek/zeek.git
synced 2025-10-09 10:08:20 +00:00
Merge branch 'refactor' of https://github.com/MaxKellermann/zeek
- Minor code style/format tweaks in merge * 'refactor' of https://github.com/MaxKellermann/zeek: IntrusivePtr: overload std::swap() IntrusivePtr: eliminate setPtr() IntrusivePtr: optimize release() using std::exchange() Expr: remove unused default constructors and `friend` declarations Expr: remove useless override Type: don't pass reference to pointer to MatchesIndex() Expr: don't pass reference to pointer to check_and_promote*() ID: remove unused default constructor Scope: simplify PList access, use pop_back() and back() List: add method empty()
This commit is contained in:
commit
597407a708
10 changed files with 67 additions and 190 deletions
|
@ -71,9 +71,9 @@ public:
|
|||
*
|
||||
* @param raw_ptr Pointer to the shared object.
|
||||
*/
|
||||
IntrusivePtr(AdoptRef, pointer raw_ptr) noexcept
|
||||
constexpr IntrusivePtr(AdoptRef, pointer raw_ptr) noexcept
|
||||
: ptr_(raw_ptr)
|
||||
{
|
||||
setPtr(raw_ptr, false);
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -85,8 +85,10 @@ public:
|
|||
* @param raw_ptr Pointer to the shared object.
|
||||
*/
|
||||
IntrusivePtr(NewRef, pointer raw_ptr) noexcept
|
||||
: ptr_(raw_ptr)
|
||||
{
|
||||
setPtr(raw_ptr, true);
|
||||
if ( ptr_ )
|
||||
Ref(ptr_);
|
||||
}
|
||||
|
||||
IntrusivePtr(IntrusivePtr&& other) noexcept : ptr_(other.release())
|
||||
|
@ -116,6 +118,12 @@ public:
|
|||
std::swap(ptr_, other.ptr_);
|
||||
}
|
||||
|
||||
friend void swap(IntrusivePtr& a, IntrusivePtr& b) noexcept
|
||||
{
|
||||
using std::swap;
|
||||
swap(a.ptr_, b.ptr_);
|
||||
}
|
||||
|
||||
/**
|
||||
* Detaches an object from the automated lifetime management and sets this
|
||||
* intrusive pointer to @c nullptr.
|
||||
|
@ -123,10 +131,7 @@ public:
|
|||
*/
|
||||
pointer release() noexcept
|
||||
{
|
||||
auto result = ptr_;
|
||||
if ( result )
|
||||
ptr_ = nullptr;
|
||||
return result;
|
||||
return std::exchange(ptr_, nullptr);
|
||||
}
|
||||
|
||||
IntrusivePtr& operator=(IntrusivePtr other) noexcept
|
||||
|
@ -161,13 +166,6 @@ public:
|
|||
}
|
||||
|
||||
private:
|
||||
void setPtr(pointer raw_ptr, bool add_ref) noexcept
|
||||
{
|
||||
ptr_ = raw_ptr;
|
||||
if ( raw_ptr && add_ref )
|
||||
Ref(raw_ptr);
|
||||
}
|
||||
|
||||
pointer ptr_ = nullptr;
|
||||
};
|
||||
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue