From 4b2bce7b83d11ea1c26f2e3916c072aa39db5ef0 Mon Sep 17 00:00:00 2001 From: Fabian Homborg Date: Mon, 17 May 2021 17:58:49 +0200 Subject: [PATCH] screen: Remove useless .c_str() and wcslen calls This passed the wchar_t* to outputter::writestr(), which then had to do a wcslen on it, when it already has a perfectly cromulent wcstring overload. Just use that one. --- src/screen.cpp | 8 +++++--- 1 file changed, 5 insertions(+), 3 deletions(-) diff --git a/src/screen.cpp b/src/screen.cpp index 1db56ecd4..3d25d25d2 100644 --- a/src/screen.cpp +++ b/src/screen.cpp @@ -627,6 +627,7 @@ static void s_write_mbs(screen_t *screen, const char *s) { writembs(screen->outp /// Convert a wide string to a multibyte string and append it to the buffer. static void s_write_str(screen_t *screen, const wchar_t *s) { screen->outp().writestr(s); } +static void s_write_str(screen_t *screen, const wcstring &s) { screen->outp().writestr(s); } /// Returns the length of the "shared prefix" of the two lines, which is the run of matching text /// and colors. If the prefix ends on a combining character, do not include the previous character @@ -742,12 +743,13 @@ static void s_update(screen_t *scr, const wcstring &left_prompt, const wcstring if (clr_eol) { s_write_mbs(scr, clr_eol); } - s_write_str(scr, left_prompt.substr(start, line_break - start).c_str()); + s_write_str(scr, left_prompt.substr(start, line_break - start)); start = line_break; } - s_write_str(scr, left_prompt.c_str() + start); + s_write_str(scr, left_prompt.substr(start)); scr->actual_left_prompt = left_prompt; scr->actual.cursor.x = static_cast(left_prompt_width); + set_color(highlight_spec_t{}); } // Output all lines. @@ -882,7 +884,7 @@ static void s_update(screen_t *scr, const wcstring &left_prompt, const wcstring s_move(scr, 0, 0); s_move(scr, static_cast(screen_width - right_prompt_width), static_cast(i)); set_color(highlight_spec_t{}); - s_write_str(scr, right_prompt.c_str()); + s_write_str(scr, right_prompt); scr->actual.cursor.x += right_prompt_width; // We output in the last column. Some terms (Linux) push the cursor further right, past