mirror of
https://github.com/RGBCube/serenity
synced 2025-07-26 13:17:35 +00:00
LibGfx: Add fast paths for identity/translate-only transforms
This shrinks time spent in AffineTransform::map() from 3.3% to 1.6% when hovering links on ziglang.org.
This commit is contained in:
parent
20ff69cd41
commit
2dacd1252c
1 changed files with 11 additions and 0 deletions
|
@ -89,6 +89,11 @@ AffineTransform& AffineTransform::skew_radians(float x_radians, float y_radians)
|
||||||
|
|
||||||
AffineTransform& AffineTransform::translate(float tx, float ty)
|
AffineTransform& AffineTransform::translate(float tx, float ty)
|
||||||
{
|
{
|
||||||
|
if (is_identity_or_translation()) {
|
||||||
|
m_values[4] += tx;
|
||||||
|
m_values[5] += ty;
|
||||||
|
return *this;
|
||||||
|
}
|
||||||
m_values[4] += tx * m_values[0] + ty * m_values[2];
|
m_values[4] += tx * m_values[0] + ty * m_values[2];
|
||||||
m_values[5] += tx * m_values[1] + ty * m_values[3];
|
m_values[5] += tx * m_values[1] + ty * m_values[3];
|
||||||
return *this;
|
return *this;
|
||||||
|
@ -208,6 +213,12 @@ static T largest_of(T p1, T p2, T p3, T p4)
|
||||||
template<>
|
template<>
|
||||||
FloatRect AffineTransform::map(FloatRect const& rect) const
|
FloatRect AffineTransform::map(FloatRect const& rect) const
|
||||||
{
|
{
|
||||||
|
if (is_identity()) {
|
||||||
|
return rect;
|
||||||
|
}
|
||||||
|
if (is_identity_or_translation()) {
|
||||||
|
return rect.translated(e(), f());
|
||||||
|
}
|
||||||
FloatPoint p1 = map(rect.top_left());
|
FloatPoint p1 = map(rect.top_left());
|
||||||
FloatPoint p2 = map(rect.top_right());
|
FloatPoint p2 = map(rect.top_right());
|
||||||
FloatPoint p3 = map(rect.bottom_right());
|
FloatPoint p3 = map(rect.bottom_right());
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue