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