Don't call Move if there is no need to move
This commit is contained in:
parent
c691094aa1
commit
c3645e3f95
2 changed files with 12 additions and 9 deletions
|
@ -28,23 +28,26 @@ ScopedTemporaryFile::~ScopedTemporaryFile() {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
bool ScopedTemporaryFile::Init(const base::FilePath::StringType ext) {
|
bool ScopedTemporaryFile::Init(const base::FilePath::StringType& ext) {
|
||||||
if (!path_.empty())
|
if (!path_.empty())
|
||||||
return true;
|
return true;
|
||||||
|
|
||||||
base::ThreadRestrictions::ScopedAllowIO allow_io;
|
base::ThreadRestrictions::ScopedAllowIO allow_io;
|
||||||
|
|
||||||
base::FilePath temporaryPath_;
|
base::FilePath temp_path;
|
||||||
if (!base::CreateTemporaryFile(&temporaryPath_)) {
|
if (!base::CreateTemporaryFile(&temp_path))
|
||||||
return false;
|
return false;
|
||||||
}
|
|
||||||
|
|
||||||
path_ = temporaryPath_.AddExtension(ext);
|
if (ext.empty())
|
||||||
return base::Move(temporaryPath_, path_);
|
return true;
|
||||||
|
|
||||||
|
// Keep the original extension.
|
||||||
|
path_ = temp_path.AddExtension(ext);
|
||||||
|
return base::Move(temp_path, path_);
|
||||||
}
|
}
|
||||||
|
|
||||||
bool ScopedTemporaryFile::InitFromFile(base::File* src,
|
bool ScopedTemporaryFile::InitFromFile(base::File* src,
|
||||||
const base::FilePath::StringType ext,
|
const base::FilePath::StringType& ext,
|
||||||
uint64 offset, uint64 size) {
|
uint64 offset, uint64 size) {
|
||||||
if (!src->IsValid())
|
if (!src->IsValid())
|
||||||
return false;
|
return false;
|
||||||
|
|
|
@ -23,11 +23,11 @@ class ScopedTemporaryFile {
|
||||||
virtual ~ScopedTemporaryFile();
|
virtual ~ScopedTemporaryFile();
|
||||||
|
|
||||||
// Init an empty temporary file with a certain extension.
|
// Init an empty temporary file with a certain extension.
|
||||||
bool Init(const base::FilePath::StringType ext);
|
bool Init(const base::FilePath::StringType& ext);
|
||||||
|
|
||||||
// Init an temporary file and fill it with content of |path|.
|
// Init an temporary file and fill it with content of |path|.
|
||||||
bool InitFromFile(base::File* src,
|
bool InitFromFile(base::File* src,
|
||||||
const base::FilePath::StringType ext,
|
const base::FilePath::StringType& ext,
|
||||||
uint64 offset, uint64 size);
|
uint64 offset, uint64 size);
|
||||||
|
|
||||||
base::FilePath path() const { return path_; }
|
base::FilePath path() const { return path_; }
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue