Remove some unnecessary string copy related to substr.

Patch By: phosit
Differential Revision: https://code.wildfiregames.com/D4772
This was SVN commit r27271.
This commit is contained in:
vladislavbelov
2022-12-04 19:56:12 +00:00
parent b2f529c655
commit 2ef801f5d0
13 changed files with 73 additions and 40 deletions
+4 -2
View File
@@ -41,6 +41,7 @@
#include "scriptinterface/ScriptInterface.h"
#include "scriptinterface/JSON.h"
#include <string_view>
#include <vector>
#include <wctype.h>
@@ -548,7 +549,8 @@ void CConsole::InsertMessage(const std::string& message)
m_MsgHistory.push_front(wrapAround.substr(oldNewline, distance));
oldNewline += distance+1;
}
m_MsgHistory.push_front(wrapAround.substr(oldNewline));
wrapAround.erase(0, oldNewline);
m_MsgHistory.push_front(std::move(wrapAround));
}
}
@@ -615,7 +617,7 @@ void CConsole::LoadHistory()
{
if (pos > 0)
m_BufHistory.push_front(str.Left(str[pos-1] == '\r' ? pos - 1 : pos));
str = str.substr(pos + 1);
str.erase(0, pos + 1);
}
else if (str.length() > 0)
m_BufHistory.push_front(str);
+1 -1
View File
@@ -40,7 +40,7 @@ bool CTemplateLoader::LoadTemplateFile(CParamNode& node, std::string_view templa
// Handle infinite loops more gracefully than running out of stack space and crashing
if (depth > 100)
{
LOGERROR("Probable infinite inheritance loop in entity template '%s'", std::string(templateName));
LOGERROR("Probable infinite inheritance loop in entity template '%s'", templateName);
return false;
}
+3 -1
View File
@@ -28,6 +28,7 @@
#include "scriptinterface/ScriptInterface.h"
#include <libxml/parser.h>
#include <string_view>
#include <unordered_map>
const char* XMBStorage::HeaderMagicStr = "XMB0";
@@ -235,7 +236,8 @@ bool JSNodeData::Setup(XMBStorageWriter& xmb, JS::HandleValue value)
std::string_view name = prop;
if (!attrib && !prop.empty() && prop.back() == '@')
{
size_t idx = prop.substr(0, prop.size()-1).find_last_of('@');
const size_t idx = std::string_view{prop}.substr(0, prop.size() - 1)
.find_last_of('@');
if (idx == std::string::npos)
{
LOGERROR("Object key name cannot end with an '@' unless it is an index specifier.");
+2 -2
View File
@@ -1,4 +1,4 @@
/* Copyright (C) 2009 Wildfire Games.
/* Copyright (C) 2022 Wildfire Games.
* This file is part of 0 A.D.
*
* 0 A.D. is free software: you can redistribute it and/or modify
@@ -85,7 +85,7 @@ public:
std::string s = mainlog->str();
size_t start = s.find(header_end);
TS_ASSERT_DIFFERS(start, s.npos);
s = s.substr(start + header_end.length());
s.erase(0, start + header_end.length());
size_t n = 0, m;
while (s.npos != (m = s.find('\n', n)))