Skip to content

Commit

Permalink
Shell: Improve readability of cache_path()
Browse files Browse the repository at this point in the history
I prefer String::format over StringBuilder here.
Also simplified a weird continue statement.
  • Loading branch information
willmcpherson2 authored and awesomekling committed Dec 11, 2019
1 parent c0696ad commit bb311b9
Show file tree
Hide file tree
Showing 2 changed files with 4 additions and 11 deletions.
14 changes: 4 additions & 10 deletions Shell/LineEditor.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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());
}
}

Expand Down
1 change: 0 additions & 1 deletion Shell/LineEditor.h
Original file line number Diff line number Diff line change
Expand Up @@ -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>
Expand Down

0 comments on commit bb311b9

Please sign in to comment.