env: change various file filename() functions to return copies

I'm doing this so that the file cache implementation of these calls has the
flexibility to return newly constructed strings.

I don't expect it to be a big deal because:
1) These are generally only called in LOG() statements.
2) Return value optimization should reduce the number of copies.

Change-Id: Iae4a74963b5b12676b54831e2f6adddc4a6583c5
Reviewed-on: http://gerrit.cloudera.org:8080/5085
Tested-by: Kudu Jenkins
Reviewed-by: Dan Burkert <[email protected]>


Project: http://git-wip-us.apache.org/repos/asf/kudu/repo
Commit: http://git-wip-us.apache.org/repos/asf/kudu/commit/e836ac18
Tree: http://git-wip-us.apache.org/repos/asf/kudu/tree/e836ac18
Diff: http://git-wip-us.apache.org/repos/asf/kudu/diff/e836ac18

Branch: refs/heads/master
Commit: e836ac18df2ec2405a61aa7a9a90d61ee30716c5
Parents: 583aa22
Author: Adar Dembo <[email protected]>
Authored: Mon Nov 14 16:16:22 2016 -0800
Committer: Adar Dembo <[email protected]>
Committed: Wed Nov 16 02:00:20 2016 +0000

----------------------------------------------------------------------
 src/kudu/util/env-test.cc  | 2 +-
 src/kudu/util/env.h        | 8 ++++----
 src/kudu/util/env_posix.cc | 8 ++++----
 src/kudu/util/pb_util.cc   | 2 +-
 src/kudu/util/pb_util.h    | 2 +-
 5 files changed, 11 insertions(+), 11 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/kudu/blob/e836ac18/src/kudu/util/env-test.cc
----------------------------------------------------------------------
diff --git a/src/kudu/util/env-test.cc b/src/kudu/util/env-test.cc
index e132bca..897d5ac 100644
--- a/src/kudu/util/env-test.cc
+++ b/src/kudu/util/env-test.cc
@@ -393,7 +393,7 @@ class ShortReadRandomAccessFile : public RandomAccessFile {
     return wrapped_->Size(size);
   }
 
-  virtual const string& filename() const OVERRIDE { return 
wrapped_->filename(); }
+  virtual string filename() const OVERRIDE { return wrapped_->filename(); }
 
   virtual size_t memory_footprint() const OVERRIDE {
     return wrapped_->memory_footprint();

http://git-wip-us.apache.org/repos/asf/kudu/blob/e836ac18/src/kudu/util/env.h
----------------------------------------------------------------------
diff --git a/src/kudu/util/env.h b/src/kudu/util/env.h
index a59a766..ae5c943 100644
--- a/src/kudu/util/env.h
+++ b/src/kudu/util/env.h
@@ -301,7 +301,7 @@ class SequentialFile {
   virtual Status Skip(uint64_t n) = 0;
 
   // Returns the filename provided when the SequentialFile was constructed.
-  virtual const std::string& filename() const = 0;
+  virtual std::string filename() const = 0;
 };
 
 // A file abstraction for randomly reading the contents of a file.
@@ -326,7 +326,7 @@ class RandomAccessFile {
   virtual Status Size(uint64_t *size) const = 0;
 
   // Returns the filename provided when the RandomAccessFile was constructed.
-  virtual const std::string& filename() const = 0;
+  virtual std::string filename() const = 0;
 
   // Returns the approximate memory usage of this RandomAccessFile including
   // the object itself.
@@ -398,7 +398,7 @@ class WritableFile {
   virtual uint64_t Size() const = 0;
 
   // Returns the filename provided when the WritableFile was constructed.
-  virtual const std::string& filename() const = 0;
+  virtual std::string filename() const = 0;
 
  private:
   // No copying allowed
@@ -505,7 +505,7 @@ class RWFile {
   virtual Status Size(uint64_t* size) const = 0;
 
   // Returns the filename provided when the RWFile was constructed.
-  virtual const std::string& filename() const = 0;
+  virtual std::string filename() const = 0;
 
  private:
   DISALLOW_COPY_AND_ASSIGN(RWFile);

http://git-wip-us.apache.org/repos/asf/kudu/blob/e836ac18/src/kudu/util/env_posix.cc
----------------------------------------------------------------------
diff --git a/src/kudu/util/env_posix.cc b/src/kudu/util/env_posix.cc
index a1a8b89..6d2c383 100644
--- a/src/kudu/util/env_posix.cc
+++ b/src/kudu/util/env_posix.cc
@@ -263,7 +263,7 @@ class PosixSequentialFile: public SequentialFile {
     return Status::OK();
   }
 
-  virtual const string& filename() const OVERRIDE { return filename_; }
+  virtual string filename() const OVERRIDE { return filename_; }
 };
 
 // pread() based random-access
@@ -302,7 +302,7 @@ class PosixRandomAccessFile: public RandomAccessFile {
     return Status::OK();
   }
 
-  virtual const string& filename() const OVERRIDE { return filename_; }
+  virtual string filename() const OVERRIDE { return filename_; }
 
   virtual size_t memory_footprint() const OVERRIDE {
     return kudu_malloc_usable_size(this) + filename_.capacity();
@@ -438,7 +438,7 @@ class PosixWritableFile : public WritableFile {
     return filesize_;
   }
 
-  virtual const string& filename() const OVERRIDE { return filename_; }
+  virtual string filename() const OVERRIDE { return filename_; }
 
  private:
 
@@ -682,7 +682,7 @@ class PosixRWFile : public RWFile {
     return Status::OK();
   }
 
-  virtual const string& filename() const OVERRIDE {
+  virtual string filename() const OVERRIDE {
     return filename_;
   }
 

http://git-wip-us.apache.org/repos/asf/kudu/blob/e836ac18/src/kudu/util/pb_util.cc
----------------------------------------------------------------------
diff --git a/src/kudu/util/pb_util.cc b/src/kudu/util/pb_util.cc
index d19b16f..760ce19 100644
--- a/src/kudu/util/pb_util.cc
+++ b/src/kudu/util/pb_util.cc
@@ -660,7 +660,7 @@ Status WritablePBContainerFile::Close() {
   return Status::OK();
 }
 
-const string& WritablePBContainerFile::filename() const {
+string WritablePBContainerFile::filename() const {
   return writer_->filename();
 }
 

http://git-wip-us.apache.org/repos/asf/kudu/blob/e836ac18/src/kudu/util/pb_util.h
----------------------------------------------------------------------
diff --git a/src/kudu/util/pb_util.h b/src/kudu/util/pb_util.h
index f674a61..fa0158e 100644
--- a/src/kudu/util/pb_util.h
+++ b/src/kudu/util/pb_util.h
@@ -309,7 +309,7 @@ class WritablePBContainerFile {
   Status Close();
 
   // Returns the path to the container's underlying file handle.
-  const std::string& filename() const;
+  std::string filename() const;
 
  private:
   friend class TestPBUtil;

Reply via email to