diff options
author | 2023-03-26 01:32:50 +1100 | |
---|---|---|
committer | 2023-03-26 01:32:50 +1100 | |
commit | 4cf33cfe0a427d24d754c134eb94b9d1a67da637 (patch) | |
tree | 71d0864fd5efa77a50ed2061d3a2c6da05c41b33 /src/lib/util/palette.cpp | |
parent | fb81cb16bb19603f7fa0fff3698bdfa32b2896fc (diff) |
Various optimisations to code generaton.
util/bitmap.cpp, util/palette.cpp: Marked lots of things constexpr.
Bitmaps don't throw exceptions on allocation failure, they just become
invalid. Almost nothing in MAME actually checks for this.
emu/profiler.cpp: Abort if the profile stack overflows rather than
throwing an exception. This is a developer feature and if it overflows,
the code is broken. Calling a noreturn noexcept function generates less
code than throwing an exception, which adds up.
util/strformat.cpp: Traded away some unnecessary flexibility for more
compact code. The stream objects must derive from std::basic_ostream
now - they can't just be any old objects with the expected operators.
Diffstat (limited to 'src/lib/util/palette.cpp')
-rw-r--r-- | src/lib/util/palette.cpp | 40 |
1 files changed, 18 insertions, 22 deletions
diff --git a/src/lib/util/palette.cpp b/src/lib/util/palette.cpp index 730800d5249..612dc9042be 100644 --- a/src/lib/util/palette.cpp +++ b/src/lib/util/palette.cpp @@ -8,12 +8,12 @@ ******************************************************************************/ -#include <cassert> - #include "palette.h" -#include <cstdlib> -#include <cmath> + #include <algorithm> +#include <cassert> +#include <cmath> +#include <cstdlib> //************************************************************************** @@ -44,9 +44,7 @@ inline rgb_t palette_t::adjust_palette_entry(rgb_t entry, float brightness, floa // dirty_state - constructor //------------------------------------------------- -palette_client::dirty_state::dirty_state() - : m_mindirty(0), - m_maxdirty(0) +palette_client::dirty_state::dirty_state() : m_mindirty(0), m_maxdirty(0) { } @@ -56,7 +54,7 @@ palette_client::dirty_state::dirty_state() // min/max values //------------------------------------------------- -const uint32_t *palette_client::dirty_state::dirty_list(uint32_t &mindirty, uint32_t &maxdirty) +const uint32_t *palette_client::dirty_state::dirty_list(uint32_t &mindirty, uint32_t &maxdirty) noexcept { // fill in the mindirty/maxdirty mindirty = m_mindirty; @@ -92,7 +90,7 @@ void palette_client::dirty_state::resize(uint32_t colors) // mark_dirty - mark a single entry dirty //------------------------------------------------- -void palette_client::dirty_state::mark_dirty(uint32_t index) +void palette_client::dirty_state::mark_dirty(uint32_t index) noexcept { m_dirty[index / 32] |= 1 << (index % 32); m_mindirty = std::min(m_mindirty, index); @@ -105,7 +103,7 @@ void palette_client::dirty_state::mark_dirty(uint32_t index) // entries as clean //------------------------------------------------- -void palette_client::dirty_state::reset() +void palette_client::dirty_state::reset() noexcept { // erase relevant entries in the new live one if (m_mindirty <= m_maxdirty) @@ -168,20 +166,18 @@ palette_client::~palette_client() // list for a client //------------------------------------------------- -const uint32_t *palette_client::dirty_list(uint32_t &mindirty, uint32_t &maxdirty) +const uint32_t *palette_client::dirty_list(uint32_t &mindirty, uint32_t &maxdirty) noexcept { // if nothing to report, report nothing and don't swap - const uint32_t *result = m_live->dirty_list(mindirty, maxdirty); - if (result == nullptr) - return nullptr; - - // swap the live and previous lists - dirty_state *temp = m_live; - m_live = m_previous; - m_previous = temp; + uint32_t const *const result = m_live->dirty_list(mindirty, maxdirty); + if (result) + { + // swap the live and previous lists + std::swap(m_live, m_previous); - // reset new live one and return the pointer to the previous - m_live->reset(); + // reset new live one and return the pointer to the previous + m_live->reset(); + } return result; } @@ -266,7 +262,7 @@ palette_t::~palette_t() // palette_t - destructor //------------------------------------------------- -void palette_t::deref() +void palette_t::deref() noexcept { if (--m_refcount == 0) delete this; |