Merge "Fix clang-tidy performance warnings in system/core."

This commit is contained in:
Chih-hung Hsieh 2017-08-04 21:05:51 +00:00 committed by Gerrit Code Review
commit 69ff5009c7
2 changed files with 11 additions and 11 deletions

View file

@ -105,7 +105,7 @@ TEST(liblog, __android_log_btwrite) {
} }
#if (defined(__ANDROID__) && defined(USING_LOGGER_DEFAULT)) #if (defined(__ANDROID__) && defined(USING_LOGGER_DEFAULT))
static std::string popenToString(std::string command) { static std::string popenToString(const std::string& command) {
std::string ret; std::string ret;
FILE* fp = popen(command.c_str(), "r"); FILE* fp = popen(command.c_str(), "r");
@ -129,17 +129,17 @@ static bool isPmsgActive() {
static bool isLogdwActive() { static bool isLogdwActive() {
std::string logdwSignature = std::string logdwSignature =
popenToString("grep /dev/socket/logdw /proc/net/unix"); popenToString("grep /dev/socket/logdw /proc/net/unix");
size_t beginning = logdwSignature.find(" "); size_t beginning = logdwSignature.find(' ');
if (beginning == std::string::npos) return true; if (beginning == std::string::npos) return true;
beginning = logdwSignature.find(" ", beginning + 1); beginning = logdwSignature.find(' ', beginning + 1);
if (beginning == std::string::npos) return true; if (beginning == std::string::npos) return true;
size_t end = logdwSignature.find(" ", beginning + 1); size_t end = logdwSignature.find(' ', beginning + 1);
if (end == std::string::npos) return true; if (end == std::string::npos) return true;
end = logdwSignature.find(" ", end + 1); end = logdwSignature.find(' ', end + 1);
if (end == std::string::npos) return true; if (end == std::string::npos) return true;
end = logdwSignature.find(" ", end + 1); end = logdwSignature.find(' ', end + 1);
if (end == std::string::npos) return true; if (end == std::string::npos) return true;
end = logdwSignature.find(" ", end + 1); end = logdwSignature.find(' ', end + 1);
if (end == std::string::npos) return true; if (end == std::string::npos) return true;
std::string allLogdwEndpoints = popenToString( std::string allLogdwEndpoints = popenToString(
"grep ' 00000002" + logdwSignature.substr(beginning, end - beginning) + "grep ' 00000002" + logdwSignature.substr(beginning, end - beginning) +
@ -159,7 +159,7 @@ static bool isLogdwActive() {
// NB: fgrep with multiple strings is broken in Android // NB: fgrep with multiple strings is broken in Android
for (beginning = 0; for (beginning = 0;
(end = allLogdwEndpoints.find("\n", beginning)) != std::string::npos; (end = allLogdwEndpoints.find('\n', beginning)) != std::string::npos;
beginning = end + 1) { beginning = end + 1) {
if (myPidFds.find(allLogdwEndpoints.substr(beginning, end - beginning)) != if (myPidFds.find(allLogdwEndpoints.substr(beginning, end - beginning)) !=
std::string::npos) std::string::npos)
@ -3170,7 +3170,7 @@ static bool isZero(const std::string& content, std::string::size_type pos,
return (offset != std::string::npos) && return (offset != std::string::npos) &&
((offset = content.find_first_not_of(" \t", offset + strlen(needle))) != ((offset = content.find_first_not_of(" \t", offset + strlen(needle))) !=
std::string::npos) && std::string::npos) &&
(content.find_first_not_of("0", offset) != offset); (content.find_first_not_of('0', offset) != offset);
} }
// must not be: '<needle:> 0 kB' // must not be: '<needle:> 0 kB'
@ -3239,7 +3239,7 @@ static void event_log_tags_test_smap(pid_t pid) {
filename = android::base::StringPrintf("/proc/%d/comm", pid); filename = android::base::StringPrintf("/proc/%d/comm", pid);
android::base::ReadFileToString(filename, &content); android::base::ReadFileToString(filename, &content);
content = android::base::StringPrintf( content = android::base::StringPrintf(
"%d:%s", pid, content.substr(0, content.find("\n")).c_str()); "%d:%s", pid, content.substr(0, content.find('\n')).c_str());
EXPECT_TRUE(IsOk(shared_ok, content)); EXPECT_TRUE(IsOk(shared_ok, content));
EXPECT_TRUE(IsOk(private_ok, content)); EXPECT_TRUE(IsOk(private_ok, content));

View file

@ -1256,7 +1256,7 @@ static int __logcat(android_logcat_context_internal* context) {
// example: "qemu_pipe,pipe:logcat" // example: "qemu_pipe,pipe:logcat"
// upon opening of /dev/qemu_pipe, the "pipe:logcat" // upon opening of /dev/qemu_pipe, the "pipe:logcat"
// string with trailing '\0' should be written to the fd // string with trailing '\0' should be written to the fd
size_t pos = devname.find(","); size_t pos = devname.find(',');
if (pos != std::string::npos) { if (pos != std::string::npos) {
pipePurpose = devname.substr(pos + 1); pipePurpose = devname.substr(pos + 1);
devname = devname.substr(0, pos); devname = devname.substr(0, pos);