From 6f8885bc143460d77f300a981169e0487ff923c1 Mon Sep 17 00:00:00 2001 From: Adam Lesinski Date: Tue, 22 Sep 2015 18:42:19 -0700 Subject: [PATCH] Implement C++11 move semantics for android::FileMap FileMaps should be movable, thereby not requiring them to be only used with a unique_ptr as they currently are. Change-Id: I0fb8013bf398a2ced5420d85ba888c2a7fc5a496 --- include/utils/FileMap.h | 3 +++ libutils/FileMap.cpp | 37 +++++++++++++++++++++++++++++++++++++ 2 files changed, 40 insertions(+) diff --git a/include/utils/FileMap.h b/include/utils/FileMap.h index afd7bfd7b..7d372e1dc 100644 --- a/include/utils/FileMap.h +++ b/include/utils/FileMap.h @@ -52,6 +52,9 @@ class FileMap { public: FileMap(void); + FileMap(FileMap&& f); + FileMap& operator=(FileMap&& f); + /* * Create a new mapping on an open file. * diff --git a/libutils/FileMap.cpp b/libutils/FileMap.cpp index 91e45d873..4f4b8895a 100644 --- a/libutils/FileMap.cpp +++ b/libutils/FileMap.cpp @@ -53,6 +53,43 @@ FileMap::FileMap(void) { } +// Move Constructor. +FileMap::FileMap(FileMap&& other) + : mFileName(other.mFileName), mBasePtr(other.mBasePtr), mBaseLength(other.mBaseLength), + mDataOffset(other.mDataOffset), mDataPtr(other.mDataPtr), mDataLength(other.mDataLength) +#if defined(__MINGW32__) + , mFileHandle(other.mFileHandle), mFileMapping(other.mFileMapping) +#endif +{ + other.mFileName = NULL; + other.mBasePtr = NULL; + other.mDataPtr = NULL; +#if defined(__MINGW32__) + other.mFileHandle = 0; + other.mFileMapping = 0; +#endif +} + +// Move assign operator. +FileMap& FileMap::operator=(FileMap&& other) { + mFileName = other.mFileName; + mBasePtr = other.mBasePtr; + mBaseLength = other.mBaseLength; + mDataOffset = other.mDataOffset; + mDataPtr = other.mDataPtr; + mDataLength = other.mDataLength; + other.mFileName = NULL; + other.mBasePtr = NULL; + other.mDataPtr = NULL; +#if defined(__MINGW32__) + mFileHandle = other.mFileHandle; + mFileMapping = other.mFileMapping; + other.mFileHandle = 0; + other.mFileMapping = 0; +#endif + return *this; +} + // Destructor. FileMap::~FileMap(void) {