Rework ensure_all_buffers_are_saved to remove an unneeded Vector

This commit is contained in:
Maxime Coste 2016-11-23 23:31:17 +00:00
parent 1ccccbce04
commit b884b499dd

View File

@ -365,25 +365,24 @@ const CommandDesc write_all_cmd = {
static void ensure_all_buffers_are_saved()
{
Vector<String> names;
for (auto& buffer : BufferManager::instance())
{
if ((buffer->flags() & Buffer::Flags::File) and buffer->is_modified())
names.push_back(buffer->name());
}
if (not names.empty())
{
auto is_modified = [](const std::unique_ptr<Buffer>& buf) {
return (buf->flags() & Buffer::Flags::File) and buf->is_modified();
};
auto it = find_if(BufferManager::instance(), is_modified);
const auto end = BufferManager::instance().end();
if (it == end)
return;
String message = "modified buffers remaining: [";
for (auto it = names.begin(); it != names.end(); ++it)
while (it != end)
{
if (it != names.begin())
message += ", ";
message += *it;
message += (*it)->name();
it = std::find_if(it+1, end, is_modified);
message += (it != end) ? ", " : "]";
}
message += "]";
throw runtime_error(message);
}
}
const CommandDesc kill_cmd = {
"kill",