textfile.cpp: small performance improvements

- Pass std::string by reference
- Don't construct path using format()
This commit is contained in:
Unnamed 2019-08-21 11:31:49 +00:00 committed by TotallyNotElite
parent 4eacb00b43
commit 87e9892a88
2 changed files with 5 additions and 5 deletions

View File

@ -14,8 +14,8 @@ class TextFile
{ {
public: public:
TextFile(); TextFile();
void Load(std::string filename); void Load(const std::string &filename);
bool TryLoad(std::string filename); bool TryLoad(const std::string &filename);
size_t LineCount() const; size_t LineCount() const;
const std::string &Line(size_t id) const; const std::string &Line(size_t id) const;

View File

@ -13,7 +13,7 @@ TextFile::TextFile() : lines{}
{ {
} }
bool TextFile::TryLoad(std::string name) bool TextFile::TryLoad(const std::string &name)
{ {
if (name.length() == 0) if (name.length() == 0)
return false; return false;
@ -33,9 +33,9 @@ bool TextFile::TryLoad(std::string name)
return true; return true;
} }
void TextFile::Load(std::string name) void TextFile::Load(const std::string &name)
{ {
std::string filename = format(DATA_PATH "/", name); std::string filename = DATA_PATH "/" + name;
std::ifstream file(filename, std::ios::in); std::ifstream file(filename, std::ios::in);
if (file.bad()) if (file.bad())
{ {