From 8fdaa55cfc951459b0ee079839cdf40e88baa2af Mon Sep 17 00:00:00 2001 From: Andrei Karas Date: Wed, 20 Jul 2011 23:03:30 +0300 Subject: Small optimisations. --- src/gui/outfitwindow.h | 12 +++++++++--- src/resources/image.cpp | 30 ++++++++++++++++-------------- 2 files changed, 25 insertions(+), 17 deletions(-) (limited to 'src') diff --git a/src/gui/outfitwindow.h b/src/gui/outfitwindow.h index 2d2f6271b..60634dbdd 100644 --- a/src/gui/outfitwindow.h +++ b/src/gui/outfitwindow.h @@ -28,6 +28,12 @@ #include #include +#ifdef __GNUC__ +#define A_PURE __attribute__ ((pure)) +#else +#define A_PURE +#endif + #define OUTFITS_COUNT 100 #define OUTFIT_ITEM_COUNT 12 @@ -82,9 +88,9 @@ class OutfitWindow : public Window, gcn::ActionListener void unequipNotInOutfit(int outfit); - int keyToNumber(SDLKey key) const; + int keyToNumber(SDLKey key) const A_PURE; - SDLKey numberToKey(int number) const; + SDLKey numberToKey(int number) const A_PURE; void next(); @@ -100,7 +106,7 @@ class OutfitWindow : public Window, gcn::ActionListener void showCurrentOutfit(); - std::string keyName(int number); + std::string keyName(int number) A_PURE; private: Button *mPreviousButton; diff --git a/src/resources/image.cpp b/src/resources/image.cpp index e39eb1edc..6bb0a9faa 100644 --- a/src/resources/image.cpp +++ b/src/resources/image.cpp @@ -165,13 +165,15 @@ Resource *Image::load(void *buffer, unsigned bufferSize, Dye const &dye) Uint32 *pixels = static_cast< Uint32 * >(surf->pixels); for (Uint32 *p_end = pixels + surf->w * surf->h; pixels != p_end; ++pixels) { - int alpha = *pixels & 255; + const Uint32 p = *pixels; + + int alpha = p & 255; if (!alpha) continue; int v[3]; - v[0] = (*pixels >> 24) & 255; - v[1] = (*pixels >> 16) & 255; - v[2] = (*pixels >> 8 ) & 255; + v[0] = (p >> 24) & 255; + v[1] = (p >> 16) & 255; + v[2] = (p >> 8 ) & 255; dye.update(v); *pixels = (v[0] << 24) | (v[1] << 16) | (v[2] << 8) | alpha; } @@ -217,21 +219,21 @@ Image *Image::createTextSurface(SDL_Surface *tmpImage, float alpha) { for (int i = 0; i < sz; ++ i) { - unsigned v = ((static_cast(tmpImage->pixels))[i] - & fmt->Amask) >> fmt->Ashift; + Uint32 c = (static_cast(tmpImage->pixels))[i]; + + unsigned v = (c & fmt->Amask) >> fmt->Ashift; Uint8 a = (v << fmt->Aloss) + (v >> (8 - (fmt->Aloss << 1))); Uint8 a2 = static_cast(static_cast(a) * alpha); - (static_cast(tmpImage->pixels))[i] &= ~fmt->Amask; - (static_cast(tmpImage->pixels))[i] |= - ((a2 >> fmt->Aloss) << fmt->Ashift & fmt->Amask); + c &= ~fmt->Amask; + c |= ((a2 >> fmt->Aloss) << fmt->Ashift & fmt->Amask); + (static_cast(tmpImage->pixels))[i] = c; if (a != 255) hasAlpha = true; alphaChannel[i] = a; - } } @@ -429,10 +431,10 @@ void Image::setAlpha(float alpha) Uint8 a = static_cast( static_cast(sourceAlpha) * mAlpha); - (static_cast(mSDLSurface->pixels))[i] - &= ~fmt->Amask; - (static_cast(mSDLSurface->pixels))[i] - |= ((a >> fmt->Aloss) << fmt->Ashift & fmt->Amask); + Uint32 c = (static_cast(mSDLSurface->pixels))[i]; + c &= ~fmt->Amask; + c |= ((a >> fmt->Aloss) << fmt->Ashift & fmt->Amask); + (static_cast(mSDLSurface->pixels))[i] = c; } } -- cgit v1.2.3-60-g2f50