Changeset View
Changeset View
Standalone View
Standalone View
source/ps/CConsole.cpp
Show All 35 Lines | |||||
#include "ps/Globals.h" | #include "ps/Globals.h" | ||||
#include "ps/Hotkey.h" | #include "ps/Hotkey.h" | ||||
#include "ps/Profile.h" | #include "ps/Profile.h" | ||||
#include "ps/Pyrogenesis.h" | #include "ps/Pyrogenesis.h" | ||||
#include "ps/VideoMode.h" | #include "ps/VideoMode.h" | ||||
#include "scriptinterface/ScriptInterface.h" | #include "scriptinterface/ScriptInterface.h" | ||||
#include "scriptinterface/JSON.h" | #include "scriptinterface/JSON.h" | ||||
#include <string_view> | |||||
#include <vector> | #include <vector> | ||||
#include <wctype.h> | #include <wctype.h> | ||||
namespace | namespace | ||||
{ | { | ||||
// For text being typed into the console. | // For text being typed into the console. | ||||
constexpr int CONSOLE_BUFFER_SIZE = 1024; | constexpr int CONSOLE_BUFFER_SIZE = 1024; | ||||
▲ Show 20 Lines • Show All 491 Lines • ▼ Show 20 Lines | oldNewline = 0; | ||||
std::lock_guard<std::mutex> lock(m_Mutex); // needed for safe access to m_deqMsgHistory | std::lock_guard<std::mutex> lock(m_Mutex); // needed for safe access to m_deqMsgHistory | ||||
while ( (distance = wrapAround.find(newline, oldNewline)) != wrapAround.npos) | while ( (distance = wrapAround.find(newline, oldNewline)) != wrapAround.npos) | ||||
{ | { | ||||
distance -= oldNewline; | distance -= oldNewline; | ||||
m_MsgHistory.push_front(wrapAround.substr(oldNewline, distance)); | m_MsgHistory.push_front(wrapAround.substr(oldNewline, distance)); | ||||
oldNewline += distance+1; | oldNewline += distance+1; | ||||
} | } | ||||
m_MsgHistory.push_front(wrapAround.substr(oldNewline)); | wrapAround.erase(0, oldNewline); | ||||
m_MsgHistory.push_front(std::move(wrapAround)); | |||||
vladislavbelov: Might be `emplace_front`. | |||||
Done Inline Actionsemplace is not needed. The string will be moved either way. phosit: emplace is not needed. The string will be moved either way. | |||||
Done Inline Actionsemplace is just preferable, but I don't insist. BTW std::move isn't useful here, because substr is const. vladislavbelov: `emplace` is just preferable, but I don't insist.
BTW `std::move` isn't useful here, because… | |||||
Done Inline ActionsI can use erase instead of substr. phosit: I can use erase instead of substr. | |||||
} | } | ||||
} | } | ||||
const wchar_t* CConsole::GetBuffer() | const wchar_t* CConsole::GetBuffer() | ||||
{ | { | ||||
m_Buffer[m_BufferLength] = 0; | m_Buffer[m_BufferLength] = 0; | ||||
return m_Buffer.get(); | return m_Buffer.get(); | ||||
} | } | ||||
▲ Show 20 Lines • Show All 50 Lines • ▼ Show 20 Lines | void CConsole::LoadHistory() | ||||
size_t pos = 0; | size_t pos = 0; | ||||
while (pos != CStrW::npos) | while (pos != CStrW::npos) | ||||
{ | { | ||||
pos = str.find('\n'); | pos = str.find('\n'); | ||||
if (pos != CStrW::npos) | if (pos != CStrW::npos) | ||||
{ | { | ||||
if (pos > 0) | if (pos > 0) | ||||
m_BufHistory.push_front(str.Left(str[pos-1] == '\r' ? pos - 1 : pos)); | m_BufHistory.push_front(str.Left(str[pos-1] == '\r' ? pos - 1 : pos)); | ||||
str = str.substr(pos + 1); | str.erase(0, pos + 1); | ||||
Done Inline ActionsWhy iterators here? In other places size_t indices. vladislavbelov: Why iterators here? In other places `size_t` indices. | |||||
} | } | ||||
else if (str.length() > 0) | else if (str.length() > 0) | ||||
m_BufHistory.push_front(str); | m_BufHistory.push_front(str); | ||||
} | } | ||||
} | } | ||||
void CConsole::SaveHistory() | void CConsole::SaveHistory() | ||||
{ | { | ||||
▲ Show 20 Lines • Show All 115 Lines • Show Last 20 Lines |
Wildfire Games · Phabricator
Might be emplace_front.