Some fixes to readability-else-after-return

This commit is contained in:
David Capello 2024-02-29 10:26:47 -03:00
parent 667335be62
commit cfb663f820
14 changed files with 46 additions and 82 deletions

View File

@ -720,24 +720,21 @@ Workspace* App::workspace() const
{ {
if (m_mainWindow) if (m_mainWindow)
return m_mainWindow->getWorkspace(); return m_mainWindow->getWorkspace();
else return nullptr;
return nullptr;
} }
ContextBar* App::contextBar() const ContextBar* App::contextBar() const
{ {
if (m_mainWindow) if (m_mainWindow)
return m_mainWindow->getContextBar(); return m_mainWindow->getContextBar();
else return nullptr;
return nullptr;
} }
Timeline* App::timeline() const Timeline* App::timeline() const
{ {
if (m_mainWindow) if (m_mainWindow)
return m_mainWindow->getTimeline(); return m_mainWindow->getTimeline();
else return nullptr;
return nullptr;
} }
Preferences& App::preferences() const Preferences& App::preferences() const
@ -866,8 +863,7 @@ PixelFormat app_get_current_pixel_format()
Doc* doc = ctx->activeDocument(); Doc* doc = ctx->activeDocument();
if (doc) if (doc)
return doc->sprite()->pixelFormat(); return doc->sprite()->pixelFormat();
else return IMAGE_RGB;
return IMAGE_RGB;
} }
int app_get_color_to_clear_layer(Layer* layer) int app_get_color_to_clear_layer(Layer* layer)

View File

@ -48,8 +48,7 @@ namespace app {
auto it = m_params.find(name); auto it = m_params.find(name);
if (it != m_params.end()) if (it != m_params.end())
return it->second; return it->second;
else return std::string();
return std::string();
} }
void operator|=(const Params& params) { void operator|=(const Params& params) {

View File

@ -37,16 +37,14 @@ namespace app {
const std::lock_guard lock(m_token_mutex); const std::lock_guard lock(m_token_mutex);
if (m_token) if (m_token)
return m_token->canceled(); return m_token->canceled();
else return false;
return false;
} }
float progress() const { float progress() const {
const std::lock_guard lock(m_token_mutex); const std::lock_guard lock(m_token_mutex);
if (m_token) if (m_token)
return m_token->progress(); return m_token->progress();
else return 0.0f;
return 0.0f;
} }
void cancel() { void cancel() {

View File

@ -75,8 +75,7 @@ namespace doc {
Image* originalImage() const { Image* originalImage() const {
if (m_backupImage) if (m_backupImage)
return m_backupImage.get(); return m_backupImage.get();
else return m_image.get();
return m_image.get();
} }
private: private:

View File

@ -1,5 +1,5 @@
// Aseprite Document Library // Aseprite Document Library
// Copyright (c) 2018-2023 Igara Studio S.A. // Copyright (c) 2018-2024 Igara Studio S.A.
// Copyright (c) 2001-2015 David Capello // Copyright (c) 2001-2015 David Capello
// //
// This file is released under the terms of the MIT license. // This file is released under the terms of the MIT license.
@ -53,13 +53,11 @@ namespace doc {
if (rgba_geta(a) == 0) { if (rgba_geta(a) == 0) {
if (rgba_geta(b) == 0) if (rgba_geta(b) == 0)
return true; return true;
else
return false;
}
else if (rgba_geta(b) == 0)
return false; return false;
else }
return a == b; if (rgba_geta(b) == 0)
return false;
return a == b;
} }
}; };
@ -98,13 +96,11 @@ namespace doc {
if (graya_geta(a) == 0) { if (graya_geta(a) == 0) {
if (graya_geta(b) == 0) if (graya_geta(b) == 0)
return true; return true;
else
return false;
}
else if (graya_geta(b) == 0)
return false; return false;
else }
return a == b; if (graya_geta(b) == 0)
return false;
return a == b;
} }
}; };

View File

