You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@orc.apache.org by wi...@apache.org on 2023/01/11 02:41:23 UTC

[orc] branch main updated: ORC-1355: [C++] Use const references in `addUserMetadata|printAttributes|stripPrefix`

This is an automated email from the ASF dual-hosted git repository.

william pushed a commit to branch main
in repository https://gitbox.apache.org/repos/asf/orc.git


The following commit(s) were added to refs/heads/main by this push:
     new 549e4053a ORC-1355: [C++] Use const references in `addUserMetadata|printAttributes|stripPrefix`
549e4053a is described below

commit 549e4053a13209e1004e19a245129dd00695c1c2
Author: Junwang Zhao <zh...@gmail.com>
AuthorDate: Tue Jan 10 18:41:15 2023 -0800

    ORC-1355: [C++] Use const references in `addUserMetadata|printAttributes|stripPrefix`
    
    ### What changes were proposed in this pull request?
    
    change `void addUserMetadata(const std::string name, const std::string value) override;`
        to `void addUserMetadata(const std::string& name, const std::string& value) override;`
    to reduce copy construct.
    
    ### Why are the changes needed?
    
    performance improvement.
    
    ### How was this patch tested?
    
    This patch introduces no new features and all the exist test cases passed.
    
    Closes #1374 from zhjwpku/add_user_metadata_const_reference.
    
    Authored-by: Junwang Zhao <zh...@gmail.com>
    Signed-off-by: William Hyun <wi...@apache.org>
---
 c++/include/orc/Writer.hh  | 2 +-
 c++/src/Writer.cc          | 4 ++--
 tools/src/FileMetadata.cc  | 2 +-
 tools/test/TestFileScan.cc | 2 +-
 4 files changed, 5 insertions(+), 5 deletions(-)

diff --git a/c++/include/orc/Writer.hh b/c++/include/orc/Writer.hh
index 6b9e2b459..5eed39033 100644
--- a/c++/include/orc/Writer.hh
+++ b/c++/include/orc/Writer.hh
@@ -289,7 +289,7 @@ namespace orc {
     /**
      * Add user metadata to the writer.
      */
-    virtual void addUserMetadata(const std::string name, const std::string value) = 0;
+    virtual void addUserMetadata(const std::string& name, const std::string& value) = 0;
   };
 }  // namespace orc
 
diff --git a/c++/src/Writer.cc b/c++/src/Writer.cc
index 36c9efb36..bc174ae1b 100644
--- a/c++/src/Writer.cc
+++ b/c++/src/Writer.cc
@@ -306,7 +306,7 @@ namespace orc {
 
     void close() override;
 
-    void addUserMetadata(const std::string name, const std::string value) override;
+    void addUserMetadata(const std::string& name, const std::string& value) override;
 
    private:
     void init();
@@ -389,7 +389,7 @@ namespace orc {
     outStream->close();
   }
 
-  void WriterImpl::addUserMetadata(const std::string name, const std::string value) {
+  void WriterImpl::addUserMetadata(const std::string& name, const std::string& value) {
     proto::UserMetadataItem* userMetadataItem = fileFooter.add_metadata();
     userMetadataItem->set_name(name);
     userMetadataItem->set_value(value);
diff --git a/tools/src/FileMetadata.cc b/tools/src/FileMetadata.cc
index 7c697db38..94b4a678d 100644
--- a/tools/src/FileMetadata.cc
+++ b/tools/src/FileMetadata.cc
@@ -85,7 +85,7 @@ void printRawTail(std::ostream& out, const char* filename) {
   out << tail.DebugString();
 }
 
-void printAttributes(std::ostream& out, const orc::Type& type, const std::string name,
+void printAttributes(std::ostream& out, const orc::Type& type, const std::string& name,
                      bool* hasAnyAttributes) {
   const auto& attributeKeys = type.getAttributeKeys();
   bool typeHasAttrs = !attributeKeys.empty();
diff --git a/tools/test/TestFileScan.cc b/tools/test/TestFileScan.cc
index bfa2c5f1b..ecf6b4f12 100644
--- a/tools/test/TestFileScan.cc
+++ b/tools/test/TestFileScan.cc
@@ -72,7 +72,7 @@ TEST(TestFileScan, testNominal) {
  * stripPrefix("abcdef", "cd") -> "cdef"
  * stripPrefix("abcdef", "xx") -> "abcdef"
  */
-std::string stripPrefix(const std::string& input, const std::string goal) {
+std::string stripPrefix(const std::string& input, const std::string& goal) {
   size_t loc = input.find(goal);
   if (loc == std::string::npos) {
     return input;