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

LibWeb: Add fast_is<T>() for some DOM and layout node subclasses

The generic is<T>() uses dynamic_cast which is fine in the majority
of cases, but when one of them shows up in profiles, we can make it
faster by answering the is-a question manually.
This commit is contained in:
Andreas Kling 2021-01-17 09:34:01 +01:00
parent 65fa0c2774
commit fd441b954d
7 changed files with 24 additions and 17 deletions

View file

@ -67,7 +67,7 @@ const BlockBox* Node::containing_block() const
auto* ancestor = parent();
while (ancestor && !is<BlockBox>(*ancestor))
ancestor = ancestor->parent();
return downcast<BlockBox>(ancestor);
return static_cast<const BlockBox*>(ancestor);
};
if (is<TextNode>(*this))
@ -79,9 +79,9 @@ const BlockBox* Node::containing_block() const
auto* ancestor = parent();
while (ancestor && !ancestor->can_contain_boxes_with_position_absolute())
ancestor = ancestor->parent();
while (ancestor && (!is<BlockBox>(ancestor) || ancestor->is_anonymous()))
while (ancestor && (!is<BlockBox>(*ancestor) || ancestor->is_anonymous()))
ancestor = ancestor->containing_block();
return downcast<BlockBox>(ancestor);
return static_cast<const BlockBox*>(ancestor);
}
if (position == CSS::Position::Fixed)