AK: Let's call decrementing reference counts "unref" instead of "deref"

It always bothered me that we're using the overloaded "dereference"
term for this. Let's call it "unreference" instead. :^)
This commit is contained in:
Andreas Kling 2020-01-23 15:14:21 +01:00
parent 4aa1b5b40e
commit 3de5439579
12 changed files with 24 additions and 24 deletions

View file

@ -176,7 +176,7 @@ void JsonValue::clear()
{
switch (m_type) {
case Type::String:
m_value.as_string->deref();
m_value.as_string->unref();
break;
case Type::Object:
delete m_value.as_object;

View file

@ -46,10 +46,10 @@ inline void ref_if_not_null(T* ptr)
}
template<typename T>
inline void deref_if_not_null(T* ptr)
inline void unref_if_not_null(T* ptr)
{
if (ptr)
ptr->deref();
ptr->unref();
}
template<typename T>
@ -103,7 +103,7 @@ public:
}
~NonnullRefPtr()
{
deref_if_not_null(m_ptr);
unref_if_not_null(m_ptr);
m_ptr = nullptr;
#ifdef SANITIZE_PTRS
if constexpr (sizeof(T*) == 8)

View file

@ -87,7 +87,7 @@ protected:
template<typename T>
class RefCounted : public RefCountedBase {
public:
void deref()
void unref()
{
deref_base();
if (m_ref_count == 0) {

View file

@ -198,7 +198,7 @@ public:
void clear()
{
deref_if_not_null(m_ptr);
unref_if_not_null(m_ptr);
m_ptr = nullptr;
}

View file

@ -40,7 +40,7 @@ TEST_CASE(basics)
EXPECT_EQ(object->ref_count(), 1);
object->ref();
EXPECT_EQ(object->ref_count(), 2);
object->deref();
object->unref();
EXPECT_EQ(object->ref_count(), 1);
{

View file

@ -40,7 +40,7 @@ TEST_CASE(basics)
EXPECT_EQ(object->ref_count(), 1);
object->ref();
EXPECT_EQ(object->ref_count(), 2);
object->deref();
object->unref();
EXPECT_EQ(object->ref_count(), 1);
{

View file

@ -105,7 +105,12 @@ int main(int argc, char** argv)
unveil(nullptr, nullptr);
auto window = GWindow::construct();
window->set_title("System Monitor");
window->set_rect(20, 200, 680, 400);
auto keeper = GWidget::construct();
window->set_main_widget(keeper);
keeper->set_layout(make<GBoxLayout>(Orientation::Vertical));
keeper->set_fill_with_background_color(true);
keeper->layout()->set_margins({ 4, 4, 4, 4 });
@ -140,7 +145,7 @@ int main(int argc, char** argv)
process_table_view->refresh();
if (auto* memory_stats_widget = MemoryStatsWidget::the())
memory_stats_widget->refresh();
});
}, window);
auto kill_action = GAction::create("Kill process", { Mod_Ctrl, Key_K }, GraphicsBitmap::load_from_file("/res/icons/kill16.png"), [process_table_view](const GAction&) {
pid_t pid = process_table_view->selected_pid();
@ -164,11 +169,6 @@ int main(int argc, char** argv)
toolbar->add_action(stop_action);
toolbar->add_action(continue_action);
auto window = GWindow::construct();
window->set_title("System Monitor");
window->set_rect(20, 200, 680, 400);
window->set_main_widget(keeper);
auto menubar = make<GMenuBar>();
auto app_menu = GMenu::construct("System Monitor");
app_menu->add_action(GCommonActions::make_quit_action([](auto&) {

View file

@ -35,7 +35,7 @@ Shared ownership is implemented via reference counting.
NonnullRefPtr<T> is a special variant of RefPtr with one additional property: it cannot be null. NonnullRefPtr is suitable as a return type from functions that are guaranteed to never return null, and as an argument type where the argument may not be null. In other words, if RefPtr is "\*", then NonnullRefPtr is "&".
Objects can only be held by RefPtr if they meet certain criteria. Specifically, they need to implement the functions `ref()` and `deref()`.
Objects can only be held by RefPtr if they meet certain criteria. Specifically, they need to implement the functions `ref()` and `unref()`.
To make a class T reference counted, you can simply make it inherit from RefCounted<T>. This will add all the necessary pieces to T.

View file

@ -46,7 +46,7 @@ public:
++m_retain_count;
}
void deref()
void unref()
{
ASSERT(m_retain_count);
if (!--m_retain_count) {

View file

@ -61,13 +61,13 @@ void GVariant::clear()
{
switch (m_type) {
case Type::String:
AK::deref_if_not_null(m_value.as_string);
AK::unref_if_not_null(m_value.as_string);
break;
case Type::Bitmap:
AK::deref_if_not_null(m_value.as_bitmap);
AK::unref_if_not_null(m_value.as_bitmap);
break;
case Type::Icon:
AK::deref_if_not_null(m_value.as_icon);
AK::unref_if_not_null(m_value.as_icon);
break;
default:
break;

View file

@ -48,7 +48,7 @@ public:
++m_ref_count;
}
void deref()
void unref()
{
ASSERT(m_ref_count);
if (!--m_ref_count) {
@ -60,7 +60,7 @@ public:
for (auto* child = m_first_child; child; child = next_child) {
next_child = child->m_next_sibling;
child->m_parent = nullptr;
child->deref();
child->unref();
}
delete static_cast<T*>(this);
}
@ -221,7 +221,7 @@ inline NonnullRefPtr<T> TreeNode<T>::remove_child(NonnullRefPtr<T> node, bool ca
if (call_removed_from)
node->removed_from(static_cast<T&>(*this));
node->deref();
node->unref();
return node;
}

View file

@ -81,11 +81,11 @@ private:
if (m_on_complete) {
CEventLoop::main().post_event(*this, make<CDeferredInvocationEvent>([this](CObject&) {
m_on_complete(m_result.release_value());
this->deref();
this->unref();
}));
CEventLoop::main().wake();
} else
this->deref();
this->unref();
});
}