1
Fork 0
mirror of https://github.com/RGBCube/serenity synced 2025-07-27 18:27:35 +00:00

Everywhere: Stop using NonnullRefPtrVector

This class had slightly confusing semantics and the added weirdness
doesn't seem worth it just so we can say "." instead of "->" when
iterating over a vector of NNRPs.

This patch replaces NonnullRefPtrVector<T> with Vector<NNRP<T>>.
This commit is contained in:
Andreas Kling 2023-03-06 14:17:01 +01:00
parent 104be6c8ac
commit 8a48246ed1
168 changed files with 1280 additions and 1280 deletions

View file

@ -152,7 +152,7 @@ public:
class Object : public ValueNode {
public:
Object() = default;
Object(DeprecatedString name, NonnullRefPtrVector<Node const> properties, NonnullRefPtrVector<Node const> sub_objects)
Object(DeprecatedString name, Vector<NonnullRefPtr<Node const>> properties, Vector<NonnullRefPtr<Node const>> sub_objects)
: m_properties(move(properties))
, m_sub_objects(move(sub_objects))
, m_name(move(name))
@ -182,7 +182,7 @@ public:
{
for (auto const& child : m_properties) {
if (is<KeyValuePair>(child)) {
auto const& property = static_cast<KeyValuePair const&>(child);
auto const& property = static_cast<KeyValuePair const&>(*child);
if (property.key() != "layout" && is<JsonValueNode>(property.value().ptr()))
callback(property.key(), static_ptr_cast<JsonValueNode>(property.value()));
}
@ -207,7 +207,7 @@ public:
for (auto const& child : m_sub_objects) {
// doesn't capture layout as intended, as that's behind a kv-pair
if (is<Object>(child)) {
TRY(callback(static_cast<Object const&>(child)));
TRY(callback(static_cast<Object const&>(*child)));
}
}
@ -218,7 +218,7 @@ public:
{
for (auto const& child : m_properties) {
if (is<KeyValuePair>(child)) {
auto const& property = static_cast<KeyValuePair const&>(child);
auto const& property = static_cast<KeyValuePair const&>(*child);
if (property.key() == "layout") {
VERIFY(is<Object>(property.value().ptr()));
return static_cast<Object const&>(*property.value());
@ -232,7 +232,7 @@ public:
{
for (auto const& child : m_properties) {
if (is<KeyValuePair>(child)) {
auto const& property = static_cast<KeyValuePair const&>(child);
auto const& property = static_cast<KeyValuePair const&>(*child);
if (property.key() == property_name)
return property.value();
}
@ -251,7 +251,7 @@ public:
builder.append('\n');
for (auto const& property : m_properties)
property.format(builder, indentation + 1, false);
property->format(builder, indentation + 1, false);
if (!m_properties.is_empty() && !m_sub_objects.is_empty())
builder.append('\n');
@ -259,7 +259,7 @@ public:
// This loop is necessary as we need to know what the last child is.
for (size_t i = 0; i < m_sub_objects.size(); ++i) {
auto const& child = m_sub_objects[i];
child.format(builder, indentation + 1, false);
child->format(builder, indentation + 1, false);
if (is<Object>(child) && i != m_sub_objects.size() - 1)
builder.append('\n');
@ -274,9 +274,9 @@ public:
private:
// Properties and comments
NonnullRefPtrVector<Node const> m_properties;
Vector<NonnullRefPtr<Node const>> m_properties;
// Sub objects and comments
NonnullRefPtrVector<Node const> m_sub_objects;
Vector<NonnullRefPtr<Node const>> m_sub_objects;
DeprecatedString m_name {};
};
@ -304,18 +304,18 @@ public:
bool has_main_class() const { return m_main_class != nullptr; }
NonnullRefPtrVector<Comment const> leading_comments() const { return m_leading_comments; }
Vector<NonnullRefPtr<Comment const>> leading_comments() const { return m_leading_comments; }
Object const& main_class() const
{
VERIFY(!m_main_class.is_null());
return *m_main_class.ptr();
}
NonnullRefPtrVector<Comment const> trailing_comments() const { return m_trailing_comments; }
Vector<NonnullRefPtr<Comment const>> trailing_comments() const { return m_trailing_comments; }
virtual void format(StringBuilder& builder, size_t indentation, [[maybe_unused]] bool is_inline) const override
{
for (auto const& comment : m_leading_comments)
comment.format(builder, indentation, false);
comment->format(builder, indentation, false);
if (!m_leading_comments.is_empty())
builder.append('\n');
@ -324,13 +324,13 @@ public:
builder.append('\n');
for (auto const& comment : m_trailing_comments)
comment.format(builder, indentation, false);
comment->format(builder, indentation, false);
}
private:
NonnullRefPtrVector<Comment const> m_leading_comments;
Vector<NonnullRefPtr<Comment const>> m_leading_comments;
RefPtr<Object const> m_main_class;
NonnullRefPtrVector<Comment const> m_trailing_comments;
Vector<NonnullRefPtr<Comment const>> m_trailing_comments;
};
}

View file

@ -46,7 +46,7 @@ static ErrorOr<NonnullRefPtr<Object>> parse_gml_object(Queue<Token>& tokens)
tokens.dequeue();
NonnullRefPtrVector<Comment> pending_comments;
Vector<NonnullRefPtr<Comment>> pending_comments;
for (;;) {
if (peek() == Token::Type::RightCurly) {
// End of object

View file

@ -32,7 +32,7 @@ public:
private:
Menubar() = default;
NonnullRefPtrVector<Menu> m_menus;
Vector<NonnullRefPtr<Menu>> m_menus;
};
}

View file

@ -63,46 +63,46 @@ void Statusbar::set_segment_count(size_t count)
void Statusbar::update_segment(size_t index)
{
auto& segment = m_segments.at(index);
if (segment.mode() == Segment::Mode::Auto) {
if (segment.restored_text().is_empty())
segment.set_visible(false);
if (segment->mode() == Segment::Mode::Auto) {
if (segment->restored_text().is_empty())
segment->set_visible(false);
else {
constexpr auto horizontal_padding { 10 };
auto width = font().width(segment.restored_text()) + horizontal_padding;
segment.set_restored_width(width);
segment.set_fixed_width(width);
auto width = font().width(segment->restored_text()) + horizontal_padding;
segment->set_restored_width(width);
segment->set_fixed_width(width);
}
} else if (segment.mode() == Segment::Mode::Fixed) {
if (segment.max_width().is_int()) {
segment.set_restored_width(segment.max_width().as_int());
segment.set_fixed_width(segment.max_width());
} else if (segment->mode() == Segment::Mode::Fixed) {
if (segment->max_width().is_int()) {
segment->set_restored_width(segment->max_width().as_int());
segment->set_fixed_width(segment->max_width());
}
}
if (segment.override_text().is_null()) {
if (segment->override_text().is_null()) {
for (size_t i = 1; i < m_segments.size(); i++) {
if (!text(i).is_empty())
m_segments[i].set_visible(true);
m_segments[i]->set_visible(true);
}
segment.set_text(String::from_utf8(segment.restored_text()).release_value_but_fixme_should_propagate_errors());
segment.set_frame_shape(Gfx::FrameShape::Panel);
if (segment.mode() != Segment::Mode::Proportional)
segment.set_fixed_width(segment.restored_width());
segment->set_text(String::from_utf8(segment->restored_text()).release_value_but_fixme_should_propagate_errors());
segment->set_frame_shape(Gfx::FrameShape::Panel);
if (segment->mode() != Segment::Mode::Proportional)
segment->set_fixed_width(segment->restored_width());
} else {
for (size_t i = 1; i < m_segments.size(); i++) {
if (!m_segments[i].is_clickable())
m_segments[i].set_visible(false);
if (!m_segments[i]->is_clickable())
m_segments[i]->set_visible(false);
}
segment.set_text(String::from_utf8(segment.override_text()).release_value_but_fixme_should_propagate_errors());
segment.set_frame_shape(Gfx::FrameShape::NoFrame);
if (segment.mode() != Segment::Mode::Proportional)
segment.set_fixed_width(SpecialDimension::Grow);
segment->set_text(String::from_utf8(segment->override_text()).release_value_but_fixme_should_propagate_errors());
segment->set_frame_shape(Gfx::FrameShape::NoFrame);
if (segment->mode() != Segment::Mode::Proportional)
segment->set_fixed_width(SpecialDimension::Grow);
}
}
DeprecatedString Statusbar::text(size_t index) const
{
return m_segments.at(index).text().to_deprecated_string();
return m_segments[index]->text().to_deprecated_string();
}
void Statusbar::set_text(DeprecatedString text)
@ -112,13 +112,13 @@ void Statusbar::set_text(DeprecatedString text)
void Statusbar::set_text(size_t index, DeprecatedString text)
{
m_segments.at(index).m_restored_text = move(text);
m_segments[index]->m_restored_text = move(text);
update_segment(index);
}
void Statusbar::set_override_text(DeprecatedString override_text)
{
m_segments.at(0).m_override_text = move(override_text);
m_segments[0]->m_override_text = move(override_text);
update_segment(0);
}

View file

@ -78,7 +78,7 @@ private:
virtual void child_event(Core::ChildEvent&) override;
NonnullRefPtrVector<Segment> m_segments;
Vector<NonnullRefPtr<Segment>> m_segments;
RefPtr<ResizeCorner> m_corner;
};

View file

@ -414,7 +414,7 @@ private:
RefPtr<Action> m_select_all_action;
RefPtr<Action> m_insert_emoji_action;
Core::ElapsedTimer m_triple_click_timer;
NonnullRefPtrVector<Action> m_custom_context_menu_actions;
Vector<NonnullRefPtr<Action>> m_custom_context_menu_actions;
size_t m_reflow_deferred { 0 };
bool m_reflow_requested { false };

View file

@ -32,12 +32,12 @@ ModelIndex TreeViewModel::parent_index(ModelIndex const& index) const
return {};
if (parent_node->parent_node() == nullptr) {
for (size_t row = 0; row < m_nodes.size(); row++)
if (m_nodes.ptr_at(row).ptr() == parent_node)
if (m_nodes[row] == parent_node)
return create_index(static_cast<int>(row), 0, parent_node);
VERIFY_NOT_REACHED();
}
for (size_t row = 0; row < parent_node->parent_node()->child_nodes().size(); row++) {
auto const* child_node_at_row = parent_node->parent_node()->child_nodes().ptr_at(row).ptr();
auto const* child_node_at_row = parent_node->parent_node()->child_nodes()[row].ptr();
if (child_node_at_row == parent_node)
return create_index(static_cast<int>(row), 0, parent_node);
}

View file

@ -59,18 +59,18 @@ public:
Node const* parent_node() const { return m_parent_node; }
Node* parent_node() { return m_parent_node; }
NonnullRefPtrVector<Node> const& child_nodes() const { return m_child_nodes; }
NonnullRefPtrVector<Node>& child_nodes() { return m_child_nodes; }
Vector<NonnullRefPtr<Node>> const& child_nodes() const { return m_child_nodes; }
Vector<NonnullRefPtr<Node>>& child_nodes() { return m_child_nodes; }
private:
DeprecatedString m_text;
Optional<Icon> m_icon;
WeakPtr<Node> m_parent_node;
NonnullRefPtrVector<Node> m_child_nodes;
Vector<NonnullRefPtr<Node>> m_child_nodes;
};
NonnullRefPtrVector<Node> const& nodes() const { return m_nodes; }
NonnullRefPtrVector<Node>& nodes() { return m_nodes; }
Vector<NonnullRefPtr<Node>> const& nodes() const { return m_nodes; }
Vector<NonnullRefPtr<Node>>& nodes() { return m_nodes; }
template<typename NodeType = Node, typename... Args>
NonnullRefPtr<NodeType> add_node(DeprecatedString text, Optional<Icon> icon, Args&&... args)
@ -86,7 +86,7 @@ public:
private:
TreeViewModel() = default;
NonnullRefPtrVector<Node> m_nodes;
Vector<NonnullRefPtr<Node>> m_nodes;
};
}

View file

@ -702,7 +702,7 @@ Widget* Widget::child_at(Gfx::IntPoint point) const
for (int i = children().size() - 1; i >= 0; --i) {
if (!is<Widget>(children()[i]))
continue;
auto& child = verify_cast<Widget>(children()[i]);
auto& child = verify_cast<Widget>(*children()[i]);
if (!child.is_visible())
continue;
if (child.relative_non_grabbable_rect().contains(point))
@ -976,7 +976,7 @@ bool Widget::is_frontmost() const
auto* parent = parent_widget();
if (!parent)
return true;
return &parent->children().last() == this;
return parent->children().last() == this;
}
bool Widget::is_backmost() const
@ -984,7 +984,7 @@ bool Widget::is_backmost() const
auto* parent = parent_widget();
if (!parent)
return true;
return &parent->children().first() == this;
return parent->children().first() == this;
}
Action* Widget::action_for_shortcut(Shortcut const& shortcut)
@ -1036,8 +1036,8 @@ Vector<Widget&> Widget::child_widgets() const
Vector<Widget&> widgets;
widgets.ensure_capacity(children().size());
for (auto& child : const_cast<Widget*>(this)->children()) {
if (is<Widget>(child))
widgets.append(static_cast<Widget&>(child));
if (is<Widget>(*child))
widgets.append(static_cast<Widget&>(*child));
}
return widgets;
}

View file

@ -76,7 +76,7 @@ WizardDialog::WizardDialog(Window* parent_window)
void WizardDialog::push_page(AbstractWizardPage& page)
{
if (!m_page_stack.is_empty())
m_page_stack.last().page_leave();
m_page_stack.last()->page_leave();
m_page_stack.append(page);
m_page_container_widget->remove_all_children();
@ -111,7 +111,7 @@ void WizardDialog::pop_page()
m_page_container_widget->add_child(m_page_stack.last());
update_navigation();
m_page_stack.last().page_enter();
m_page_stack.last()->page_enter();
}
void WizardDialog::update_navigation()

View file

@ -49,6 +49,6 @@ private:
RefPtr<Button> m_next_button;
RefPtr<Button> m_cancel_button;
NonnullRefPtrVector<AbstractWizardPage> m_page_stack;
Vector<NonnullRefPtr<AbstractWizardPage>> m_page_stack;
};
}