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

alexey pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/kudu.git


The following commit(s) were added to refs/heads/master by this push:
     new 36120ffe0 [cfile] use std::move where appropriate
36120ffe0 is described below

commit 36120ffe02fd91e21247adc3eaf61591ada51b4a
Author: Alexey Serbin <[email protected]>
AuthorDate: Tue Nov 29 22:49:34 2022 -0800

    [cfile] use std::move where appropriate
    
    Change-Id: I9013d2660008a9d9655d4d94528c868e210ec0a8
    Reviewed-on: http://gerrit.cloudera.org:8080/20426
    Tested-by: Alexey Serbin <[email protected]>
    Reviewed-by: Mahesh Reddy <[email protected]>
    Reviewed-by: Abhishek Chennaka <[email protected]>
---
 src/kudu/cfile/binary_dict_block.cc |  8 +++---
 src/kudu/cfile/binary_dict_block.h  |  3 ---
 src/kudu/cfile/block_compression.cc | 15 ++++++-----
 src/kudu/cfile/block_compression.h  |  8 +++---
 src/kudu/cfile/bloomfile.cc         |  7 +++--
 src/kudu/cfile/cfile-test.cc        |  6 ++---
 src/kudu/cfile/cfile_writer.cc      | 53 ++++++++++++++++++++-----------------
 src/kudu/cfile/cfile_writer.h       | 22 +++++++--------
 src/kudu/cfile/index_btree.cc       |  8 +++---
 9 files changed, 62 insertions(+), 68 deletions(-)

