Merge pull request #19027 from GermanAizek/char-as-param-for-string-methods

Minor optimize methods std::string using param as char with simpler implementation
This commit is contained in:
Henrik Rydgård 2024-04-10 17:16:14 +02:00 committed by GitHub
commit fc58a97024
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
8 changed files with 13 additions and 13 deletions

View file

@ -328,20 +328,20 @@ bool Section::Get(const char* key, std::vector<std::string>& values) const
return false; return false;
} }
// ignore starting , if any // ignore starting , if any
size_t subStart = temp.find_first_not_of(","); size_t subStart = temp.find_first_not_of(',');
size_t subEnd; size_t subEnd;
// split by , // split by ,
while (subStart != std::string::npos) { while (subStart != std::string::npos) {
// Find next , // Find next ,
subEnd = temp.find_first_of(",", subStart); subEnd = temp.find_first_of(',', subStart);
if (subStart != subEnd) if (subStart != subEnd)
// take from first char until next , // take from first char until next ,
values.push_back(StripSpaces(temp.substr(subStart, subEnd - subStart))); values.push_back(StripSpaces(temp.substr(subStart, subEnd - subStart)));
// Find the next non , char // Find the next non , char
subStart = temp.find_first_not_of(",", subEnd); subStart = temp.find_first_not_of(',', subEnd);
} }
return true; return true;

View file

