mirror of
https://github.com/RGBCube/serenity
synced 2025-07-26 20:47:45 +00:00
LibCore+LibGUI: Make it fast to check if a Core::Object is a Widget
This check happens very often in LibGUI code. 25% of time spent layouting the emoji input dialog was wasted on RTTI. Adding a simple fast_is<Widget>() melts almost all of that away.
This commit is contained in:
parent
1cff5fe2ff
commit
30815c25a2
2 changed files with 10 additions and 0 deletions
|
@ -98,6 +98,11 @@ public:
|
||||||
|
|
||||||
virtual StringView class_name() const = 0;
|
virtual StringView class_name() const = 0;
|
||||||
|
|
||||||
|
template<typename T>
|
||||||
|
bool fast_is() const = delete;
|
||||||
|
|
||||||
|
virtual bool is_widget() const { return false; }
|
||||||
|
|
||||||
String const& name() const { return m_name; }
|
String const& name() const { return m_name; }
|
||||||
void set_name(String name) { m_name = move(name); }
|
void set_name(String name) { m_name = move(name); }
|
||||||
|
|
||||||
|
|
|
@ -404,6 +404,8 @@ protected:
|
||||||
void show_or_hide_tooltip();
|
void show_or_hide_tooltip();
|
||||||
|
|
||||||
private:
|
private:
|
||||||
|
virtual bool is_widget() const final { return true; }
|
||||||
|
|
||||||
void handle_paint_event(PaintEvent&);
|
void handle_paint_event(PaintEvent&);
|
||||||
void handle_resize_event(ResizeEvent&);
|
void handle_resize_event(ResizeEvent&);
|
||||||
void handle_mousedown_event(MouseEvent&);
|
void handle_mousedown_event(MouseEvent&);
|
||||||
|
@ -466,6 +468,9 @@ inline Widget const* Widget::parent_widget() const
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
template<>
|
||||||
|
inline bool Core::Object::fast_is<GUI::Widget>() const { return is_widget(); }
|
||||||
|
|
||||||
template<>
|
template<>
|
||||||
struct AK::Formatter<GUI::Widget> : AK::Formatter<Core::Object> {
|
struct AK::Formatter<GUI::Widget> : AK::Formatter<Core::Object> {
|
||||||
};
|
};
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue