From 27c0ee92dec73e889f5335b9827bb800737a4368 Mon Sep 17 00:00:00 2001 From: Fabian Homborg Date: Sat, 20 Oct 2018 17:57:39 +0200 Subject: [PATCH] Remove a few useless .c_str() With .c_str(), these call the wchar_t* overloads, which frequently then go on to call wcslen. Just directly use the wcstring we already have. --- src/builtin_set.cpp | 2 +- src/builtin_status.cpp | 2 +- src/pager.cpp | 6 +++--- 3 files changed, 5 insertions(+), 5 deletions(-) diff --git a/src/builtin_set.cpp b/src/builtin_set.cpp index aea3801dc..ac76193fc 100644 --- a/src/builtin_set.cpp +++ b/src/builtin_set.cpp @@ -554,7 +554,7 @@ static void show_scope(const wchar_t *var_name, int scope, io_streams_t &streams } const wcstring value = vals[i]; const wcstring escaped_val = - escape_string(value.c_str(), ESCAPE_NO_QUOTED, STRING_STYLE_SCRIPT); + escape_string(value, ESCAPE_NO_QUOTED, STRING_STYLE_SCRIPT); streams.out.append_format(_(L"$%ls[%d]: length=%d value=|%ls|\n"), var_name, i + 1, value.size(), escaped_val.c_str()); } diff --git a/src/builtin_status.cpp b/src/builtin_status.cpp index c9dba63cc..b05e1ccfc 100644 --- a/src/builtin_status.cpp +++ b/src/builtin_status.cpp @@ -429,7 +429,7 @@ int builtin_status(parser_t &parser, io_streams_t &streams, wchar_t **argv) { } case STATUS_FISH_PATH: { CHECK_FOR_UNEXPECTED_STATUS_ARGS(opts.status_cmd) - streams.out.append(str2wcstring(get_executable_path("fish")).c_str()); + streams.out.append(str2wcstring(get_executable_path("fish"))); streams.out.push_back(L'\n'); break; } diff --git a/src/pager.cpp b/src/pager.cpp index 08ec14a9c..6883e22e6 100644 --- a/src/pager.cpp +++ b/src/pager.cpp @@ -319,7 +319,7 @@ static comp_info_list_t process_completions_into_infos(const completion_list_t & } void pager_t::measure_completion_infos(comp_info_list_t *infos, const wcstring &prefix) const { - size_t prefix_len = fish_wcswidth(prefix.c_str()); + size_t prefix_len = fish_wcswidth(prefix); for (size_t i = 0; i < infos->size(); i++) { comp_t *comp = &infos->at(i); const wcstring_list_t &comp_strings = comp->comp; @@ -329,12 +329,12 @@ void pager_t::measure_completion_infos(comp_info_list_t *infos, const wcstring & if (j >= 1) comp->comp_width += 2; // fish_wcswidth() can return -1 if it can't calculate the width. So be cautious. - int comp_width = fish_wcswidth(comp_strings.at(j).c_str()); + int comp_width = fish_wcswidth(comp_strings.at(j)); if (comp_width >= 0) comp->comp_width += prefix_len + comp_width; } // fish_wcswidth() can return -1 if it can't calculate the width. So be cautious. - int desc_width = fish_wcswidth(comp->desc.c_str()); + int desc_width = fish_wcswidth(comp->desc); comp->desc_width = desc_width > 0 ? desc_width : 0; } }