summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorWilliam McPherson <willmcpherson2@gmail.com>2019-12-10 18:02:43 +1100
committerAndreas Kling <awesomekling@gmail.com>2019-12-11 12:10:52 +0100
commitbb311b970f4d5c7b7e1c40d45e9064790bee6c2c (patch)
tree20e4d52665b94ea6f03b3db1d8afe2df23cf2966
parentc0696ad3aad8436d0855a28e06ceb211b0704187 (diff)
downloadserenity-bb311b970f4d5c7b7e1c40d45e9064790bee6c2c.zip
Shell: Improve readability of cache_path()
I prefer String::format over StringBuilder here. Also simplified a weird continue statement.
-rw-r--r--Shell/LineEditor.cpp14
-rw-r--r--Shell/LineEditor.h1
2 files changed, 4 insertions, 11 deletions
diff --git a/Shell/LineEditor.cpp b/Shell/LineEditor.cpp
index af4878bc4f..6f1267f04b 100644
--- a/Shell/LineEditor.cpp
+++ b/Shell/LineEditor.cpp
@@ -51,17 +51,11 @@ void LineEditor::cache_path()
CDirIterator programs(directory.characters(), CDirIterator::SkipDots);
while (programs.has_next()) {
auto program = programs.next_path();
-
- StringBuilder program_path;
- program_path.append(directory.characters());
- program_path.append('/');
- program_path.append(program.characters());
+ String program_path = String::format("%s/%s", directory.characters(), program.characters());
struct stat program_status;
- int stat_error = stat(program_path.to_string().characters(), &program_status);
- if (stat_error || !(program_status.st_mode & S_IXUSR))
- continue;
-
- m_path.append(program.characters());
+ int stat_error = stat(program_path.characters(), &program_status);
+ if (!stat_error && (program_status.st_mode & S_IXUSR))
+ m_path.append(program.characters());
}
}
diff --git a/Shell/LineEditor.h b/Shell/LineEditor.h
index 2f502d3541..6f4f4708fa 100644
--- a/Shell/LineEditor.h
+++ b/Shell/LineEditor.h
@@ -3,7 +3,6 @@
#include <AK/BinarySearch.h>
#include <AK/QuickSort.h>
#include <AK/String.h>
-#include <AK/StringBuilder.h>
#include <AK/Vector.h>
#include <LibCore/CDirIterator.h>
#include <sys/stat.h>