@ -1,5 +1,5 @@
// Aseprite Document Library // Aseprite Document Library
// Copyright (c) 2022 Igara Studio S.A. // Copyright (c) 2022-2024 Igara Studio S.A.
// Copyright (c) 2017 David Capello // Copyright (c) 2017 David Capello
// //
// This file is released under the terms of the MIT license. // This file is released under the terms of the MIT license.
@ -72,14 +72,12 @@ namespace doc {
T* operator*() { T* operator*() {
if (m_it != m_end) if (m_it != m_end)
return m_it->value(); return m_it->value();
else return nullptr;
return nullptr;
} }
T* operator->() { T* operator->() {
if (m_it != m_end) if (m_it != m_end)
return m_it->value(); return m_it->value();
else return nullptr;
return nullptr;
} }
private: private:
iterator m_it, m_next; iterator m_it, m_next;
@ -154,8 +152,7 @@ namespace doc {
it->value() && it->value() &&
frame >= it->frame()) frame >= it->frame())
return it->value(); return it->value();
else return nullptr;
return nullptr;
} }
iterator begin() { return m_keys.begin(); } iterator begin() { return m_keys.begin(); }
@ -185,15 +182,13 @@ namespace doc {
frame_t fromFrame() const { frame_t fromFrame() const {
if (!m_keys.empty()) if (!m_keys.empty())
return m_keys.front().frame(); return m_keys.front().frame();
else return -1;
return -1;
} }
frame_t toFrame() const { frame_t toFrame() const {
if (!m_keys.empty()) if (!m_keys.empty())
return m_keys.back().frame(); return m_keys.back().frame();
else return -1;
return -1;
} }
Range range(const frame_t from, Range range(const frame_t from,

View File

@ -73,8 +73,7 @@ namespace doc {
ASSERT(i >= 0); ASSERT(i >= 0);
if (i >= 0 && i < size()) if (i >= 0 && i < size())
return m_colors[i]; return m_colors[i];
else return 0;
return 0;
} }
color_t getEntry(int i) const { color_t getEntry(int i) const {
return entry(i); return entry(i);

View File

@ -54,8 +54,7 @@ namespace doc {
//ASSERT(index >= 0 && index < size()); //ASSERT(index >= 0 && index < size());
if (index >= 0 && index < size()) if (index >= 0 && index < size())
return m_map[index]; return m_map[index];
else return index; // No remap
return index; // No remap
} }
void merge(const Remap& other); void merge(const Remap& other);

View File

@ -84,8 +84,7 @@ namespace doc {
ImageRef get(const tile_index ti) const { ImageRef get(const tile_index ti) const {
if (ti >= 0 && ti < size()) if (ti >= 0 && ti < size())
return m_tiles[ti].image; return m_tiles[ti].image;
else return ImageRef(nullptr);
return ImageRef(nullptr);
} }
void set(const tile_index ti, void set(const tile_index ti,
const ImageRef& image); const ImageRef& image);
@ -93,8 +92,7 @@ namespace doc {
UserData& getTileData(const tile_index ti) const { UserData& getTileData(const tile_index ti) const {
if (ti >= 0 && ti < size()) if (ti >= 0 && ti < size())
return const_cast<UserData&>(m_tiles[ti].data); return const_cast<UserData&>(m_tiles[ti].data);
else return kNoUserData;
return kNoUserData;
} }
void setTileData(const tile_index ti, void setTileData(const tile_index ti,
const UserData& userData); const UserData& userData);

View File

@ -38,8 +38,7 @@ namespace doc {
Tileset* get(const tileset_index tsi) const { Tileset* get(const tileset_index tsi) const {
if (tsi < size()) if (tsi < size())
return m_tilesets[tsi]; return m_tilesets[tsi];
else return nullptr;
return nullptr;
} }
tileset_index getIndex(const Tileset *tileset) { tileset_index getIndex(const Tileset *tileset) {

View File

@ -52,17 +52,13 @@ namespace fixmath {
errno = ERANGE; errno = ERANGE;
return -0x7FFFFFFF; return -0x7FFFFFFF;
} }
else return result;
return result;
} }
else { if ((x > 0) && (y > 0)) {
if ((x > 0) && (y > 0)) { errno = ERANGE;
errno = ERANGE; return 0x7FFFFFFF;
return 0x7FFFFFFF;
}
else
return result;
} }
return result;
} }
inline fixed fixsub(fixed x, fixed y) { inline fixed fixsub(fixed x, fixed y) {
@ -73,17 +69,13 @@ namespace fixmath {
errno = ERANGE; errno = ERANGE;
return -0x7FFFFFFF; return -0x7FFFFFFF;
} }
else return result;
return result;
} }
else { if ((x > 0) && (y < 0)) {
if ((x > 0) && (y < 0)) { errno = ERANGE;
errno = ERANGE; return 0x7FFFFFFF;
return 0x7FFFFFFF;
}
else
return result;
} }
return result;
} }
inline fixed fixmul(fixed x, fixed y) { inline fixed fixmul(fixed x, fixed y) {
@ -95,16 +87,14 @@ namespace fixmath {
errno = ERANGE; errno = ERANGE;
return (x < 0) ? -0x7FFFFFFF : 0x7FFFFFFF; return (x < 0) ? -0x7FFFFFFF : 0x7FFFFFFF;
} }
else return ftofix(fixtof(x) / fixtof(y));
return ftofix(fixtof(x) / fixtof(y));
} }
inline int fixfloor(fixed x) { inline int fixfloor(fixed x) {
/* (x >> 16) is not portable */ /* (x >> 16) is not portable */
if (x >= 0) if (x >= 0)
return (x >> 16); return (x >> 16);
else return ~((~x) >> 16);
return ~((~x) >> 16);
} }
inline int fixceil(fixed x) { inline int fixceil(fixed x) {

View File

@ -72,10 +72,9 @@ namespace render {
if (n == 2) if (n == 2)
return D2[i*2 + j]; return D2[i*2 + j];
else return
return + 4*Dn(i%(n/2), j%(n/2), n/2)
+ 4*Dn(i%(n/2), j%(n/2), n/2) + Dn(i/(n/2), j/(n/2), 2);
+ Dn(i/(n/2), j/(n/2), 2);
} }
}; };

View File

@ -76,16 +76,14 @@ namespace render {
inline int Zoom::remove(int x) const { inline int Zoom::remove(int x) const {
if (x < 0) if (x < 0)
return (x * m_den / m_num) - 1; return (x * m_den / m_num) - 1;
else return (x * m_den / m_num);
return (x * m_den / m_num);
} }
inline int Zoom::removeCeiling(int x) const { inline int Zoom::removeCeiling(int x) const {
int v = x * m_den; int v = x * m_den;
if (x < 0) if (x < 0)
return (v / m_num); return (v / m_num);
else return (v / m_num) + (v % m_num != 0);
return (v / m_num) + (v % m_num != 0);
} }
inline gfx::Rect Zoom::apply(const gfx::Rect& r) const { inline gfx::Rect Zoom::apply(const gfx::Rect& r) const {

View File

@ -142,8 +142,7 @@ namespace ui {
gfx::Color bgColor() const { gfx::Color bgColor() const {
if (gfx::geta(m_bgColor) == 0 && m_parent) if (gfx::geta(m_bgColor) == 0 && m_parent)
return m_parent->bgColor(); return m_parent->bgColor();
else return m_bgColor;
return m_bgColor;
} }
// Sets the background color of the widget // Sets the background color of the widget