@ -153,7 +153,7 @@ void WordWrapper::AppendWord(int endIndex, int lastChar, bool addNewline) {
x_ = 0.0f; x_ = 0.0f;
} else { } else {
// We may have appended a newline - check. // We may have appended a newline - check.
size_t pos = out_.find_last_of("\n"); size_t pos = out_.find_last_of('\n');
if (pos != out_.npos) { if (pos != out_.npos) {
lastLineStart_ = pos + 1; lastLineStart_ = pos + 1;
} }

View file

@ -114,7 +114,7 @@ bool AndroidContentURI::CanNavigateUp() const {
// Only goes downwards in hierarchies. No ".." will ever be generated. // Only goes downwards in hierarchies. No ".." will ever be generated.
bool AndroidContentURI::ComputePathTo(const AndroidContentURI &other, std::string &path) const { bool AndroidContentURI::ComputePathTo(const AndroidContentURI &other, std::string &path) const {
size_t offset = FilePath().size() + 1; size_t offset = FilePath().size() + 1;
std::string otherFilePath = other.FilePath(); const auto &otherFilePath = other.FilePath();
if (offset >= otherFilePath.size()) { if (offset >= otherFilePath.size()) {
ERROR_LOG(SYSTEM, "Bad call to PathTo. '%s' -> '%s'", FilePath().c_str(), other.FilePath().c_str()); ERROR_LOG(SYSTEM, "Bad call to PathTo. '%s' -> '%s'", FilePath().c_str(), other.FilePath().c_str());
return false; return false;
@ -125,11 +125,11 @@ bool AndroidContentURI::ComputePathTo(const AndroidContentURI &other, std::strin
} }
std::string AndroidContentURI::GetFileExtension() const { std::string AndroidContentURI::GetFileExtension() const {
size_t pos = file.rfind("."); size_t pos = file.rfind('.');
if (pos == std::string::npos) { if (pos == std::string::npos) {
return ""; return "";
} }
size_t slash_pos = file.rfind("/"); size_t slash_pos = file.rfind('/');
if (slash_pos != std::string::npos && slash_pos > pos) { if (slash_pos != std::string::npos && slash_pos > pos) {
// Don't want to detect "df/file" from "/as.df/file" // Don't want to detect "df/file" from "/as.df/file"
return ""; return "";

View file

@ -686,7 +686,7 @@ bool CBreakPoints::EvaluateLogFormat(DebugInterface *cpu, const std::string &fmt
size_t pos = 0; size_t pos = 0;
while (pos < fmt.size()) { while (pos < fmt.size()) {
size_t next = fmt.find_first_of("{", pos); size_t next = fmt.find_first_of('{', pos);
if (next == fmt.npos) { if (next == fmt.npos) {
// End of the string. // End of the string.
result += fmt.substr(pos); result += fmt.substr(pos);
@ -697,7 +697,7 @@ bool CBreakPoints::EvaluateLogFormat(DebugInterface *cpu, const std::string &fmt
pos = next; pos = next;
} }
size_t end = fmt.find_first_of("}", next + 1); size_t end = fmt.find_first_of('}', next + 1);
if (end == fmt.npos) { if (end == fmt.npos) {
// Invalid: every expression needs a { and a }. // Invalid: every expression needs a { and a }.
return false; return false;

View file

@ -219,7 +219,7 @@ static int sceNpMatching2ContextStart(int ctxId)
text = entity.substr(ofs, ofs2 - ofs); text = entity.substr(ofs, ofs2 - ofs);
INFO_LOG(SCENET, "%s - Agent-FQDN#%d Status: %s", __FUNCTION__, i, text.c_str()); INFO_LOG(SCENET, "%s - Agent-FQDN#%d Status: %s", __FUNCTION__, i, text.c_str());
ofs = entity.find(">", ++ofs2); ofs = entity.find('>', ++ofs2);
if (ofs == std::string::npos) if (ofs == std::string::npos)
return hleLogError(SCENET, SCE_NP_COMMUNITY_SERVER_ERROR_NO_SUCH_TITLE, "agent host not found"); return hleLogError(SCENET, SCE_NP_COMMUNITY_SERVER_ERROR_NO_SUCH_TITLE, "agent host not found");

View file

@ -436,7 +436,7 @@ bool Load_PSP_ELF_PBP(FileLoader *fileLoader, std::string *error_string) {
std::string finalName = ms_path + file; std::string finalName = ms_path + file;
std::string homebrewName = PSP_CoreParameter().fileToStart.ToVisualString(); std::string homebrewName = PSP_CoreParameter().fileToStart.ToVisualString();
std::size_t lslash = homebrewName.find_last_of("/"); std::size_t lslash = homebrewName.find_last_of('/');
#if PPSSPP_PLATFORM(UWP) #if PPSSPP_PLATFORM(UWP)
if (lslash == homebrewName.npos) { if (lslash == homebrewName.npos) {
lslash = homebrewName.find_last_of("\\"); lslash = homebrewName.find_last_of("\\");

View file

@ -988,7 +988,7 @@ namespace SaveState
if (title.empty()) { if (title.empty()) {
// Homebrew title // Homebrew title
title = PSP_CoreParameter().fileToStart.ToVisualString(); title = PSP_CoreParameter().fileToStart.ToVisualString();
std::size_t lslash = title.find_last_of("/"); std::size_t lslash = title.find_last_of('/');
title = title.substr(lslash + 1); title = title.substr(lslash + 1);
} }
result = CChunkFileReader::Save(op.filename, title, PPSSPP_GIT_VERSION, state); result = CChunkFileReader::Save(op.filename, title, PPSSPP_GIT_VERSION, state);

View file

@ -581,7 +581,7 @@ bool GameManager::InstallMemstickGame(struct zip *z, const Path &zipfile, const
Path outFilename = dest / zippedName.substr(info.stripChars); Path outFilename = dest / zippedName.substr(info.stripChars);
bool isDir = zippedName.empty() || zippedName.back() == '/'; bool isDir = zippedName.empty() || zippedName.back() == '/';
if (!isDir && zippedName.find("/") != std::string::npos) { if (!isDir && zippedName.find('/') != std::string::npos) {
outFilename = dest / zippedName.substr(0, zippedName.rfind('/')); outFilename = dest / zippedName.substr(0, zippedName.rfind('/'));
} else if (!isDir) { } else if (!isDir) {
outFilename = dest; outFilename = dest;