C++'s strings have a quicker length operation. There's no need to
convert those strings to null-terminated C strings and run strlen()
on it.
---
src/devices/ahci.cpp | 2 +-
src/display.cpp | 7 +++----
src/lib.cpp | 2 +-
3 files changed, 5 insertions(+), 6 deletions(-)
diff --git a/src/devices/ahci.cpp b/src/devices/ahci.cpp
index 2fa2f52..31a42d3 100644
--- a/src/devices/ahci.cpp
+++ b/src/devices/ahci.cpp
@@ -150,7 +150,7 @@ ahci::ahci(char *_name, char *path): device()
diskname = model_name(path, _name);
- if (strlen(diskname.c_str()) == 0)
+ if (diskname.length() == 0)
snprintf(humanname, sizeof(humanname), _("SATA link: %s"), _name);
else
snprintf(humanname, sizeof(humanname), _("SATA disk: %s"),
diskname.c_str());
diff --git a/src/display.cpp b/src/display.cpp
index 10ee48a..8484683 100644
--- a/src/display.cpp
+++ b/src/display.cpp
@@ -98,7 +98,7 @@ void show_tab(unsigned int tab)
class tab_window *win;
unsigned int i;
int tab_pos = 17;
- const char *c;
+ string& s = bottom_lines[tab_names[tab]];
if (!display)
return;
@@ -123,9 +123,8 @@ void show_tab(unsigned int tab)
wattrset(bottom_line, A_REVERSE);
mvwprintw(bottom_line, 0,0, "%120s", "");
- c = bottom_lines[tab_names[tab]].c_str();
- if (c && strlen(c) > 0)
- mvwprintw(bottom_line, 0,0, c);
+ if (s.length() > 0)
+ mvwprintw(bottom_line, 0,0, s.c_str());
else
mvwprintw(bottom_line, 0, 0,
"<ESC> %s | <TAB> / <Shift + TAB> %s | ",
_("Exit"),
diff --git a/src/lib.cpp b/src/lib.cpp
index 5e48f37..b80ad36 100644
--- a/src/lib.cpp
+++ b/src/lib.cpp
@@ -424,7 +424,7 @@ char *pretty_print(const char *str, char *buf, int len)
p = pretty_prints[str].c_str();
- if (strlen(p) == 0)
+ if (pretty_prints[str].length() == 0)
p = str;
snprintf(buf, len, "%s", p);
--
2.16.1.windows.4
Show replies by date
Apologies folks,
I am not very good at using Thunderbird for sending patches, so this one
is back to an attachment. This patch is the only change different from
Bai's submission; it fixes a missing "free" in the normal case of
measure_string.
--
Regards,
Mingye Wang