From 268a9d8db3e3cd7b14ace8102b1be313ff6a8f2f Mon Sep 17 00:00:00 2001 From: Fabian Homborg Date: Tue, 19 Oct 2021 17:47:21 +0200 Subject: [PATCH] Prevent some copies --- src/builtin_path.cpp | 7 +++---- src/builtin_path.h | 1 - 2 files changed, 3 insertions(+), 5 deletions(-) diff --git a/src/builtin_path.cpp b/src/builtin_path.cpp index 70e39ad28..701788213 100644 --- a/src/builtin_path.cpp +++ b/src/builtin_path.cpp @@ -221,7 +221,7 @@ static int handle_flag_t(const wchar_t **argv, parser_t &parser, io_streams_t &s if (!opts->have_type) opts->type = 0; opts->have_type = true; wcstring_list_t types = split_string_tok(w.woptarg, L","); - for (auto t : types) { + for (const auto &t : types) { if (t == L"file") { opts->type |= TYPE_FILE; } else if (t == L"dir") { @@ -254,7 +254,7 @@ static int handle_flag_p(const wchar_t **argv, parser_t &parser, io_streams_t &s if (!opts->have_perm) opts->perm = 0; opts->have_perm = true; wcstring_list_t perms = split_string_tok(w.woptarg, L","); - for (auto p : perms) { + for (const auto &p : perms) { if (p == L"read") { opts->perm |= PERM_READ; } else if (p == L"write") { @@ -433,10 +433,9 @@ static int path_transform(parser_t &parser, io_streams_t &streams, int argc, con int n_transformed = 0; arg_iterator_t aiter(argv, optind, streams, opts.null_in); while (const wcstring *arg = aiter.nextstr()) { - wcstring transformed(*arg); // Empty paths make no sense, but e.g. wbasename returns true for them. if (arg->empty()) continue; - transformed = func(*arg); + wcstring transformed = func(*arg); if (transformed != *arg) { n_transformed++; // Return okay if path wasn't already in this form diff --git a/src/builtin_path.h b/src/builtin_path.h index 00fe84a6e..537234b83 100644 --- a/src/builtin_path.h +++ b/src/builtin_path.h @@ -1,4 +1,3 @@ -// Prototypes for functions for executing builtin_string functions. #ifndef FISH_BUILTIN_PATH_H #define FISH_BUILTIN_PATH_H