1
0
mirror of https://github.com/TerryCavanagh/VVVVVV.git synced 2024-06-23 13:08:30 +02:00

Use const std::string& where possible in function params

If it's at all possible to use `const std::string&` when passing
`std::string`s around, then we use it. This is to limit the amount of
memory usage as a result of the frequent use of `std::string`s, so the
game no longer unnecessarily copies strings when it doesn't need to.
This commit is contained in:
Misa 2021-09-06 15:41:49 -07:00
parent ff07f9c268
commit 33c5b8b7c0
10 changed files with 49 additions and 49 deletions

View File

@ -246,7 +246,7 @@ void customlevelclass::getDirectoryData(void)
}
}
bool customlevelclass::getLevelMetaData(std::string& _path, LevelMetaData& _data )
bool customlevelclass::getLevelMetaData(const std::string& _path, LevelMetaData& _data )
{
unsigned char *uMem;
FILESYSTEM_loadFileToMemory(_path.c_str(), &uMem, NULL, true);
@ -1264,7 +1264,7 @@ fail:
}
#ifndef NO_EDITOR
bool customlevelclass::save(std::string& _path)
bool customlevelclass::save(const std::string& _path)
{
tinyxml2::XMLDocument doc;

View File

@ -80,7 +80,7 @@ public:
void loadZips(void);
void getDirectoryData(void);
bool getLevelMetaData(std::string& filename, LevelMetaData& _data );
bool getLevelMetaData(const std::string& filename, LevelMetaData& _data );
void reset(void);
const int* loadlevel(int rxi, int ryi);
@ -117,7 +117,7 @@ public:
bool load(std::string& _path);
#ifndef NO_EDITOR
bool save(std::string& _path);
bool save(const std::string& _path);
#endif
void generatecustomminimap(void);

View File

@ -122,7 +122,7 @@ void editorclass::gethooks(void)
}
}
void editorclass::loadhookineditor(std::string t)
void editorclass::loadhookineditor(const std::string& t)
{
//Find hook t in the scriptclass, then load it into the editor
clearscriptbuffer();
@ -145,7 +145,7 @@ void editorclass::loadhookineditor(std::string t)
}
}
void editorclass::addhooktoscript(std::string t)
void editorclass::addhooktoscript(const std::string& t)
{
//Adds hook+the scriptbuffer to the end of the scriptclass
removehookfromscript(t);
@ -155,7 +155,7 @@ void editorclass::addhooktoscript(std::string t)
script.customscripts.push_back(script_);
}
void editorclass::removehookfromscript(std::string t)
void editorclass::removehookfromscript(const std::string& t)
{
/* Find hook t in the scriptclass, then removes it (and any other code with it)
* When this loop reaches the end, it wraps to SIZE_MAX; SIZE_MAX + 1 is 0 */
@ -169,7 +169,7 @@ void editorclass::removehookfromscript(std::string t)
}
}
void editorclass::removehook(std::string t)
void editorclass::removehook(const std::string& t)
{
//Check the hooklist for the hook t. If it's there, remove it from here and the script
size_t i;
@ -184,7 +184,7 @@ void editorclass::removehook(std::string t)
}
}
void editorclass::addhook(std::string t)
void editorclass::addhook(const std::string& t)
{
//Add an empty function to the list in both editor and script
removehook(t);
@ -192,7 +192,7 @@ void editorclass::addhook(std::string t)
addhooktoscript(t);
}
bool editorclass::checkhook(std::string t)
bool editorclass::checkhook(const std::string& t)
{
//returns true if hook t already is in the list
for(size_t i=0; i<hooklist.size(); i++)

View File

@ -149,14 +149,14 @@ public:
int pagey;
//Functions for interfacing with the script:
void addhook(std::string t);
void removehook(std::string t);
void addhooktoscript(std::string t);
void removehookfromscript(std::string t);
void loadhookineditor(std::string t);
void addhook(const std::string& t);
void removehook(const std::string& t);
void addhooktoscript(const std::string& t);
void removehookfromscript(const std::string& t);
void loadhookineditor(const std::string& t);
void clearscriptbuffer(void);
void gethooks(void);
bool checkhook(std::string t);
bool checkhook(const std::string& t);
std::vector<std::string> hooklist;
int hookmenupage, hookmenu;

View File

@ -5012,7 +5012,7 @@ void Game::readmaingamesave(const char* savename, tinyxml2::XMLDocument& doc)
}
void Game::customloadquick(std::string savfile)
void Game::customloadquick(const std::string& savfile)
{
tinyxml2::XMLDocument doc;
tinyxml2::XMLHandle hDoc(&doc);
@ -5541,7 +5541,7 @@ std::string Game::writemaingamesave(tinyxml2::XMLDocument& doc)
}
bool Game::customsavequick(std::string savfile)
bool Game::customsavequick(const std::string& savfile)
{
const std::string levelfile = savfile.substr(7);

View File

@ -121,7 +121,7 @@ public:
void resetgameclock(void);
bool customsavequick(std::string savfile);
bool customsavequick(const std::string& savfile);
bool savequick(void);
void gameclock(void);
@ -196,7 +196,7 @@ public:
void deathsequence(void);
void customloadquick(std::string savfile);
void customloadquick(const std::string& savfile);
void loadquick(void);
void customdeletequick(const std::string& file);

View File

@ -545,11 +545,11 @@ void Graphics::do_print(
}
}
void Graphics::Print( int _x, int _y, std::string _s, int r, int g, int b, bool cen /*= false*/ ) {
void Graphics::Print( int _x, int _y, const std::string& _s, int r, int g, int b, bool cen /*= false*/ ) {
return PrintAlpha(_x,_y,_s,r,g,b,255,cen);
}
void Graphics::PrintAlpha( int _x, int _y, std::string _s, int r, int g, int b, int a, bool cen /*= false*/ )
void Graphics::PrintAlpha( int _x, int _y, const std::string& _s, int r, int g, int b, int a, bool cen /*= false*/ )
{
if (cen)
_x = ((160 ) - ((len(_s)) / 2));
@ -671,7 +671,7 @@ void Graphics::PrintWrap(
}
void Graphics::bigprint( int _x, int _y, std::string _s, int r, int g, int b, bool cen, int sc )
void Graphics::bigprint( int _x, int _y, const std::string& _s, int r, int g, int b, bool cen, int sc )
{
if (cen)
{
@ -681,7 +681,7 @@ void Graphics::bigprint( int _x, int _y, std::string _s, int r, int g, int b, b
return do_print(_x, _y, _s, r, g, b, 255, sc);
}
void Graphics::bigbprint(int x, int y, std::string s, int r, int g, int b, bool cen, int sc)
void Graphics::bigbprint(int x, int y, const std::string& s, int r, int g, int b, bool cen, int sc)
{
if (!notextoutline)
{
@ -703,10 +703,10 @@ void Graphics::bigbprint(int x, int y, std::string s, int r, int g, int b, bool
bigprint(x, y, s, r, g, b, cen, sc);
}
int Graphics::len(std::string t)
int Graphics::len(const std::string& t)
{
int bfontpos = 0;
std::string::iterator iter = t.begin();
std::string::const_iterator iter = t.begin();
while (iter != t.end()) {
int cur = utf8::unchecked::next(iter);
bfontpos += bfontlen(cur);
@ -714,11 +714,11 @@ int Graphics::len(std::string t)
return bfontpos;
}
void Graphics::bprint( int x, int y, std::string t, int r, int g, int b, bool cen /*= false*/ ) {
void Graphics::bprint( int x, int y, const std::string& t, int r, int g, int b, bool cen /*= false*/ ) {
bprintalpha(x,y,t,r,g,b,255,cen);
}
void Graphics::bprintalpha( int x, int y, std::string t, int r, int g, int b, int a, bool cen /*= false*/ )
void Graphics::bprintalpha( int x, int y, const std::string& t, int r, int g, int b, int a, bool cen /*= false*/ )
{
if (!notextoutline)
{
@ -1370,7 +1370,7 @@ void Graphics::textboxtimer( int t )
textbox[m].timer=t;
}
void Graphics::addline( std::string t )
void Graphics::addline( const std::string& t )
{
if (!INBOUNDS_VEC(m, textbox))
{
@ -1394,7 +1394,7 @@ void Graphics::textboxadjust(void)
void Graphics::createtextboxreal(
std::string t,
const std::string& t,
int xp,
int yp,
int r,
@ -1420,7 +1420,7 @@ void Graphics::createtextboxreal(
}
void Graphics::createtextbox(
std::string t,
const std::string& t,
int xp,
int yp,
int r,
@ -1431,7 +1431,7 @@ void Graphics::createtextbox(
}
void Graphics::createtextboxflipme(
std::string t,
const std::string& t,
int xp,
int yp,
int r,
@ -3184,7 +3184,7 @@ void Graphics::renderfixedpost(void)
}
}
void Graphics::bigrprint(int x, int y, std::string& t, int r, int g, int b, bool cen, float sc)
void Graphics::bigrprint(int x, int y, const std::string& t, int r, int g, int b, bool cen, float sc)
{
x = x / (sc);
@ -3202,7 +3202,7 @@ void Graphics::bigrprint(int x, int y, std::string& t, int r, int g, int b, bool
return do_print(x, y, t, r, g, b, 255, sc);
}
void Graphics::bigbrprint(int x, int y, std::string& s, int r, int g, int b, bool cen, float sc)
void Graphics::bigbrprint(int x, int y, const std::string& s, int r, int g, int b, bool cen, float sc)
{
if (!notextoutline)
{

View File

@ -52,7 +52,7 @@ public:
void setwarprect(int a, int b, int c, int d);
void createtextboxreal(
std::string t,
const std::string& t,
int xp,
int yp,
int r,
@ -61,7 +61,7 @@ public:
bool flipme
);
void createtextbox(
std::string t,
const std::string& t,
int xp,
int yp,
int r,
@ -69,7 +69,7 @@ public:
int b
);
void createtextboxflipme(
std::string t,
const std::string& t,
int xp,
int yp,
int r,
@ -87,7 +87,7 @@ public:
void textboxadjust(void);
void addline(std::string t);
void addline(const std::string& t);
void textboxtimer(int t);
@ -133,9 +133,9 @@ public:
void do_print(int x, int y, const std::string& text, int r, int g, int b, int a, int scale);
void Print(int _x, int _y, std::string _s, int r, int g, int b, bool cen = false);
void Print(int _x, int _y, const std::string& _s, int r, int g, int b, bool cen = false);
void PrintAlpha(int _x, int _y, std::string _s, int r, int g, int b, int a, bool cen = false);
void PrintAlpha(int _x, int _y, const std::string& _s, int r, int g, int b, int a, bool cen = false);
bool next_wrap(size_t* start, size_t* len, const char* str, int maxwidth);
@ -143,13 +143,13 @@ public:
void PrintWrap(int x, int y, const char* str, int r, int g, int b, bool cen, int linespacing, int maxwidth);
void bprint(int x, int y, std::string t, int r, int g, int b, bool cen = false);
void bprint(int x, int y, const std::string& t, int r, int g, int b, bool cen = false);
void bprintalpha(int x, int y, std::string t, int r, int g, int b, int a, bool cen = false);
void bprintalpha(int x, int y, const std::string& t, int r, int g, int b, int a, bool cen = false);
int len(std::string t);
void bigprint( int _x, int _y, std::string _s, int r, int g, int b, bool cen = false, int sc = 2 );
void bigbprint(int x, int y, std::string s, int r, int g, int b, bool cen = false, int sc = 2);
int len(const std::string& t);
void bigprint( int _x, int _y, const std::string& _s, int r, int g, int b, bool cen = false, int sc = 2 );
void bigbprint(int x, int y, const std::string& s, int r, int g, int b, bool cen = false, int sc = 2);
void drawspritesetcol(int x, int y, int t, int c);
@ -173,8 +173,8 @@ public:
void drawtrophytext(void);
void bigrprint(int x, int y, std::string& t, int r, int g, int b, bool cen = false, float sc = 2);
void bigbrprint(int x, int y, std::string& t, int r, int g, int b, bool cen = false, float sc = 2);
void bigrprint(int x, int y, const std::string& t, int r, int g, int b, bool cen = false, float sc = 2);
void bigbrprint(int x, int y, const std::string& t, int r, int g, int b, bool cen = false, float sc = 2);
void drawtele(int x, int y, int t, Uint32 c);

View File

@ -107,7 +107,7 @@ void textboxclass::resize(void)
h = (line.size() + 2) * 8;
}
void textboxclass::addline(std::string t)
void textboxclass::addline(const std::string& t)
{
line.push_back(t);
resize();

View File

@ -25,7 +25,7 @@ public:
void resize(void);
void addline(std::string t);
void addline(const std::string& t);
public:
//Fundamentals
std::vector<std::string> line;