mirror of
https://github.com/RGBCube/serenity
synced 2025-05-31 11:28:12 +00:00
AK: Make Vector use size_t for its size and capacity
This commit is contained in:
parent
9c6f7d3e7d
commit
ceec1a7d38
94 changed files with 323 additions and 317 deletions
|
@ -222,7 +222,7 @@ void AbstractTableView::update_headers()
|
|||
|
||||
AbstractTableView::ColumnData& AbstractTableView::column_data(int column) const
|
||||
{
|
||||
if (column >= m_column_data.size())
|
||||
if (static_cast<size_t>(column) >= m_column_data.size())
|
||||
m_column_data.resize(column + 1);
|
||||
return m_column_data.at(column);
|
||||
}
|
||||
|
|
|
@ -58,9 +58,9 @@ void BoxLayout::run(Widget& widget)
|
|||
if (should_log)
|
||||
dbgprintf("BoxLayout: Starting with available size: %s\n", available_size.to_string().characters());
|
||||
|
||||
int last_entry_with_automatic_size = -1;
|
||||
Optional<size_t> last_entry_with_automatic_size;
|
||||
|
||||
for (int i = 0; i < m_entries.size(); ++i) {
|
||||
for (size_t i = 0; i < m_entries.size(); ++i) {
|
||||
auto& entry = m_entries[i];
|
||||
if (entry.type == Entry::Type::Spacer) {
|
||||
++number_of_visible_entries;
|
||||
|
@ -123,7 +123,7 @@ void BoxLayout::run(Widget& widget)
|
|||
int current_x = margins().left();
|
||||
int current_y = margins().top();
|
||||
|
||||
for (int i = 0; i < m_entries.size(); ++i) {
|
||||
for (size_t i = 0; i < m_entries.size(); ++i) {
|
||||
auto& entry = m_entries[i];
|
||||
if (entry.type == Entry::Type::Spacer) {
|
||||
current_x += automatic_size.width();
|
||||
|
@ -141,7 +141,7 @@ void BoxLayout::run(Widget& widget)
|
|||
}
|
||||
ASSERT(entry.widget);
|
||||
|
||||
if (i == last_entry_with_automatic_size) {
|
||||
if (last_entry_with_automatic_size.has_value() && i == last_entry_with_automatic_size.value()) {
|
||||
rect.set_size(automatic_size_for_last_entry);
|
||||
} else {
|
||||
rect.set_size(automatic_size);
|
||||
|
|
|
@ -74,7 +74,7 @@ void ColumnsView::paint_event(PaintEvent& event)
|
|||
|
||||
int column_x = 0;
|
||||
|
||||
for (int i = 0; i < m_columns.size(); i++) {
|
||||
for (size_t i = 0; i < m_columns.size(); i++) {
|
||||
auto& column = m_columns[i];
|
||||
auto* next_column = i + 1 == m_columns.size() ? nullptr : &m_columns[i + 1];
|
||||
|
||||
|
|
|
@ -72,8 +72,8 @@ void CppSyntaxHighlighter::highlight_matching_token_pair()
|
|||
Backward,
|
||||
};
|
||||
|
||||
auto find_span_of_type = [&](int i, CppToken::Type type, CppToken::Type not_type, Direction direction) {
|
||||
int nesting_level = 0;
|
||||
auto find_span_of_type = [&](auto i, CppToken::Type type, CppToken::Type not_type, Direction direction) -> Optional<size_t> {
|
||||
size_t nesting_level = 0;
|
||||
bool forward = direction == Direction::Forward;
|
||||
for (forward ? ++i : --i; forward ? (i < document.spans().size()) : (i >= 0); forward ? ++i : --i) {
|
||||
auto& span = document.spans().at(i);
|
||||
|
@ -85,7 +85,7 @@ void CppSyntaxHighlighter::highlight_matching_token_pair()
|
|||
return i;
|
||||
}
|
||||
}
|
||||
return -1;
|
||||
return {};
|
||||
};
|
||||
|
||||
auto make_buddies = [&](int index0, int index1) {
|
||||
|
@ -114,15 +114,15 @@ void CppSyntaxHighlighter::highlight_matching_token_pair()
|
|||
{ CppToken::Type::LeftBracket, CppToken::Type::RightBracket },
|
||||
};
|
||||
|
||||
for (int i = 0; i < document.spans().size(); ++i) {
|
||||
for (size_t i = 0; i < document.spans().size(); ++i) {
|
||||
auto& span = const_cast<GUI::TextDocumentSpan&>(document.spans().at(i));
|
||||
auto token_type = (CppToken::Type)((uintptr_t)span.data);
|
||||
|
||||
for (auto& pair : pairs) {
|
||||
if (token_type == pair.open && span.range.start() == m_editor->cursor()) {
|
||||
auto buddy = find_span_of_type(i, pair.close, pair.open, Direction::Forward);
|
||||
if (buddy != -1)
|
||||
make_buddies(i, buddy);
|
||||
if (buddy.has_value())
|
||||
make_buddies(i, buddy.value());
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
@ -133,8 +133,8 @@ void CppSyntaxHighlighter::highlight_matching_token_pair()
|
|||
for (auto& pair : pairs) {
|
||||
if (token_type == pair.close && right_of_end == m_editor->cursor()) {
|
||||
auto buddy = find_span_of_type(i, pair.open, pair.close, Direction::Backward);
|
||||
if (buddy != -1)
|
||||
make_buddies(i, buddy);
|
||||
if (buddy.has_value())
|
||||
make_buddies(i, buddy.value());
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
|
|
@ -44,7 +44,7 @@ ModelIndex FileSystemModel::Node::index(const FileSystemModel& model, int column
|
|||
{
|
||||
if (!parent)
|
||||
return {};
|
||||
for (int row = 0; row < parent->children.size(); ++row) {
|
||||
for (size_t row = 0; row < parent->children.size(); ++row) {
|
||||
if (&parent->children[row] == this)
|
||||
return model.create_index(row, column, const_cast<Node*>(this));
|
||||
}
|
||||
|
@ -169,7 +169,7 @@ ModelIndex FileSystemModel::index(const StringView& path, int column) const
|
|||
const Node* node = m_root;
|
||||
if (canonical_path.string() == "/")
|
||||
return m_root->index(*this, column);
|
||||
for (int i = 0; i < canonical_path.parts().size(); ++i) {
|
||||
for (size_t i = 0; i < canonical_path.parts().size(); ++i) {
|
||||
auto& part = canonical_path.parts()[i];
|
||||
bool found = false;
|
||||
for (auto& child : node->children) {
|
||||
|
@ -318,7 +318,7 @@ ModelIndex FileSystemModel::index(int row, int column, const ModelIndex& parent)
|
|||
return {};
|
||||
auto& node = this->node(parent);
|
||||
const_cast<Node&>(node).reify_if_needed(*this);
|
||||
if (row >= node.children.size())
|
||||
if (static_cast<size_t>(row) >= node.children.size())
|
||||
return {};
|
||||
return create_index(row, column, &node.children[row]);
|
||||
}
|
||||
|
|
|
@ -50,7 +50,7 @@ void JsonArrayModel::update()
|
|||
|
||||
Model::ColumnMetadata JsonArrayModel::column_metadata(int column) const
|
||||
{
|
||||
ASSERT(column < m_fields.size());
|
||||
ASSERT(column < static_cast<int>(m_fields.size()));
|
||||
return { 100, m_fields[column].text_alignment };
|
||||
}
|
||||
|
||||
|
|
|
@ -108,7 +108,7 @@ int Menu::realize_menu()
|
|||
dbgprintf("GUI::Menu::realize_menu(): New menu ID: %d\n", m_menu_id);
|
||||
#endif
|
||||
ASSERT(m_menu_id > 0);
|
||||
for (int i = 0; i < m_items.size(); ++i) {
|
||||
for (size_t i = 0; i < m_items.size(); ++i) {
|
||||
auto& item = m_items[i];
|
||||
item.set_menu_id({}, m_menu_id);
|
||||
item.set_identifier({}, i);
|
||||
|
@ -157,7 +157,7 @@ void Menu::unrealize_menu()
|
|||
m_menu_id = 0;
|
||||
}
|
||||
|
||||
Action* Menu::action_at(int index)
|
||||
Action* Menu::action_at(size_t index)
|
||||
{
|
||||
if (index >= m_items.size())
|
||||
return nullptr;
|
||||
|
|
|
@ -50,7 +50,7 @@ public:
|
|||
|
||||
const String& name() const { return m_name; }
|
||||
|
||||
Action* action_at(int);
|
||||
Action* action_at(size_t);
|
||||
|
||||
void add_action(NonnullRefPtr<Action>);
|
||||
void add_separator();
|
||||
|
|
|
@ -264,7 +264,7 @@ String Shortcut::to_string() const
|
|||
parts.append(key_code_to_string(m_key));
|
||||
|
||||
StringBuilder builder;
|
||||
for (int i = 0; i < parts.size(); ++i) {
|
||||
for (size_t i = 0; i < parts.size(); ++i) {
|
||||
builder.append(parts[i]);
|
||||
if (i != parts.size() - 1)
|
||||
builder.append('+');
|
||||
|
|
|
@ -59,7 +59,7 @@ ModelIndex SortingProxyModel::map_to_target(const ModelIndex& index) const
|
|||
{
|
||||
if (!index.is_valid())
|
||||
return {};
|
||||
if (index.row() >= m_row_mappings.size() || index.column() >= column_count())
|
||||
if (static_cast<size_t>(index.row()) >= m_row_mappings.size() || index.column() >= column_count())
|
||||
return {};
|
||||
return target().index(m_row_mappings[index.row()], index.column());
|
||||
}
|
||||
|
@ -143,7 +143,7 @@ void SortingProxyModel::resort()
|
|||
|
||||
selection.clear();
|
||||
for (auto& index : selected_indexes_in_target) {
|
||||
for (int i = 0; i < m_row_mappings.size(); ++i) {
|
||||
for (size_t i = 0; i < m_row_mappings.size(); ++i) {
|
||||
if (m_row_mappings[i] == index.row()) {
|
||||
selection.add(this->index(i, index.column()));
|
||||
continue;
|
||||
|
|
|
@ -24,9 +24,9 @@ void SyntaxHighlighter::cursor_did_change()
|
|||
ASSERT(m_editor);
|
||||
auto& document = m_editor->document();
|
||||
if (m_has_brace_buddies) {
|
||||
if (m_brace_buddies[0].index >= 0 && m_brace_buddies[0].index < document.spans().size())
|
||||
if (m_brace_buddies[0].index >= 0 && m_brace_buddies[0].index < static_cast<int>(document.spans().size()))
|
||||
document.set_span_at_index(m_brace_buddies[0].index, m_brace_buddies[0].span_backup);
|
||||
if (m_brace_buddies[1].index >= 0 && m_brace_buddies[1].index < document.spans().size())
|
||||
if (m_brace_buddies[1].index >= 0 && m_brace_buddies[1].index < static_cast<int>(document.spans().size()))
|
||||
document.set_span_at_index(m_brace_buddies[1].index, m_brace_buddies[1].span_backup);
|
||||
m_has_brace_buddies = false;
|
||||
m_editor->update();
|
||||
|
|
|
@ -145,19 +145,19 @@ void TabWidget::paint_event(PaintEvent& event)
|
|||
|
||||
Gfx::StylePainter::paint_frame(painter, container_rect, palette(), Gfx::FrameShape::Container, Gfx::FrameShadow::Raised, 2);
|
||||
|
||||
for (int i = 0; i < m_tabs.size(); ++i) {
|
||||
for (size_t i = 0; i < m_tabs.size(); ++i) {
|
||||
if (m_tabs[i].widget == m_active_widget)
|
||||
continue;
|
||||
bool hovered = i == m_hovered_tab_index;
|
||||
bool hovered = static_cast<int>(i) == m_hovered_tab_index;
|
||||
auto button_rect = this->button_rect(i);
|
||||
Gfx::StylePainter::paint_tab_button(painter, button_rect, palette(), false, hovered, m_tabs[i].widget->is_enabled());
|
||||
painter.draw_text(button_rect.translated(0, 1), m_tabs[i].title, Gfx::TextAlignment::Center, palette().button_text());
|
||||
}
|
||||
|
||||
for (int i = 0; i < m_tabs.size(); ++i) {
|
||||
for (size_t i = 0; i < m_tabs.size(); ++i) {
|
||||
if (m_tabs[i].widget != m_active_widget)
|
||||
continue;
|
||||
bool hovered = i == m_hovered_tab_index;
|
||||
bool hovered = static_cast<int>(i) == m_hovered_tab_index;
|
||||
auto button_rect = this->button_rect(i);
|
||||
Gfx::StylePainter::paint_tab_button(painter, button_rect, palette(), true, hovered, m_tabs[i].widget->is_enabled());
|
||||
painter.draw_text(button_rect.translated(0, 1), m_tabs[i].title, Gfx::TextAlignment::Center, palette().button_text());
|
||||
|
@ -190,7 +190,7 @@ int TabWidget::TabData::width(const Gfx::Font& font) const
|
|||
|
||||
void TabWidget::mousedown_event(MouseEvent& event)
|
||||
{
|
||||
for (int i = 0; i < m_tabs.size(); ++i) {
|
||||
for (size_t i = 0; i < m_tabs.size(); ++i) {
|
||||
auto button_rect = this->button_rect(i);
|
||||
if (!button_rect.contains(event.position()))
|
||||
continue;
|
||||
|
@ -202,7 +202,7 @@ void TabWidget::mousedown_event(MouseEvent& event)
|
|||
void TabWidget::mousemove_event(MouseEvent& event)
|
||||
{
|
||||
int hovered_tab = -1;
|
||||
for (int i = 0; i < m_tabs.size(); ++i) {
|
||||
for (size_t i = 0; i < m_tabs.size(); ++i) {
|
||||
auto button_rect = this->button_rect(i);
|
||||
if (!button_rect.contains(event.position()))
|
||||
continue;
|
||||
|
@ -243,7 +243,7 @@ void TabWidget::set_tab_position(TabPosition tab_position)
|
|||
|
||||
int TabWidget::active_tab_index() const
|
||||
{
|
||||
for (int i = 0; i < m_tabs.size(); i++) {
|
||||
for (size_t i = 0; i < m_tabs.size(); i++) {
|
||||
if (m_tabs.at(i).widget == m_active_widget)
|
||||
return i;
|
||||
}
|
||||
|
|
|
@ -389,7 +389,7 @@ Optional<TextDocumentSpan> TextDocument::first_non_skippable_span_before(const T
|
|||
|
||||
Optional<TextDocumentSpan> TextDocument::first_non_skippable_span_after(const TextPosition& position) const
|
||||
{
|
||||
for (int i = 0; i < m_spans.size(); ++i) {
|
||||
for (size_t i = 0; i < m_spans.size(); ++i) {
|
||||
if (!m_spans[i].range.contains(position))
|
||||
continue;
|
||||
while ((i + 1) < m_spans.size() && m_spans[i + 1].is_skippable)
|
||||
|
|
|
@ -1352,7 +1352,7 @@ void TextEditor::recompute_visual_lines(size_t line_index)
|
|||
visual_data.visual_line_breaks.append(line.length());
|
||||
|
||||
if (is_line_wrapping_enabled())
|
||||
visual_data.visual_rect = { m_horizontal_content_padding, 0, available_width, visual_data.visual_line_breaks.size() * line_height() };
|
||||
visual_data.visual_rect = { m_horizontal_content_padding, 0, available_width, static_cast<int>(visual_data.visual_line_breaks.size()) * line_height() };
|
||||
else
|
||||
visual_data.visual_rect = { m_horizontal_content_padding, 0, font().width(line.view()), line_height() };
|
||||
}
|
||||
|
|
|
@ -52,7 +52,7 @@ void UndoStack::undo()
|
|||
return;
|
||||
}
|
||||
|
||||
for (int i = 0; i < undo_vector.size(); i++) {
|
||||
for (size_t i = 0; i < undo_vector.size(); i++) {
|
||||
auto& undo_command = undo_vector[i];
|
||||
undo_command.undo();
|
||||
}
|
||||
|
@ -68,7 +68,7 @@ void UndoStack::redo()
|
|||
auto& undo_container = m_stack[m_stack_index - 1];
|
||||
auto& redo_vector = undo_container.m_undo_vector;
|
||||
|
||||
for (int i = redo_vector.size() - 1; i >= 0; i--) {
|
||||
for (int i = static_cast<int>(redo_vector.size()) - 1; i >= 0; i--) {
|
||||
auto& undo_command = redo_vector[i];
|
||||
undo_command.redo();
|
||||
}
|
||||
|
@ -84,7 +84,7 @@ void UndoStack::push(NonnullOwnPtr<Command>&& command)
|
|||
}
|
||||
|
||||
// Clear the elements of the stack before the m_undo_stack_index (Excluding our new element)
|
||||
for (int i = 1; i < m_stack_index; i++)
|
||||
for (size_t i = 1; i < m_stack_index; i++)
|
||||
m_stack.remove(1);
|
||||
|
||||
if (m_stack_index > 0 && !m_stack.is_empty())
|
||||
|
|
|
@ -52,8 +52,8 @@ private:
|
|||
};
|
||||
|
||||
NonnullOwnPtrVector<UndoCommandsContainer> m_stack;
|
||||
int m_stack_index { 0 };
|
||||
int m_last_updated_undo_vector_size { 0 };
|
||||
size_t m_stack_index { 0 };
|
||||
size_t m_last_updated_undo_vector_size { 0 };
|
||||
};
|
||||
|
||||
}
|
||||
|
|
|
@ -677,7 +677,7 @@ void Widget::focus_previous_widget()
|
|||
void Widget::focus_next_widget()
|
||||
{
|
||||
auto focusable_widgets = window()->focusable_widgets();
|
||||
for (int i = 0; i < focusable_widgets.size(); ++i) {
|
||||
for (size_t i = 0; i < focusable_widgets.size(); ++i) {
|
||||
if (focusable_widgets[i] != this)
|
||||
continue;
|
||||
if (i < focusable_widgets.size() - 1)
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue