move more parameters from const String& to StringView

This commit is contained in:
Maxime Coste 2014-11-01 19:31:13 +00:00
parent 9a2822e329
commit c04dfc7bb7
4 changed files with 15 additions and 13 deletions

View File

@ -35,7 +35,7 @@ namespace Kakoune
namespace
{
Buffer* open_fifo(const String& name , const String& filename, bool scroll)
Buffer* open_fifo(StringView name, StringView filename, bool scroll)
{
int fd = open(parse_filename(filename).c_str(), O_RDONLY);
fcntl(fd, F_SETFD, FD_CLOEXEC);
@ -44,7 +44,7 @@ Buffer* open_fifo(const String& name , const String& filename, bool scroll)
BufferManager::instance().delete_buffer_if_exists(name);
return create_fifo_buffer(std::move(name), fd, scroll);
return create_fifo_buffer(name, fd, scroll);
}
template<typename T>
@ -1163,7 +1163,7 @@ const CommandDesc prompt_cmd = {
context.input_handler().prompt(
params[0], std::move(initstr), get_face("Prompt"), Completer{},
[=](const String& str, PromptEvent event, Context& context)
[=](StringView str, PromptEvent event, Context& context)
{
if (event != PromptEvent::Validate)
return;

View File

@ -474,7 +474,7 @@ void history_push(std::vector<String>& history, StringView entry)
class Prompt : public InputMode
{
public:
Prompt(InputHandler& input_handler, const String& prompt,
Prompt(InputHandler& input_handler, StringView prompt,
String initstr, Face face, Completer completer,
PromptCallback callback)
: InputMode(input_handler), m_prompt(prompt), m_prompt_face(face),
@ -1058,7 +1058,7 @@ void InputHandler::repeat_last_insert()
kak_assert(dynamic_cast<InputModes::Normal*>(m_mode.get()) != nullptr);
}
void InputHandler::prompt(const String& prompt, String initstr,
void InputHandler::prompt(StringView prompt, String initstr,
Face prompt_face, Completer completer,
PromptCallback callback)
{

View File

@ -27,7 +27,7 @@ enum class PromptEvent
Abort,
Validate
};
using PromptCallback = std::function<void (const String&, PromptEvent, Context&)>;
using PromptCallback = std::function<void (StringView, PromptEvent, Context&)>;
using KeyCallback = std::function<void (Key, Context&)>;
class InputMode;
@ -50,7 +50,7 @@ public:
// abort or validation with corresponding PromptEvent value
// returns to normal mode after validation if callback does
// not change the mode itself
void prompt(const String& prompt, String initstr,
void prompt(StringView prompt, String initstr,
Face prompt_face, Completer completer,
PromptCallback callback);
void set_prompt_face(Face prompt_face);

View File

@ -355,7 +355,7 @@ void command(Context& context, int)
context.input_handler().prompt(
":", "", get_face("Prompt"),
std::bind(&CommandManager::complete, &CommandManager::instance(), _1, _2, _3, _4),
[](const String& cmdline, PromptEvent event, Context& context) {
[](StringView cmdline, PromptEvent event, Context& context) {
if (context.has_ui())
{
context.ui().info_hide();
@ -379,7 +379,7 @@ void pipe(Context& context, int)
{
const char* prompt = mode == InsertMode::Replace ? "pipe:" : "pipe (ins):";
context.input_handler().prompt(prompt, "", get_face("Prompt"), shell_complete,
[](const String& cmdline, PromptEvent event, Context& context)
[](StringView cmdline, PromptEvent event, Context& context)
{
if (event != PromptEvent::Validate)
return;
@ -389,7 +389,7 @@ void pipe(Context& context, int)
real_cmd = context.main_sel_register_value("|");
else
{
RegisterManager::instance()['|'] = cmdline;
RegisterManager::instance()['|'] = String{cmdline};
real_cmd = cmdline;
}
@ -530,7 +530,7 @@ void regex_prompt(Context& context, const String prompt, T func)
{
SelectionList selections = context.selections();
context.input_handler().prompt(prompt, "", get_face("Prompt"), complete_nothing,
[=](const String& str, PromptEvent event, Context& context) mutable {
[=](StringView str, PromptEvent event, Context& context) mutable {
try
{
if (event != PromptEvent::Change and context.has_ui())
@ -546,7 +546,9 @@ void regex_prompt(Context& context, const String prompt, T func)
if (event == PromptEvent::Validate)
context.push_jump();
func(str.empty() ? Regex{} : Regex{str}, event, context);
Regex regex = str.empty() ? Regex{}
: Regex{str.begin(), str.end()};
func(std::move(regex), event, context);
}
catch (RegexError& err)
{
@ -748,7 +750,7 @@ void keep_pipe(Context& context, int)
{
context.input_handler().prompt(
"keep pipe:", "", get_face("Prompt"), shell_complete,
[](const String& cmdline, PromptEvent event, Context& context) {
[](StringView cmdline, PromptEvent event, Context& context) {
if (event != PromptEvent::Validate)
return;
const Buffer& buffer = context.buffer();