diff --git a/src/kudu/cfile/binary_dict_block.cc 
b/src/kudu/cfile/binary_dict_block.cc
index 194915a02..53cbfb40d 100644
--- a/src/kudu/cfile/binary_dict_block.cc
+++ b/src/kudu/cfile/binary_dict_block.cc
@@ -155,9 +155,8 @@ Status BinaryDictBlockBuilder::AppendExtraInfo(CFileWriter* 
c_writer, CFileFoote
   vector<Slice> dict_v;
   dict_block_.Finish(0, &dict_v);
 
-
   BlockPointer ptr;
-  Status s = c_writer->AppendDictBlock(dict_v, &ptr, "Append dictionary 
block");
+  Status s = c_writer->AppendDictBlock(std::move(dict_v), &ptr, "Append 
dictionary block");
   if (!s.ok()) {
     LOG(WARNING) << "Unable to append block to file: " << s.ToString();
     return s;
@@ -176,10 +175,9 @@ Status BinaryDictBlockBuilder::GetFirstKey(void* key_void) 
const {
     Slice* slice = reinterpret_cast<Slice*>(key_void);
     *slice = Slice(first_key_);
     return Status::OK();
-  } else {
-    DCHECK_EQ(mode_, kPlainBinaryMode);
-    return data_builder_->GetFirstKey(key_void);
   }
+  DCHECK_EQ(mode_, kPlainBinaryMode);
+  return data_builder_->GetFirstKey(key_void);
 }
 
 Status BinaryDictBlockBuilder::GetLastKey(void* key_void) const {
diff --git a/src/kudu/cfile/binary_dict_block.h 
b/src/kudu/cfile/binary_dict_block.h
index fa07fc5e9..dd653ac5e 100644
--- a/src/kudu/cfile/binary_dict_block.h
+++ b/src/kudu/cfile/binary_dict_block.h
@@ -56,9 +56,6 @@
 #include "kudu/util/slice.h"
 #include "kudu/util/status.h"
 
-template <class X>
-struct GoodFastHash;
-
 namespace kudu {
 
 class ColumnDataView;
diff --git a/src/kudu/cfile/block_compression.cc 
b/src/kudu/cfile/block_compression.cc
index e61cf5f6d..e3f8a064c 100644
--- a/src/kudu/cfile/block_compression.cc
+++ b/src/kudu/cfile/block_compression.cc
@@ -18,9 +18,11 @@
 #include "kudu/cfile/block_compression.h"
 
 #include <cstring>
+#include <iterator>
+#include <utility>
 
-#include <glog/logging.h>
 #include <gflags/gflags.h>
+#include <glog/logging.h>
 
 #include "kudu/gutil/port.h"
 #include "kudu/gutil/strings/substitute.h"
@@ -58,7 +60,8 @@ CompressedBlockBuilder::CompressedBlockBuilder(const 
CompressionCodec* codec)
   : codec_(DCHECK_NOTNULL(codec)) {
 }
 
-Status CompressedBlockBuilder::Compress(const vector<Slice>& data_slices, 
vector<Slice>* result) {
+Status CompressedBlockBuilder::Compress(vector<Slice> data_slices,
+                                        vector<Slice>* result) {
   size_t data_size = 0;
   for (const Slice& data : data_slices) {
     data_size += data.size();
@@ -95,10 +98,8 @@ Status CompressedBlockBuilder::Compress(const vector<Slice>& 
data_slices, vector
     InlineEncodeFixed32(&buffer_[0], data_size);
     result->clear();
     result->reserve(data_slices.size() + 1);
-    result->push_back(Slice(buffer_.data(), kHeaderLength));
-    for (const Slice& orig_data : data_slices) {
-      result->push_back(orig_data);
-    }
+    result->emplace_back(buffer_.data(), kHeaderLength);
+    std::move(data_slices.begin(), data_slices.end(), 
std::back_inserter(*result));
     return Status::OK();
   }
 
@@ -163,7 +164,7 @@ Status CompressedBlockDecoder::Init() {
   }
 
   // Check if uncompressed size seems to be reasonable.
-  if (uncompressed_size_ > FLAGS_max_cfile_block_size) {
+  if (PREDICT_FALSE(uncompressed_size_ > FLAGS_max_cfile_block_size)) {
     return Status::Corruption(
       Substitute("uncompressed size $0 overflows the maximum length $1, 
buffer",
                  uncompressed_size_, FLAGS_max_cfile_block_size),
diff --git a/src/kudu/cfile/block_compression.h 
b/src/kudu/cfile/block_compression.h
index 76c05a07a..cd426c7c9 100644
--- a/src/kudu/cfile/block_compression.h
+++ b/src/kudu/cfile/block_compression.h
@@ -73,11 +73,11 @@ class CompressedBlockBuilder {
   // modified while the elements of 'result' are still being used.
   //
   // If an error was encountered, returns a non-OK status.
-  Status Compress(const std::vector<Slice>& data_slices,
+  Status Compress(std::vector<Slice> data_slices,
                   std::vector<Slice>* result);
 
   // See format information above.
-  static const size_t kHeaderLength = 4;
+  static constexpr size_t kHeaderLength = 4;
 
  private:
   DISALLOW_COPY_AND_ASSIGN(CompressedBlockBuilder);
@@ -117,8 +117,8 @@ class CompressedBlockDecoder {
  private:
   DISALLOW_COPY_AND_ASSIGN(CompressedBlockDecoder);
 
-  static const size_t kHeaderLengthV1 = 8;
-  static const size_t kHeaderLengthV2 = 4;
+  static constexpr size_t kHeaderLengthV1 = 8;
+  static constexpr size_t kHeaderLengthV2 = 4;
 
   size_t header_length() const {
     return cfile_version_ == 1 ? kHeaderLengthV1 : kHeaderLengthV2;
diff --git a/src/kudu/cfile/bloomfile.cc b/src/kudu/cfile/bloomfile.cc
index 3bcdd32b9..97f795e69 100644
--- a/src/kudu/cfile/bloomfile.cc
+++ b/src/kudu/cfile/bloomfile.cc
@@ -177,14 +177,13 @@ Status BloomFileWriter::FinishCurrentBloomBlock() {
   pb_util::AppendToString(hdr, &hdr_str);
 
   // The data is the concatenation of the header and the bloom itself.
-  vector<Slice> slices;
-  slices.emplace_back(hdr_str);
-  slices.push_back(bloom_builder_.slice());
+  vector<Slice> slices { Slice(hdr_str), bloom_builder_.slice() };
 
   // Append to the file.
   Slice start_key(first_key_);
   Slice last_key(last_key_);
-  RETURN_NOT_OK(writer_->AppendRawBlock(slices, 0, &start_key, last_key, 
"bloom block"));
+  RETURN_NOT_OK(writer_->AppendRawBlock(
+      std::move(slices), 0, &start_key, last_key, "bloom block"));
 
   bloom_builder_.Clear();
 
diff --git a/src/kudu/cfile/cfile-test.cc b/src/kudu/cfile/cfile-test.cc
index 761eed50e..c1fd92ca3 100644
--- a/src/kudu/cfile/cfile-test.cc
+++ b/src/kudu/cfile/cfile-test.cc
@@ -280,7 +280,7 @@ class TestCFile : public CFileTestBase {
       slices.emplace_back("Body");
       slices.emplace_back("Tail");
       slices.emplace_back(reinterpret_cast<uint8_t *>(&i), 4);
-      ASSERT_OK(w.AppendRawBlock(slices, i, nullptr, Slice(), "raw-data"));
+      ASSERT_OK(w.AppendRawBlock(std::move(slices), i, nullptr, Slice(), 
"raw-data"));
     }
     ASSERT_OK(w.Finish());
 
@@ -900,9 +900,7 @@ TEST_P(TestCFileBothCacheMemoryTypes, TestDataCorruption) {
   CFileWriter w(opts, GetTypeInfo(STRING), false, std::move(sink));
   w.AddMetadataPair("header_key", "header_value");
   ASSERT_OK(w.Start());
-  vector<Slice> slices;
-  slices.emplace_back("HelloWorld");
-  ASSERT_OK(w.AppendRawBlock(slices, 1, nullptr, Slice(), "raw-data"));
+  ASSERT_OK(w.AppendRawBlock({ "HelloWorld" }, 1, nullptr, Slice(), 
"raw-data"));
   ASSERT_OK(w.Finish());
 
   // Get the final size of the data
diff --git a/src/kudu/cfile/cfile_writer.cc b/src/kudu/cfile/cfile_writer.cc
index e0abefe6a..7a7b448de 100644
--- a/src/kudu/cfile/cfile_writer.cc
+++ b/src/kudu/cfile/cfile_writer.cc
@@ -166,8 +166,7 @@ Status CFileWriter::Start() {
   PutFixed32(&header_str, pb_size);
   pb_util::AppendToString(header, &header_str);
 
-  vector<Slice> header_slices;
-  header_slices.emplace_back(header_str);
+  vector<Slice> header_slices { header_str };
 
   // Append header checksum.
   uint8_t checksum_buf[kChecksumSize];
@@ -385,20 +384,24 @@ Status CFileWriter::FinishCurDataBlock() {
       kudu::HexDump(Slice(key_tmp_space, typeinfo_->size()));
   }
 
-  vector<Slice> v;
-  faststring null_headers;
-  if (is_nullable_) {
-    Slice non_null_bitmap = non_null_bitmap_builder_->Finish();
-    PutVarint32(&null_headers, num_elems_in_block);
-    PutVarint32(&null_headers, non_null_bitmap.size());
-    v.emplace_back(null_headers.data(), null_headers.size());
-    v.push_back(non_null_bitmap);
+  Status s;
+  {
+    vector<Slice> v;
+    v.reserve(data_slices.size() + (is_nullable_ ? 2 : 0));
+    faststring null_headers;
+    if (is_nullable_) {
+      const Slice non_null_bitmap = non_null_bitmap_builder_->Finish();
+      PutVarint32(&null_headers, num_elems_in_block);
+      PutVarint32(&null_headers, non_null_bitmap.size());
+      v.emplace_back(null_headers.data(), null_headers.size());
+      v.emplace_back(non_null_bitmap);
+    }
+    std::move(data_slices.begin(), data_slices.end(), std::back_inserter(v));
+    s = AppendRawBlock(std::move(v), first_elem_ord,
+                       reinterpret_cast<const void *>(key_tmp_space),
+                       Slice(last_key_),
+                       "data block");
   }
-  std::move(data_slices.begin(), data_slices.end(), std::back_inserter(v));
-  Status s = AppendRawBlock(v, first_elem_ord,
-                            reinterpret_cast<const void *>(key_tmp_space),
-                            Slice(last_key_),
-                            "data block");
 
   if (is_nullable_) {
     non_null_bitmap_builder_->Reset();
@@ -413,15 +416,15 @@ Status CFileWriter::FinishCurDataBlock() {
   return s;
 }
 
-Status CFileWriter::AppendRawBlock(const vector<Slice>& data_slices,
+Status CFileWriter::AppendRawBlock(vector<Slice> data_slices,
                                    size_t ordinal_pos,
-                                   const void *validx_curr,
+                                   const void* validx_curr,
                                    const Slice& validx_prev,
-                                   const char *name_for_log) {
+                                   const char* name_for_log) {
   CHECK_EQ(state_, kWriterWriting);
 
   BlockPointer ptr;
-  Status s = AddBlock(data_slices, &ptr, name_for_log);
+  Status s = AddBlock(std::move(data_slices), &ptr, name_for_log);
   if (!s.ok()) {
     LOG(WARNING) << "Unable to append block to file: " << s.ToString();
     return s;
@@ -455,29 +458,29 @@ Status CFileWriter::AppendRawBlock(const vector<Slice>& 
data_slices,
   return s;
 }
 
-Status CFileWriter::AddBlock(const vector<Slice> &data_slices,
-                             BlockPointer *block_ptr,
-                             const char *name_for_log) {
+Status CFileWriter::AddBlock(vector<Slice> data_slices,
+                             BlockPointer* block_ptr,
+                             const char* name_for_log) {
   uint64_t start_offset = off_;
   vector<Slice> out_slices;
 
   if (block_compressor_ != nullptr) {
     // Write compressed block
-    Status s = block_compressor_->Compress(data_slices, &out_slices);
+    Status s = block_compressor_->Compress(std::move(data_slices), 
&out_slices);
     if (!s.ok()) {
       LOG(WARNING) << "Unable to compress block at offset " << off_
                    << ": " << s.ToString();
       return s;
     }
   } else {
-    out_slices = data_slices;
+    out_slices = std::move(data_slices);
   }
 
   // Calculate and append a data checksum.
   uint8_t checksum_buf[kChecksumSize];
   if (FLAGS_cfile_write_checksums) {
     uint32_t checksum = 0;
-    for (const Slice &data : out_slices) {
+    for (const Slice& data : out_slices) {
       checksum = crc::Crc32c(data.data(), data.size(), checksum);
     }
     InlineEncodeFixed32(checksum_buf, checksum);
diff --git a/src/kudu/cfile/cfile_writer.h b/src/kudu/cfile/cfile_writer.h
index d0c46f936..14b938f83 100644
--- a/src/kudu/cfile/cfile_writer.h
+++ b/src/kudu/cfile/cfile_writer.h
@@ -141,11 +141,11 @@ class CFileWriter {
   //
   // validx_prev should be a Slice pointing to the last key of the previous 
block.
   // It will be used to optimize the value index entry for the block.
-  Status AppendRawBlock(const std::vector<Slice> &data_slices,
+  Status AppendRawBlock(std::vector<Slice> data_slices,
                         size_t ordinal_pos,
-                        const void *validx_curr,
-                        const Slice &validx_prev,
-                        const char *name_for_log);
+                        const void* validx_curr,
+                        const Slice& validx_prev,
+                        const char* name_for_log);
 
 
   // Return the amount of data written so far to this CFile.
@@ -169,10 +169,10 @@ class CFileWriter {
   fs::WritableBlock* block() const { return block_.get(); }
 
   // Wrapper for AddBlock() to append the dictionary block to the end of a 
Cfile.
-  Status AppendDictBlock(const std::vector<Slice> &data_slices,
-                         BlockPointer *block_ptr,
-                         const char *name_for_log) {
-    return AddBlock(data_slices, block_ptr, name_for_log);
+  Status AppendDictBlock(std::vector<Slice> data_slices,
+                         BlockPointer* block_ptr,
+                         const char* name_for_log) {
+    return AddBlock(std::move(data_slices), block_ptr, name_for_log);
   }
 
  private:
@@ -183,9 +183,9 @@ class CFileWriter {
   // Append the given block into the file.
   //
   // Sets *block_ptr to correspond to the newly inserted block.
-  Status AddBlock(const std::vector<Slice> &data_slices,
-                  BlockPointer *block_ptr,
-                  const char *name_for_log);
+  Status AddBlock(std::vector<Slice> data_slices,
+                  BlockPointer* block_ptr,
+                  const char* name_for_log);
 
   Status WriteRawData(const std::vector<Slice>& data);
 
diff --git a/src/kudu/cfile/index_btree.cc b/src/kudu/cfile/index_btree.cc
index 06963b529..887cbcaf7 100644
--- a/src/kudu/cfile/index_btree.cc
+++ b/src/kudu/cfile/index_btree.cc
@@ -20,6 +20,7 @@
 #include <cstddef>
 #include <memory>
 #include <ostream>
+#include <utility>
 #include <vector>
 
 #include <glog/logging.h>
@@ -160,11 +161,8 @@ Status IndexTreeBuilder::FinishBlockAndPropagate(size_t 
level) {
 // in 'written'.
 Status IndexTreeBuilder::FinishAndWriteBlock(size_t level, BlockPointer 
*written) {
   IndexBlockBuilder* idx_block = idx_blocks_[level].get();
-  Slice data = idx_block->Finish();
-
-  vector<Slice> v;
-  v.push_back(data);
-  Status s = writer_->AddBlock(v, written, "index block");
+  vector<Slice> v { idx_block->Finish() };
+  Status s = writer_->AddBlock(std::move(v), written, "index block");
   if (!s.ok()) {
     LOG(ERROR) << "Unable to append level-" << level << " index "
                << "block to file";

Reply via email to