mirror of
https://github.com/LadybirdBrowser/ladybird.git
synced 2024-09-30 00:31:14 +00:00
LibIDL: Fix bug where entire EffectiveOverloadSet was erased
There was a funny bug here: by storing the "last matched item" as a pointer, and then using Vector::remove_all_matching() to remove all items that didn't have that exact address, we would end up removing everything unless the last item matched was the very first item. (This happened because every time an item was removed from the vector, the remaining contents shift one step towards the start of the vector, affecting item addresses.) This patch fixes the issue by storing the last match as an index.
This commit is contained in:
parent
c266284559
commit
b1f8c5879f
Notes:
sideshowbarker
2024-07-17 03:51:04 +09:00
Author: https://github.com/awesomekling Commit: https://github.com/SerenityOS/serenity/commit/b1f8c5879f Pull-request: https://github.com/SerenityOS/serenity/pull/16249 Reviewed-by: https://github.com/AnthonyIacono Reviewed-by: https://github.com/AtkinsSJ ✅
|
@ -214,9 +214,9 @@ int EffectiveOverloadSet::distinguishing_argument_index()
|
|||
|
||||
void EffectiveOverloadSet::remove_all_other_entries()
|
||||
{
|
||||
m_items.remove_all_matching([this](auto const& item) {
|
||||
return &item != m_last_matching_item;
|
||||
});
|
||||
Vector<Item> new_items;
|
||||
new_items.append(m_items[*m_last_matching_item_index]);
|
||||
m_items = move(new_items);
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
@ -432,13 +432,14 @@ public:
|
|||
template<typename Matches>
|
||||
bool has_overload_with_matching_argument_at_index(size_t index, Matches matches)
|
||||
{
|
||||
for (auto const& item : m_items) {
|
||||
for (size_t i = 0; i < m_items.size(); ++i) {
|
||||
auto const& item = m_items[i];
|
||||
if (matches(item.types[index], item.optionality_values[index])) {
|
||||
m_last_matching_item = &item;
|
||||
m_last_matching_item_index = i;
|
||||
return true;
|
||||
}
|
||||
}
|
||||
m_last_matching_item = nullptr;
|
||||
m_last_matching_item_index = {};
|
||||
return false;
|
||||
}
|
||||
|
||||
|
@ -449,7 +450,7 @@ private:
|
|||
Vector<Item> m_items;
|
||||
size_t m_argument_count;
|
||||
|
||||
Item const* m_last_matching_item { nullptr };
|
||||
Optional<size_t> m_last_matching_item_index;
|
||||
};
|
||||
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue