IniFile: Provide an rvalue reference overload for SetLines
Allows moving in vectors instead of performing an unnecessary copy.
This commit is contained in:
parent
46d74a7760
commit
d8998b6392
|
@ -267,6 +267,11 @@ void IniFile::Section::SetLines(const std::vector<std::string>& lines)
|
|||
m_lines = lines;
|
||||
}
|
||||
|
||||
void IniFile::Section::SetLines(std::vector<std::string>&& lines)
|
||||
{
|
||||
m_lines = std::move(lines);
|
||||
}
|
||||
|
||||
bool IniFile::Section::GetLines(std::vector<std::string>* lines, const bool remove_comments) const
|
||||
{
|
||||
for (std::string line : m_lines)
|
||||
|
@ -352,6 +357,12 @@ void IniFile::SetLines(const std::string& sectionName, const std::vector<std::st
|
|||
section->SetLines(lines);
|
||||
}
|
||||
|
||||
void IniFile::SetLines(const std::string& section_name, std::vector<std::string>&& lines)
|
||||
{
|
||||
Section* section = GetOrCreateSection(section_name);
|
||||
section->SetLines(std::move(lines));
|
||||
}
|
||||
|
||||
bool IniFile::DeleteKey(const std::string& sectionName, const std::string& key)
|
||||
{
|
||||
Section* section = GetSection(sectionName);
|
||||
|
|
|
@ -67,6 +67,7 @@ public:
|
|||
bool Get(const std::string& key, std::vector<std::string>* values) const;
|
||||
|
||||
void SetLines(const std::vector<std::string>& lines);
|
||||
void SetLines(std::vector<std::string>&& lines);
|
||||
bool GetLines(std::vector<std::string>* lines, const bool remove_comments = true) const;
|
||||
|
||||
bool operator<(const Section& other) const { return name < other.name; }
|
||||
|
@ -124,6 +125,7 @@ public:
|
|||
bool GetKeys(const std::string& sectionName, std::vector<std::string>* keys) const;
|
||||
|
||||
void SetLines(const std::string& sectionName, const std::vector<std::string>& lines);
|
||||
void SetLines(const std::string& section_name, std::vector<std::string>&& lines);
|
||||
bool GetLines(const std::string& sectionName, std::vector<std::string>* lines,
|
||||
const bool remove_comments = true) const;
|
||||
|
||||
|
|
Loading…
Reference in New Issue