From 0df088be200f1206db63772adeaeb42ffd204dda Mon Sep 17 00:00:00 2001 From: Maxime Coste Date: Sun, 6 Apr 2014 10:59:51 +0100 Subject: [PATCH] Code cleanup in list_files --- src/file.cc | 14 +++++--------- 1 file changed, 5 insertions(+), 9 deletions(-) diff --git a/src/file.cc b/src/file.cc index 653b2083..68c24bdd 100644 --- a/src/file.cc +++ b/src/file.cc @@ -275,15 +275,12 @@ std::vector list_files(const String& prefix, { kak_assert(dirname.empty() or dirname.back() == '/'); DIR* dir = opendir(dirname.empty() ? "./" : dirname.c_str()); - auto closeDir = on_scope_end([=]{ - if (dir != NULL) - closedir(dir); - }); + if (not dir) + return {}; + + auto closeDir = on_scope_end([=]{ closedir(dir); }); std::vector result; - if (not dir) - return result; - std::vector subseq_result; while (dirent* entry = readdir(dir)) { @@ -309,8 +306,7 @@ std::vector list_files(const String& prefix, } } } - auto& real_result = result.empty() ? subseq_result : result; - return real_result; + return result.empty() ? subseq_result : result; } std::vector complete_filename(const String& prefix,