mirror of
https://github.com/LadybirdBrowser/ladybird.git
synced 2025-04-21 20:15:17 +00:00
Everywhere: Don't promote float to double where not needed
The `float => double => float` round trip seen in a couple of places might pessimize the code. Even if it's truncated to an int in the end, it's weird not to use the functions with the `f` suffixes when working with single precision floats.
This commit is contained in:
parent
01a0aa6e0b
commit
f14a4994b0
Notes:
sideshowbarker
2024-07-18 10:06:16 +09:00
Author: https://github.com/BertalanD Commit: https://github.com/SerenityOS/serenity/commit/f14a4994b04 Pull-request: https://github.com/SerenityOS/serenity/pull/8470 Reviewed-by: https://github.com/Dexesttp Reviewed-by: https://github.com/Hendiadyoin1 Reviewed-by: https://github.com/alimpfard Reviewed-by: https://github.com/gunnarbeutner ✅
6 changed files with 16 additions and 16 deletions
|
@ -94,7 +94,7 @@ private:
|
|||
if (value >= 0) {
|
||||
painter.draw_line(
|
||||
{ rect.x() + i, rect.bottom() },
|
||||
{ rect.x() + i, rect.top() + (int)(round(rect.height() - (value * rect.height()))) },
|
||||
{ rect.x() + i, rect.top() + (int)(roundf(rect.height() - (value * rect.height()))) },
|
||||
m_graph_color);
|
||||
} else {
|
||||
painter.draw_line(
|
||||
|
|
|
@ -18,7 +18,7 @@ bool AffineTransform::is_identity() const
|
|||
static float hypotenuse(float x, float y)
|
||||
{
|
||||
// FIXME: This won't handle overflow :(
|
||||
return sqrt(x * x + y * y);
|
||||
return sqrtf(x * x + y * y);
|
||||
}
|
||||
|
||||
float AffineTransform::x_scale() const
|
||||
|
|
|
@ -420,8 +420,8 @@ RefPtr<Gfx::Bitmap> Bitmap::scaled(float sx, float sy) const
|
|||
auto p = static_cast<float>(x) * static_cast<float>(old_width - 1) / static_cast<float>(new_width - 1);
|
||||
auto q = static_cast<float>(y) * static_cast<float>(old_height - 1) / static_cast<float>(new_height - 1);
|
||||
|
||||
int i = floor(p);
|
||||
int j = floor(q);
|
||||
int i = floorf(p);
|
||||
int j = floorf(q);
|
||||
float u = p - static_cast<float>(i);
|
||||
float v = q - static_cast<float>(j);
|
||||
|
||||
|
@ -443,7 +443,7 @@ RefPtr<Gfx::Bitmap> Bitmap::scaled(float sx, float sy) const
|
|||
for (int x = 0; x < new_width - 1; x++) {
|
||||
auto p = static_cast<float>(x) * static_cast<float>(old_width - 1) / static_cast<float>(new_width - 1);
|
||||
|
||||
int i = floor(p);
|
||||
int i = floorf(p);
|
||||
float u = p - static_cast<float>(i);
|
||||
|
||||
auto a = get_pixel(i, old_bottom_y);
|
||||
|
@ -458,7 +458,7 @@ RefPtr<Gfx::Bitmap> Bitmap::scaled(float sx, float sy) const
|
|||
for (int y = 0; y < new_height - 1; y++) {
|
||||
auto q = static_cast<float>(y) * static_cast<float>(old_height - 1) / static_cast<float>(new_height - 1);
|
||||
|
||||
int j = floor(q);
|
||||
int j = floorf(q);
|
||||
float v = q - static_cast<float>(j);
|
||||
|
||||
auto c = get_pixel(old_right_x, j);
|
||||
|
|
|
@ -1902,7 +1902,7 @@ void Painter::for_each_line_segment_on_elliptical_arc(const FloatPoint& p1, cons
|
|||
if (theta_delta < 0) {
|
||||
swap(start, end);
|
||||
theta_1 = theta_1 + theta_delta;
|
||||
theta_delta = fabs(theta_delta);
|
||||
theta_delta = fabsf(theta_delta);
|
||||
}
|
||||
|
||||
auto relative_start = start - center;
|
||||
|
|
|
@ -270,8 +270,8 @@ void Rasterizer::draw_line(Gfx::FloatPoint p0, Gfx::FloatPoint p1)
|
|||
}
|
||||
|
||||
float dxdy = (p1.x() - p0.x()) / (p1.y() - p0.y());
|
||||
u32 y0 = floor(p0.y());
|
||||
u32 y1 = ceil(p1.y());
|
||||
u32 y0 = floorf(p0.y());
|
||||
u32 y1 = ceilf(p1.y());
|
||||
float x_cur = p0.x();
|
||||
|
||||
for (u32 y = y0; y < y1; y++) {
|
||||
|
@ -289,8 +289,8 @@ void Rasterizer::draw_line(Gfx::FloatPoint p0, Gfx::FloatPoint p1)
|
|||
x1 = x_cur;
|
||||
x0 = x_next;
|
||||
}
|
||||
float x0_floor = floor(x0);
|
||||
float x1_ceil = ceil(x1);
|
||||
float x0_floor = floorf(x0);
|
||||
float x1_ceil = ceilf(x1);
|
||||
u32 x0i = x0_floor;
|
||||
|
||||
if (x1_ceil <= x0_floor + 1.0f) {
|
||||
|
@ -304,7 +304,7 @@ void Rasterizer::draw_line(Gfx::FloatPoint p0, Gfx::FloatPoint p1)
|
|||
dydx = -dydx;
|
||||
|
||||
float x0_right = 1.0f - (x0 - x0_floor);
|
||||
u32 x1_floor_i = floor(x1);
|
||||
u32 x1_floor_i = floorf(x1);
|
||||
float area_upto_here = 0.5f * x0_right * x0_right * dydx;
|
||||
m_data[line_offset + x0i] += direction * area_upto_here;
|
||||
for (u32 x = x0i + 1; x < x1_floor_i; x++) {
|
||||
|
@ -478,8 +478,8 @@ void Glyf::Glyph::raster_inner(Rasterizer& rasterizer, Gfx::AffineTransform& aff
|
|||
|
||||
RefPtr<Gfx::Bitmap> Glyf::Glyph::raster_simple(float x_scale, float y_scale) const
|
||||
{
|
||||
u32 width = (u32)(ceil((m_xmax - m_xmin) * x_scale)) + 2;
|
||||
u32 height = (u32)(ceil((m_ymax - m_ymin) * y_scale)) + 2;
|
||||
u32 width = (u32)(ceilf((m_xmax - m_xmin) * x_scale)) + 2;
|
||||
u32 height = (u32)(ceilf((m_ymax - m_ymin) * y_scale)) + 2;
|
||||
Rasterizer rasterizer(Gfx::IntSize(width, height));
|
||||
auto affine = Gfx::AffineTransform().scale(x_scale, -y_scale).translate(-m_xmin, -m_ymax);
|
||||
raster_inner(rasterizer, affine);
|
||||
|
|
|
@ -106,8 +106,8 @@ public:
|
|||
template<typename GlyphCb>
|
||||
RefPtr<Gfx::Bitmap> raster_composite(float x_scale, float y_scale, GlyphCb glyph_callback) const
|
||||
{
|
||||
u32 width = (u32)(ceil((m_xmax - m_xmin) * x_scale)) + 1;
|
||||
u32 height = (u32)(ceil((m_ymax - m_ymin) * y_scale)) + 1;
|
||||
u32 width = (u32)(ceilf((m_xmax - m_xmin) * x_scale)) + 1;
|
||||
u32 height = (u32)(ceilf((m_ymax - m_ymin) * y_scale)) + 1;
|
||||
Rasterizer rasterizer(Gfx::IntSize(width, height));
|
||||
auto affine = Gfx::AffineTransform().scale(x_scale, -y_scale).translate(-m_xmin, -m_ymax);
|
||||
ComponentIterator component_iterator(m_slice);
|
||||
|
|
Loading…
Add table
Reference in a new issue