1
0
mirror of git://projects.qi-hardware.com/gmenu2x.git synced 2024-11-29 01:27:31 +02:00

Don't use string::compare if there are better alternatives

When comparing full strings, operator== will do nicely.
When comparing the first char, "s[0] == c" is more efficient if we know
the string cannot be empty.
This commit is contained in:
Maarten ter Huurne 2014-08-15 14:19:17 +02:00
parent 6e8491abee
commit 739a9463be
3 changed files with 4 additions and 4 deletions

View File

@ -185,7 +185,7 @@ void BrowseDialog::directoryUp()
p = path.rfind("/", p - 1);
}
if (p == string::npos || path.compare(0, 1, "/") != 0 || path.length() < 2) {
if (p == string::npos || path.length() < 2 || path[0] != '/') {
quit();
} else {
selected = 0;

View File

@ -545,7 +545,7 @@ void Menu::deleteSelectedLink()
!icon_used && section<links.end(); section++)
for (vector<Link*>::iterator link = section->begin();
!icon_used && link<section->end(); link++)
icon_used = !iconpath.compare((*link)->getIconPath());
icon_used = iconpath == (*link)->getIconPath();
if (!icon_used)
gmenu2x->sc.del(iconpath);
@ -694,7 +694,7 @@ void Menu::openPackage(std::string path, bool order)
pos = metadata.rfind('.');
metadata = metadata.substr(pos + 1);
if (!metadata.compare(PLATFORM) || !metadata.compare("all")) {
if (metadata == PLATFORM || metadata == "all") {
has_metadata = true;
break;
}

View File

@ -176,7 +176,7 @@ int Selector::exec(int startSelection) {
case InputManager::LEFT:
if (link->getSelectorBrowser()) {
string::size_type p = dir.rfind("/", dir.size()-2);
if (p==string::npos || dir.compare(0, 1, "/") != 0 || dir.length() < 2) {
if (p==string::npos || dir.length() < 2 || dir[0] != '/') {
close = true;
result = false;
} else {