Skip to content

Commit

Permalink
AK: Remove virtual destructors from non-virtual classes
Browse files Browse the repository at this point in the history
Problem:
- Some classes have `virtual` destructors despite not having any
  virtual functions. This causes the classes to have a v-table and
  perform extra jumps at destruction time when there is no need.

Solution:
- Remove `virtual` keyword from destructors where there are no other
  virtual functions.
- Remove the destructor completely when the default destructor can be
  used.
  • Loading branch information
ldm5180 authored and awesomekling committed Apr 23, 2021
1 parent fcd3b9a commit 4378d36
Show file tree
Hide file tree
Showing 2 changed files with 2 additions and 4 deletions.
2 changes: 1 addition & 1 deletion AK/IntrusiveRedBlackTree.h
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ template<Integral K, typename V, IntrusiveRedBlackTreeNode<K> V::*member>
class IntrusiveRedBlackTree : public BaseRedBlackTree<K> {
public:
IntrusiveRedBlackTree() = default;
virtual ~IntrusiveRedBlackTree() override
~IntrusiveRedBlackTree()
{
clear();
}
Expand Down
4 changes: 1 addition & 3 deletions AK/RedBlackTree.h
Original file line number Diff line number Diff line change
Expand Up @@ -33,12 +33,10 @@ class BaseRedBlackTree {
: key(key)
{
}
virtual ~Node() {};
};

protected:
BaseRedBlackTree() = default; // These are protected to ensure no one instantiates the leaky base red black tree directly
virtual ~BaseRedBlackTree() {};

void rotate_left(Node* subtree_root)
{
Expand Down Expand Up @@ -418,7 +416,7 @@ template<Integral K, typename V>
class RedBlackTree : public BaseRedBlackTree<K> {
public:
RedBlackTree() = default;
virtual ~RedBlackTree() override
~RedBlackTree()
{
clear();
}
Expand Down

0 comments on commit 4378d36

Please sign in to comment.