mirror of
https://github.com/RGBCube/serenity
synced 2025-07-25 15:27:35 +00:00
Shell: Use StringView instead of String const& where feasible
This commit is contained in:
parent
1a4aad9b7e
commit
5b64abe76e
4 changed files with 68 additions and 78 deletions
|
@ -1,5 +1,5 @@
|
|||
/*
|
||||
* Copyright (c) 2020-2021, the SerenityOS developers.
|
||||
* Copyright (c) 2020-2022, the SerenityOS developers.
|
||||
*
|
||||
* SPDX-License-Identifier: BSD-2-Clause
|
||||
*/
|
||||
|
@ -8,11 +8,13 @@
|
|||
|
||||
#include "Job.h"
|
||||
#include "Parser.h"
|
||||
#include <AK/Array.h>
|
||||
#include <AK/CircularQueue.h>
|
||||
#include <AK/HashMap.h>
|
||||
#include <AK/NonnullOwnPtrVector.h>
|
||||
#include <AK/String.h>
|
||||
#include <AK/StringBuilder.h>
|
||||
#include <AK/StringView.h>
|
||||
#include <AK/Types.h>
|
||||
#include <AK/Vector.h>
|
||||
#include <LibCore/Notifier.h>
|
||||
|
@ -99,25 +101,25 @@ public:
|
|||
void block_on_pipeline(RefPtr<AST::Pipeline>);
|
||||
String prompt() const;
|
||||
|
||||
static String expand_tilde(const String&);
|
||||
static String expand_tilde(StringView expression);
|
||||
static Vector<String> expand_globs(StringView path, StringView base);
|
||||
static Vector<String> expand_globs(Vector<StringView> path_segments, StringView base);
|
||||
Vector<AST::Command> expand_aliases(Vector<AST::Command>);
|
||||
String resolve_path(String) const;
|
||||
String resolve_alias(const String&) const;
|
||||
String resolve_alias(StringView) const;
|
||||
|
||||
static String find_in_path(StringView program_name);
|
||||
|
||||
static bool has_history_event(StringView);
|
||||
|
||||
RefPtr<AST::Value> get_argument(size_t) const;
|
||||
RefPtr<AST::Value> lookup_local_variable(const String&) const;
|
||||
String local_variable_or(const String&, const String&) const;
|
||||
RefPtr<AST::Value> lookup_local_variable(StringView) const;
|
||||
String local_variable_or(StringView, const String&) const;
|
||||
void set_local_variable(const String&, RefPtr<AST::Value>, bool only_in_current_frame = false);
|
||||
void unset_local_variable(const String&, bool only_in_current_frame = false);
|
||||
void unset_local_variable(StringView, bool only_in_current_frame = false);
|
||||
|
||||
void define_function(String name, Vector<String> argnames, RefPtr<AST::Node> body);
|
||||
bool has_function(const String&);
|
||||
bool has_function(StringView);
|
||||
bool invoke_function(const AST::Command&, int& retval);
|
||||
|
||||
String format(StringView, ssize_t& cursor) const;
|
||||
|
@ -154,10 +156,10 @@ public:
|
|||
[[nodiscard]] Frame push_frame(String name);
|
||||
void pop_frame();
|
||||
|
||||
static String escape_token_for_double_quotes(const String& token);
|
||||
static String escape_token_for_single_quotes(const String& token);
|
||||
static String escape_token(const String& token);
|
||||
static String unescape_token(const String& token);
|
||||
static String escape_token_for_double_quotes(StringView token);
|
||||
static String escape_token_for_single_quotes(StringView token);
|
||||
static String escape_token(StringView token);
|
||||
static String unescape_token(StringView token);
|
||||
enum class SpecialCharacterEscapeMode {
|
||||
Untouched,
|
||||
Escaped,
|
||||
|
@ -176,12 +178,12 @@ public:
|
|||
|
||||
void highlight(Line::Editor&) const;
|
||||
Vector<Line::CompletionSuggestion> complete();
|
||||
Vector<Line::CompletionSuggestion> complete_path(const String& base, const String&, size_t offset, ExecutableOnly executable_only);
|
||||
Vector<Line::CompletionSuggestion> complete_program_name(const String&, size_t offset);
|
||||
Vector<Line::CompletionSuggestion> complete_variable(const String&, size_t offset);
|
||||
Vector<Line::CompletionSuggestion> complete_user(const String&, size_t offset);
|
||||
Vector<Line::CompletionSuggestion> complete_option(const String&, const String&, size_t offset);
|
||||
Vector<Line::CompletionSuggestion> complete_immediate_function_name(const String&, size_t offset);
|
||||
Vector<Line::CompletionSuggestion> complete_path(StringView base, StringView, size_t offset, ExecutableOnly executable_only);
|
||||
Vector<Line::CompletionSuggestion> complete_program_name(StringView, size_t offset);
|
||||
Vector<Line::CompletionSuggestion> complete_variable(StringView, size_t offset);
|
||||
Vector<Line::CompletionSuggestion> complete_user(StringView, size_t offset);
|
||||
Vector<Line::CompletionSuggestion> complete_option(StringView, StringView, size_t offset);
|
||||
Vector<Line::CompletionSuggestion> complete_immediate_function_name(StringView, size_t offset);
|
||||
|
||||
void restore_ios();
|
||||
|
||||
|
@ -191,7 +193,7 @@ public:
|
|||
void kill_job(const Job*, int sig);
|
||||
|
||||
String get_history_path();
|
||||
void print_path(const String& path);
|
||||
void print_path(StringView path);
|
||||
|
||||
bool read_single_line();
|
||||
|
||||
|
@ -293,14 +295,14 @@ private:
|
|||
void save_to(JsonObject&);
|
||||
void bring_cursor_to_beginning_of_a_line() const;
|
||||
|
||||
Optional<int> resolve_job_spec(const String&);
|
||||
Optional<int> resolve_job_spec(StringView);
|
||||
void cache_path();
|
||||
void add_entry_to_cache(const String&);
|
||||
void remove_entry_from_cache(const String&);
|
||||
void remove_entry_from_cache(StringView);
|
||||
void stop_all_jobs();
|
||||
const Job* m_current_job { nullptr };
|
||||
LocalFrame* find_frame_containing_local_variable(const String& name);
|
||||
const LocalFrame* find_frame_containing_local_variable(const String& name) const
|
||||
LocalFrame* find_frame_containing_local_variable(StringView name);
|
||||
const LocalFrame* find_frame_containing_local_variable(StringView name) const
|
||||
{
|
||||
return const_cast<Shell*>(this)->find_frame_containing_local_variable(name);
|
||||
}
|
||||
|
@ -328,14 +330,14 @@ private:
|
|||
|
||||
#undef __ENUMERATE_SHELL_BUILTIN
|
||||
|
||||
constexpr static const char* builtin_names[] = {
|
||||
#define __ENUMERATE_SHELL_BUILTIN(builtin) #builtin,
|
||||
static constexpr Array builtin_names = {
|
||||
#define __ENUMERATE_SHELL_BUILTIN(builtin) #builtin##sv,
|
||||
|
||||
ENUMERATE_SHELL_BUILTINS()
|
||||
|
||||
#undef __ENUMERATE_SHELL_BUILTIN
|
||||
|
||||
":", // POSIX-y name for "noop".
|
||||
":"sv, // POSIX-y name for "noop".
|
||||
};
|
||||
|
||||
bool m_should_ignore_jobs_on_next_exit { false };
|
||||
|
@ -376,7 +378,7 @@ private:
|
|||
return c == '_' || (c <= 'Z' && c >= 'A') || (c <= 'z' && c >= 'a') || (c <= '9' && c >= '0');
|
||||
}
|
||||
|
||||
inline size_t find_offset_into_node(const String& unescaped_text, size_t escaped_offset)
|
||||
inline size_t find_offset_into_node(StringView unescaped_text, size_t escaped_offset)
|
||||
{
|
||||
size_t unescaped_offset = 0;
|
||||
size_t offset = 0;
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue