diff options
author | vng <viktor.govako@gmail.com> | 2015-12-04 20:30:43 +0300 |
---|---|---|
committer | Sergey Yershov <yershov@corp.mail.ru> | 2016-03-23 16:02:58 +0300 |
commit | bb1ad911558044ecab8fffc0ac86e320af7e6cae (patch) | |
tree | 44e2f2aed3e958831551ccc6fe596bbbaf02a759 /coding | |
parent | 936b9cd747c9931956f677b13caaaaf148026e8b (diff) |
Move semantics for FileWriter.
Diffstat (limited to 'coding')
-rw-r--r-- | coding/file_container.cpp | 4 | ||||
-rw-r--r-- | coding/file_writer.cpp | 6 | ||||
-rw-r--r-- | coding/file_writer.hpp | 7 |
3 files changed, 8 insertions, 9 deletions
diff --git a/coding/file_container.cpp b/coding/file_container.cpp index 4c16a05d56..fab8710331 100644 --- a/coding/file_container.cpp +++ b/coding/file_container.cpp @@ -398,7 +398,7 @@ FileWriter FilesContainerW::GetWriter(Tag const & tag) writer.WritePaddingByPos(kSectionAlignment); m_info.push_back(Info(tag, writer.Pos())); ASSERT(m_info.back().m_offset % kSectionAlignment == 0, ()); - return writer; + return move(writer); } else { @@ -407,7 +407,7 @@ FileWriter FilesContainerW::GetWriter(Tag const & tag) writer.WritePaddingByPos(kSectionAlignment); m_info.push_back(Info(tag, writer.Pos())); ASSERT(m_info.back().m_offset % kSectionAlignment == 0, ()); - return writer; + return move(writer); } } diff --git a/coding/file_writer.cpp b/coding/file_writer.cpp index 0a8fd728ff..eafe6f2b77 100644 --- a/coding/file_writer.cpp +++ b/coding/file_writer.cpp @@ -1,10 +1,10 @@ #include "coding/file_writer.hpp" #include "coding/internal/file_data.hpp" -FileWriter::FileWriter(FileWriter const & rhs) -: Writer(*this), m_bTruncOnClose(rhs.m_bTruncOnClose) + +FileWriter::FileWriter(FileWriter && rhs) +: m_pFileData(move(rhs.m_pFileData)), m_bTruncOnClose(rhs.m_bTruncOnClose) { - m_pFileData.swap(const_cast<FileWriter &>(rhs).m_pFileData); } FileWriter::FileWriter(string const & fileName, FileWriter::Op op, bool bTruncOnClose) diff --git a/coding/file_writer.hpp b/coding/file_writer.hpp index 7b18d8803b..a3b9eb23d4 100644 --- a/coding/file_writer.hpp +++ b/coding/file_writer.hpp @@ -8,6 +8,8 @@ namespace my { class FileData; } // FileWriter, not thread safe. class FileWriter : public Writer { + DISALLOW_COPY(FileWriter); + public: // Values actually match internal FileData::Op enum. enum Op @@ -23,9 +25,7 @@ public: OP_APPEND = 3 }; - /// Works like "move semantics". - /// Added for use in FilesContainerW interface. - FileWriter(FileWriter const & rhs); + FileWriter(FileWriter && rhs); explicit FileWriter(string const & fileName, Op operation = OP_WRITE_TRUNCATE, bool bTruncOnClose = false); @@ -36,7 +36,6 @@ public: void Write(void const * p, size_t size); void WritePaddingByEnd(size_t factor); - void WritePaddingByPos(size_t factor); uint64_t Size() const; |