mirror of
https://gitea.wildfiregames.com/0ad/0ad.git
synced 2026-09-21 20:06:40 +00:00
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:
@@ -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);
|
||||
|
||||
@@ -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;
|
||||
}
|
||||
|
||||
|
||||
@@ -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.");
|
||||
|
||||
@@ -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)))
|
||||
|
||||
Reference in New Issue
Block a user