From d8998b63927c63b120efd7ba63dbe62e491305b0 Mon Sep 17 00:00:00 2001 From: Lioncash Date: Wed, 22 Mar 2017 18:49:11 -0400 Subject: [PATCH] IniFile: Provide an rvalue reference overload for SetLines Allows moving in vectors instead of performing an unnecessary copy. --- Source/Core/Common/IniFile.cpp | 11 +++++++++++ Source/Core/Common/IniFile.h | 2 ++ 2 files changed, 13 insertions(+) diff --git a/Source/Core/Common/IniFile.cpp b/Source/Core/Common/IniFile.cpp index cf2c89e0f3..065d7e9b3c 100644 --- a/Source/Core/Common/IniFile.cpp +++ b/Source/Core/Common/IniFile.cpp @@ -267,6 +267,11 @@ void IniFile::Section::SetLines(const std::vector& lines) m_lines = lines; } +void IniFile::Section::SetLines(std::vector&& lines) +{ + m_lines = std::move(lines); +} + bool IniFile::Section::GetLines(std::vector* 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::vectorSetLines(lines); } +void IniFile::SetLines(const std::string& section_name, std::vector&& 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); diff --git a/Source/Core/Common/IniFile.h b/Source/Core/Common/IniFile.h index 72f2317a91..faff71164f 100644 --- a/Source/Core/Common/IniFile.h +++ b/Source/Core/Common/IniFile.h @@ -67,6 +67,7 @@ public: bool Get(const std::string& key, std::vector* values) const; void SetLines(const std::vector& lines); + void SetLines(std::vector&& lines); bool GetLines(std::vector* 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* keys) const; void SetLines(const std::string& sectionName, const std::vector& lines); + void SetLines(const std::string& section_name, std::vector&& lines); bool GetLines(const std::string& sectionName, std::vector* lines, const bool remove_comments = true) const;