Small refactoring in client_manager.cc

This commit is contained in:
Maxime Coste 2015-03-14 11:27:01 +00:00
parent adcb72e987
commit 9657ef88b7

View File

@ -79,22 +79,19 @@ void ClientManager::remove_client(Client& client)
WindowAndSelections ClientManager::get_free_window(Buffer& buffer) WindowAndSelections ClientManager::get_free_window(Buffer& buffer)
{ {
for (auto it = m_free_windows.rbegin(), end = m_free_windows.rend(); auto it = find_if(reversed(m_free_windows),
it != end; ++it) [&](const WindowAndSelections& ws)
{ { return &ws.window->buffer() == &buffer; });
auto& w = it->window;
if (&w->buffer() == &buffer) if (it == m_free_windows.rend())
{ return { make_unique<Window>(buffer), { buffer, Selection{} } };
w->forget_timestamp();
it->window->forget_timestamp();
WindowAndSelections res = std::move(*it); WindowAndSelections res = std::move(*it);
m_free_windows.erase(it.base()-1); m_free_windows.erase(it.base()-1);
res.selections.update(); res.selections.update();
return res; return res;
} }
}
return WindowAndSelections{ std::unique_ptr<Window>{new Window{buffer}},
SelectionList{ buffer, Selection{} } };
}
void ClientManager::add_free_window(std::unique_ptr<Window>&& window, SelectionList selections) void ClientManager::add_free_window(std::unique_ptr<Window>&& window, SelectionList selections)
{ {
@ -136,9 +133,7 @@ void ClientManager::ensure_no_client_uses_buffer(Buffer& buffer)
bool ClientManager::validate_client_name(StringView name) const bool ClientManager::validate_client_name(StringView name) const
{ {
auto it = find_if(m_clients, [&](const std::unique_ptr<Client>& client) return const_cast<ClientManager*>(this)->get_client_ifp(name) == nullptr;
{ return client->context().name() == name; });
return it == m_clients.end();
} }
Client* ClientManager::get_client_ifp(StringView name) Client* ClientManager::get_client_ifp(StringView name)