mirror of
https://github.com/RGBCube/serenity
synced 2025-07-26 18:57:34 +00:00
AK: Add ALWAYS_INLINE, NEVER_INLINE and FLATTEN macros
It's tedious to write (and look at) [[gnu::always_inline]] etc. :^)
This commit is contained in:
parent
f1a8fb1e88
commit
888e35f0fe
14 changed files with 63 additions and 56 deletions
|
@ -118,7 +118,7 @@ public:
|
|||
void mask(u16 m) { m_address &= m; }
|
||||
|
||||
template<typename T>
|
||||
[[gnu::always_inline]] inline T in()
|
||||
ALWAYS_INLINE T in()
|
||||
{
|
||||
if constexpr (sizeof(T) == 4)
|
||||
return IO::in32(get());
|
||||
|
@ -130,7 +130,7 @@ public:
|
|||
}
|
||||
|
||||
template<typename T>
|
||||
[[gnu::always_inline]] inline void out(T value)
|
||||
ALWAYS_INLINE void out(T value)
|
||||
{
|
||||
if constexpr (sizeof(T) == 4) {
|
||||
IO::out32(get(), value);
|
||||
|
|
|
@ -393,13 +393,13 @@ int dbgprintf(const char* fmt, ...)
|
|||
return ret;
|
||||
}
|
||||
|
||||
[[gnu::always_inline]] inline void stdout_putch(char*&, char ch)
|
||||
ALWAYS_INLINE void stdout_putch(char*&, char ch)
|
||||
{
|
||||
putchar(ch);
|
||||
}
|
||||
|
||||
static FILE* __current_stream = nullptr;
|
||||
[[gnu::always_inline]] inline static void stream_putch(char*&, char ch)
|
||||
ALWAYS_INLINE static void stream_putch(char*&, char ch)
|
||||
{
|
||||
fputc(ch, __current_stream);
|
||||
}
|
||||
|
@ -455,7 +455,7 @@ int sprintf(char* buffer, const char* fmt, ...)
|
|||
}
|
||||
|
||||
static size_t __vsnprintf_space_remaining;
|
||||
[[gnu::always_inline]] inline void sized_buffer_putch(char*& bufptr, char ch)
|
||||
ALWAYS_INLINE void sized_buffer_putch(char*& bufptr, char ch)
|
||||
{
|
||||
if (__vsnprintf_space_remaining) {
|
||||
*bufptr++ = ch;
|
||||
|
|
|
@ -204,7 +204,7 @@ RefPtr<Gfx::Bitmap> load_png_from_memory(const u8* data, size_t length)
|
|||
return bitmap;
|
||||
}
|
||||
|
||||
[[gnu::always_inline]] static inline u8 paeth_predictor(int a, int b, int c)
|
||||
ALWAYS_INLINE static u8 paeth_predictor(int a, int b, int c)
|
||||
{
|
||||
int p = a + b - c;
|
||||
int pa = abs(p - a);
|
||||
|
@ -231,7 +231,7 @@ union [[gnu::packed]] Pixel
|
|||
static_assert(sizeof(Pixel) == 4);
|
||||
|
||||
template<bool has_alpha, u8 filter_type>
|
||||
[[gnu::always_inline]] static inline void unfilter_impl(Gfx::Bitmap& bitmap, int y, const void* dummy_scanline_data)
|
||||
ALWAYS_INLINE static void unfilter_impl(Gfx::Bitmap& bitmap, int y, const void* dummy_scanline_data)
|
||||
{
|
||||
auto* dummy_scanline = (const Pixel*)dummy_scanline_data;
|
||||
if constexpr (filter_type == 0) {
|
||||
|
@ -312,7 +312,7 @@ template<bool has_alpha, u8 filter_type>
|
|||
}
|
||||
}
|
||||
|
||||
[[gnu::noinline]] static void unfilter(PNGLoadingContext& context)
|
||||
NEVER_INLINE FLATTEN static void unfilter(PNGLoadingContext& context)
|
||||
{
|
||||
// First unpack the scanlines to RGBA:
|
||||
switch (context.color_type) {
|
||||
|
|
|
@ -44,18 +44,10 @@
|
|||
# pragma GCC optimize("O3")
|
||||
#endif
|
||||
|
||||
#ifndef ALWAYS_INLINE
|
||||
# if __has_attribute(always_inline)
|
||||
# define ALWAYS_INLINE __attribute__((always_inline))
|
||||
# else
|
||||
# define ALWAYS_INLINE inline
|
||||
# endif
|
||||
#endif
|
||||
|
||||
namespace Gfx {
|
||||
|
||||
template<BitmapFormat format = BitmapFormat::Invalid>
|
||||
static ALWAYS_INLINE Color get_pixel(const Gfx::Bitmap& bitmap, int x, int y)
|
||||
ALWAYS_INLINE Color get_pixel(const Gfx::Bitmap& bitmap, int x, int y)
|
||||
{
|
||||
if constexpr (format == BitmapFormat::Indexed8)
|
||||
return bitmap.palette_color(bitmap.bits(y)[x]);
|
||||
|
@ -752,12 +744,12 @@ void Painter::draw_scaled_bitmap(const Rect& a_dst_rect, const Gfx::Bitmap& sour
|
|||
}
|
||||
}
|
||||
|
||||
[[gnu::flatten]] void Painter::draw_glyph(const Point& point, char ch, Color color)
|
||||
FLATTEN void Painter::draw_glyph(const Point& point, char ch, Color color)
|
||||
{
|
||||
draw_glyph(point, ch, font(), color);
|
||||
}
|
||||
|
||||
[[gnu::flatten]] void Painter::draw_glyph(const Point& point, char ch, const Font& font, Color color)
|
||||
FLATTEN void Painter::draw_glyph(const Point& point, char ch, const Font& font, Color color)
|
||||
{
|
||||
draw_bitmap(point, font.glyph_bitmap(ch), color);
|
||||
}
|
||||
|
@ -936,7 +928,7 @@ void Painter::set_pixel(const Point& p, Color color)
|
|||
m_target->scanline(point.y())[point.x()] = color.value();
|
||||
}
|
||||
|
||||
[[gnu::always_inline]] inline void Painter::set_pixel_with_draw_op(u32& pixel, const Color& color)
|
||||
ALWAYS_INLINE void Painter::set_pixel_with_draw_op(u32& pixel, const Color& color)
|
||||
{
|
||||
if (draw_op() == DrawOp::Copy)
|
||||
pixel = color.value();
|
||||
|
|
|
@ -50,20 +50,20 @@ private:
|
|||
|
||||
class Locker {
|
||||
public:
|
||||
[[gnu::always_inline]] inline explicit Locker(Lock& l)
|
||||
ALWAYS_INLINE explicit Locker(Lock& l)
|
||||
: m_lock(l)
|
||||
{
|
||||
lock();
|
||||
}
|
||||
[[gnu::always_inline]] inline ~Locker() { unlock(); }
|
||||
[[gnu::always_inline]] inline void unlock() { m_lock.unlock(); }
|
||||
[[gnu::always_inline]] inline void lock() { m_lock.lock(); }
|
||||
ALWAYS_INLINE ~Locker() { unlock(); }
|
||||
ALWAYS_INLINE void unlock() { m_lock.unlock(); }
|
||||
ALWAYS_INLINE void lock() { m_lock.lock(); }
|
||||
|
||||
private:
|
||||
Lock& m_lock;
|
||||
};
|
||||
|
||||
[[gnu::always_inline]] inline void Lock::lock()
|
||||
ALWAYS_INLINE void Lock::lock()
|
||||
{
|
||||
int tid = gettid();
|
||||
if (m_holder == tid) {
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue