]> khamidou — GitHub mirrors - electron.git/commitdiff
Don't call Move if there is no need to move
authorCheng Zhao <zcbenz@gmail.com>
Wed, 2 Dec 2015 03:04:47 +0000 (11:04 +0800)
committerCheng Zhao <zcbenz@gmail.com>
Wed, 2 Dec 2015 03:07:48 +0000 (11:07 +0800)
atom/common/asar/scoped_temporary_file.cc
atom/common/asar/scoped_temporary_file.h

index 2cc51991e185aa32abf117067257a5095025a08e..14f2ba8ef9ddf06e975a908554695b9d17e76c64 100644 (file)
@@ -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())
     return true;
 
   base::ThreadRestrictions::ScopedAllowIO allow_io;
 
-  base::FilePath temporaryPath_;
-  if (!base::CreateTemporaryFile(&temporaryPath_)) {
+  base::FilePath temp_path;
+  if (!base::CreateTemporaryFile(&temp_path))
     return false;
-  }
 
-  path_ = temporaryPath_.AddExtension(ext);
-  return base::Move(temporaryPath_, path_);
+  if (ext.empty())
+    return true;
+
+  // Keep the original extension.
+  path_ = temp_path.AddExtension(ext);
+  return base::Move(temp_path, path_);
 }
 
 bool ScopedTemporaryFile::InitFromFile(base::File* src,
-                                       const base::FilePath::StringType ext,
+                                       const base::FilePath::StringType& ext,
                                        uint64 offset, uint64 size) {
   if (!src->IsValid())
     return false;
index c0804a4e6e5f30a96c360f32d00049f5fd1b29cd..23660a239011677b669148ec17e9c9dd052a3005 100644 (file)
@@ -23,11 +23,11 @@ class ScopedTemporaryFile {
   virtual ~ScopedTemporaryFile();
 
   // 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|.
   bool InitFromFile(base::File* src,
-                    const base::FilePath::StringType ext,
+                    const base::FilePath::StringType& ext,
                     uint64 offset, uint64 size);
 
   base::FilePath path() const { return path_; }