Skip to content

Commit

Permalink
Remove ChannelContext::from_value
Browse files Browse the repository at this point in the history
  • Loading branch information
AntoinePrv committed Nov 15, 2023
1 parent c85659f commit ff79bf0
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 16 deletions.
2 changes: 0 additions & 2 deletions libmamba/include/mamba/core/channel.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -132,8 +132,6 @@ namespace mamba
multichannel_map m_custom_multichannels;

void init_custom_channels();

Channel from_value(const std::string& value);
};

} // namespace mamba
Expand Down
24 changes: 10 additions & 14 deletions libmamba/src/core/channel.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -372,9 +372,14 @@ namespace mamba
throw std::invalid_argument("Invalid ChannelSpec::Type");
}

Channel ChannelContext::from_value(const std::string& in_value)
const Channel& ChannelContext::make_channel(const std::string& value)
{
auto spec = specs::ChannelSpec::parse(in_value);
if (const auto it = m_channel_cache.find(value); it != m_channel_cache.end())
{
return it->second;
}

auto spec = specs::ChannelSpec::parse(value);
const auto platforms = [](const auto& plats) {
return Channel::ResolveParams::platform_list(plats.cbegin(), plats.cend());
}(m_context.platforms());
Expand All @@ -384,17 +389,8 @@ namespace mamba
/* .custom_channels */ m_custom_channels,
/* .auth_db */ m_context.authentication_info(),
};
return Channel::resolve(std::move(spec), params);
}

const Channel& ChannelContext::make_channel(const std::string& value)
{
if (const auto it = m_channel_cache.find(value); it != m_channel_cache.end())
{
return it->second;
}

auto [it, inserted] = m_channel_cache.emplace(value, from_value(value));
auto [it, inserted] = m_channel_cache.emplace(value, Channel::resolve(std::move(spec), params));
assert(inserted);
return it->second;
}
Expand Down Expand Up @@ -463,7 +459,7 @@ namespace mamba
{
for (const auto& [name, location] : m_context.custom_channels)
{
auto channel = from_value(location);
auto channel = make_channel(location);
channel.set_display_name(name);
m_custom_channels.emplace(name, std::move(channel));
}
Expand All @@ -474,7 +470,7 @@ namespace mamba
channels.reserve(location_list.size());
for (auto& location : location_list)
{
channels.push_back(from_value(location));
channels.push_back(make_channel(location));
}
m_custom_multichannels.emplace(multi_name, std::move(channels));
}
Expand Down

0 comments on commit ff79bf0

Please sign in to comment.