Skip to content

Commit

Permalink
Simplify codes without unnecessary return variables
Browse files Browse the repository at this point in the history
  • Loading branch information
erwinpan1 committed Feb 13, 2024
1 parent f32ad21 commit a693243
Show file tree
Hide file tree
Showing 3 changed files with 11 additions and 22 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -58,35 +58,31 @@ CHIP_ERROR AudioOutputManager::HandleGetOutputList(AttributeValueEncoder & aEnco

bool AudioOutputManager::HandleRenameOutput(const uint8_t & index, const chip::CharSpan & name)
{
bool audioOutputRenamed = false;

for (OutputInfoType & output : mOutputs)
{
if (output.index == index)
{
audioOutputRenamed = true;
const size_t len = std::min(mNameLenMax, name.size());
memcpy(mOutputName[index], name.data(), len);
output.name = mOutputName[index];
return audioOutputRenamed;
return true;
}
}
return audioOutputRenamed;

return false;
}

bool AudioOutputManager::HandleSelectOutput(const uint8_t & index)
{
bool audioOutputSelected = false;
for (OutputInfoType & output : mOutputs)
{
if (output.index == index)
{
audioOutputSelected = true;
mCurrentOutput = index;
return audioOutputSelected;
return true;
}
}

return audioOutputSelected;
return false;
}
#endif // MATTER_DM_PLUGIN_AUDIO_OUTPUT_SERVER
6 changes: 2 additions & 4 deletions examples/chef/common/clusters/channel/ChannelManager.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -186,7 +186,6 @@ void ChannelManager::HandleChangeChannel(CommandResponseHelper<ChangeChannelResp

bool ChannelManager::HandleChangeChannelByNumber(const uint16_t & majorNumber, const uint16_t & minorNumber)
{
bool channelChanged = false;
uint16_t index = 0;
for (auto const & channel : mChannels)
{
Expand All @@ -196,15 +195,14 @@ bool ChannelManager::HandleChangeChannelByNumber(const uint16_t & majorNumber, c
// verify if channel changed by comparing values of current channel with the requested channel
if (channel.minorNumber != mCurrentChannel.minorNumber || channel.majorNumber != mCurrentChannel.majorNumber)
{
channelChanged = true;
mCurrentChannelIndex = index;
mCurrentChannel = channel;
return channelChanged;
return true;
}
}
index++;
}
return channelChanged;
return false;
}

bool ChannelManager::HandleSkipChannel(const int16_t & count)
Expand Down
13 changes: 4 additions & 9 deletions examples/chef/common/clusters/media-input/MediaInputManager.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -56,18 +56,16 @@ uint8_t MediaInputManager::HandleGetCurrentInput()

bool MediaInputManager::HandleSelectInput(const uint8_t index)
{
bool mediaInputSelected = false;
for (InputInfoType & input : mInputs)
{
if (input.index == index)
{
mediaInputSelected = true;
mCurrentInput = index;
return mediaInputSelected;
return true;
}
}

return mediaInputSelected;
return false;
}

bool MediaInputManager::HandleShowInputStatus()
Expand All @@ -92,20 +90,17 @@ bool MediaInputManager::HandleHideInputStatus()

bool MediaInputManager::HandleRenameInput(const uint8_t index, const chip::CharSpan & name)
{
bool mediaInputRenamed = false;

for (InputInfoType & input : mInputs)
{
if (input.index == index)
{
mediaInputRenamed = true;
const size_t len = std::min(mNameLenMax, name.size());
memcpy(mInputName[index], name.data(), len);
input.name = mInputName[index];
return mediaInputRenamed;
return true;
}
}

return mediaInputRenamed;
return false;
}
#endif // MATTER_DM_PLUGIN_MEDIA_INPUT_SERVER

0 comments on commit a693243

Please sign in to comment.