Skip to content

Commit

Permalink
Optimization: add channels to Model by moving instead of copying them
Browse files Browse the repository at this point in the history
  • Loading branch information
gvnnz committed May 19, 2024
1 parent 4f03b9c commit 145845c
Show file tree
Hide file tree
Showing 4 changed files with 9 additions and 9 deletions.
10 changes: 5 additions & 5 deletions src/core/channels/channelManager.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -85,9 +85,9 @@ void ChannelManager::reset(Frame framesInBuffer)
channelFactory::Data previewData = channelFactory::create(
Mixer::PREVIEW_CHANNEL_ID, ChannelType::PREVIEW, framesInBuffer, rsmpQuality, overdubProtection);

m_model.get().channels.add(masterOutData.channel);
m_model.get().channels.add(masterInData.channel);
m_model.get().channels.add(previewData.channel);
m_model.get().channels.add(std::move(masterOutData.channel));
m_model.get().channels.add(std::move(masterInData.channel));
m_model.get().channels.add(std::move(previewData.channel));

m_model.addChannelShared(std::move(masterOutData.shared));
m_model.addChannelShared(std::move(masterInData.shared));
Expand All @@ -113,7 +113,7 @@ Channel& ChannelManager::addChannel(ChannelType type, int bufferSize)

setupChannelCallbacks(data.channel, *data.shared);

m_model.get().channels.add(data.channel);
m_model.get().channels.add(std::move(data.channel));
m_model.addChannelShared(std::move(data.shared));
m_model.swap(model::SwapType::HARD);

Expand Down Expand Up @@ -181,7 +181,7 @@ Channel& ChannelManager::cloneChannel(ID channelId, int bufferSize, const std::v

/* Then push the new channel in the channels vector. */

m_model.get().channels.add(newChannelData.channel);
m_model.get().channels.add(std::move(newChannelData.channel));
m_model.addChannelShared(std::move(newChannelData.shared));
m_model.swap(model::SwapType::HARD);

Expand Down
4 changes: 2 additions & 2 deletions src/core/model/channels.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -116,8 +116,8 @@ void Channels::remove(ID id)

/* -------------------------------------------------------------------------- */

void Channels::add(const Channel& ch)
void Channels::add(Channel&& ch)
{
m_channels.push_back(ch);
m_channels.push_back(std::move(ch));
}
} // namespace giada::m::model
2 changes: 1 addition & 1 deletion src/core/model/channels.h
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,7 @@ class Channels
Channel& getLast();
std::vector<Channel>& getAll();
std::vector<Channel*> getIf(std::function<bool(const Channel&)> f);
void add(const Channel&);
void add(Channel&&);
void remove(ID);

private:
Expand Down
2 changes: 1 addition & 1 deletion src/core/model/document.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@ void Document::load(const Patch& patch, Shared& shared, float sampleRateRatio)
assert(channelShared != nullptr);

Channel channel = channelFactory::deserializeChannel(pchannel, *channelShared, sampleRateRatio, wave, plugins);
channels.add(channel);
channels.add(std::move(channel));
}

actions.set(actionFactory::deserializeActions(patch.actions));
Expand Down

0 comments on commit 145845c

Please sign in to comment.