diff --git a/include/dspatch/SignalBus.h b/include/dspatch/SignalBus.h index f655e2ac..9b6656fd 100644 --- a/include/dspatch/SignalBus.h +++ b/include/dspatch/SignalBus.h @@ -109,34 +109,18 @@ inline fast_any::any* SignalBus::GetSignal( int signalIndex ) { // You might be thinking: Why the raw pointer return here? - // This is for usability, design, and performance reasons. Usability, because a pointer allows - // the user to manipulate the contained value externally. Design, because DSPatch doesn't use - // exceptions - a nullptr return here is the equivalent of "signal does not exist". - // Performance, because returning a smart pointer means having to store the value as a smart - // pointer too - this adds yet another level of indirection to the value, as well as some - // reference counting overhead. These Get() and Set() methods are VERY frequently called, so - // doing as little as possible with the data here is best. - - if ( (size_t)signalIndex < _signals.size() ) - { - return &_signals[signalIndex]; - } - else - { - return nullptr; - } + // This is for usability and performance reasons. Usability, because a pointer allows the user + // to manipulate the contained value externally. Performance, because returning a smart pointer + // means having to store the value as a smart pointer too - this adds yet another level of + // indirection to the value, as well as some reference counting overhead. These Get() and Set() + // methods are VERY frequently called, so doing as little as possible with the data here is best. + + return &_signals[signalIndex]; } inline bool SignalBus::HasValue( int signalIndex ) const { - if ( (size_t)signalIndex < _signals.size() ) - { - return _signals[signalIndex].has_value(); - } - else - { - return false; - } + return _signals[signalIndex].has_value(); } template @@ -146,40 +130,24 @@ inline ValueType* SignalBus::GetValue( int signalIndex ) const // See: GetSignal(). - if ( (size_t)signalIndex < _signals.size() ) - { - return _signals[signalIndex].as(); - } - else - { - return nullptr; - } + return _signals[signalIndex].as(); } template inline void SignalBus::SetValue( int signalIndex, const ValueType& newValue ) { - if ( (size_t)signalIndex < _signals.size() ) - { - _signals[signalIndex].emplace( newValue ); - } + _signals[signalIndex].emplace( newValue ); } template inline void SignalBus::MoveValue( int signalIndex, ValueType&& newValue ) { - if ( (size_t)signalIndex < _signals.size() ) - { - _signals[signalIndex].emplace( std::forward( newValue ) ); - } + _signals[signalIndex].emplace( std::forward( newValue ) ); } inline void SignalBus::SetSignal( int toSignalIndex, const fast_any::any& fromSignal ) { - if ( (size_t)toSignalIndex < _signals.size() ) - { - _signals[toSignalIndex] = fromSignal; - } + _signals[toSignalIndex] = fromSignal; } inline void SignalBus::MoveSignal( int toSignalIndex, fast_any::any& fromSignal ) @@ -194,10 +162,7 @@ inline void SignalBus::MoveSignal( int toSignalIndex, fast_any::any& fromSignal // signals such that, between these two points, just two value holders need to be constructed, // and shared back and forth from then on. - if ( (size_t)toSignalIndex < _signals.size() ) - { - _signals[toSignalIndex].swap( fromSignal ); - } + _signals[toSignalIndex].swap( fromSignal ); } inline void SignalBus::ClearAllValues() @@ -210,14 +175,7 @@ inline void SignalBus::ClearAllValues() inline fast_any::type_info SignalBus::GetType( int signalIndex ) const { - if ( (size_t)signalIndex < _signals.size() ) - { - return _signals[signalIndex].type(); - } - else - { - return fast_any::type_id; - } + return _signals[signalIndex].type(); } } // namespace DSPatch