You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@kudu.apache.org by al...@apache.org on 2025/05/28 19:26:07 UTC

(kudu) branch master updated: [common] clean-up on types.{h,cc}

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 0fcdb326a [common] clean-up on types.{h,cc}
0fcdb326a is described below

commit 0fcdb326aecaa47815ce0425546a0a20ae7f36dd
Author: Alexey Serbin <al...@apache.org>
AuthorDate: Thu May 22 12:42:08 2025 -0700

    [common] clean-up on types.{h,cc}
    
    Anticipating changes in src/kudu/common/types.{h,cc} in the scope of
    array data type project, this patch updates the code to be more style
    guide-compliant.  I also added 'constexpr' specifier to some of
    the methods and fields, allowing for more compile-time optimisation.
    
    This patch doesn't contain any functional modifications.
    
    Change-Id: I68524a2a9cb5540e0c600a629dd29d1f46bd19dc
    Reviewed-on: http://gerrit.cloudera.org:8080/22940
    Tested-by: Alexey Serbin <al...@apache.org>
    Reviewed-by: Abhishek Chennaka <ac...@cloudera.com>
---
 src/kudu/common/types.cc |  39 +++---
 src/kudu/common/types.h  | 348 ++++++++++++++++++++++++-----------------------
 2 files changed, 199 insertions(+), 188 deletions(-)

diff --git a/src/kudu/common/types.cc b/src/kudu/common/types.cc
index 3ff950712..b19ba2e42 100644
--- a/src/kudu/common/types.cc
+++ b/src/kudu/common/types.cc
@@ -37,19 +37,19 @@ using strings::Substitute;
 
 template<typename TypeTraitsClass>
 TypeInfo::TypeInfo(TypeTraitsClass /*t*/)
-  : type_(TypeTraitsClass::type),
-    physical_type_(TypeTraitsClass::physical_type),
-    name_(TypeTraitsClass::name()),
-    size_(TypeTraitsClass::size),
-    min_value_(TypeTraitsClass::min_value()),
-    max_value_(TypeTraitsClass::max_value()),
-    is_virtual_(TypeTraitsClass::IsVirtual()),
-    append_func_(TypeTraitsClass::AppendDebugStringForValue),
-    compare_func_(TypeTraitsClass::Compare),
-    are_consecutive_func_(TypeTraitsClass::AreConsecutive) {
+    : type_(TypeTraitsClass::type),
+      physical_type_(TypeTraitsClass::physical_type),
+      name_(TypeTraitsClass::name()),
+      size_(TypeTraitsClass::size),
+      min_value_(TypeTraitsClass::min_value()),
+      max_value_(TypeTraitsClass::max_value()),
+      is_virtual_(TypeTraitsClass::IsVirtual()),
+      append_func_(TypeTraitsClass::AppendDebugStringForValue),
+      compare_func_(TypeTraitsClass::Compare),
+      are_consecutive_func_(TypeTraitsClass::AreConsecutive) {
 }
 
-void TypeInfo::AppendDebugStringForValue(const void *ptr, string *str) const {
+void TypeInfo::AppendDebugStringForValue(const void* ptr, string* str) const {
   if (KUDU_SHOULD_REDACT()) {
     str->append(kRedactionMessage);
   } else {
@@ -57,7 +57,7 @@ void TypeInfo::AppendDebugStringForValue(const void *ptr, string *str) const {
   }
 }
 
-int TypeInfo::Compare(const void *lhs, const void *rhs) const {
+int TypeInfo::Compare(const void* lhs, const void* rhs) const {
   return compare_func_(lhs, rhs);
 }
 
@@ -68,13 +68,13 @@ bool TypeInfo::AreConsecutive(const void* a, const void* b) const {
 class TypeInfoResolver {
  public:
   const TypeInfo* GetTypeInfo(DataType t) {
-    const TypeInfo *type_info = mapping_[t].get();
-    CHECK(type_info != nullptr) <<
-      "Bad type: " << t;
-    return type_info;
+    const TypeInfo* type_info = mapping_[t].get();
+    return CHECK_NOTNULL(type_info);
   }
 
  private:
+  friend class Singleton<TypeInfoResolver>;
+
   TypeInfoResolver() {
     AddMapping<UINT8>();
     AddMapping<INT8>();
@@ -101,14 +101,13 @@ class TypeInfoResolver {
 
   template<DataType type> void AddMapping() {
     TypeTraits<type> traits;
-    mapping_.emplace(type, unique_ptr<TypeInfo>(new TypeInfo(traits)));
+    mapping_.emplace(type, new TypeInfo(traits));
   }
 
   unordered_map<DataType,
                 unique_ptr<const TypeInfo>,
-                std::hash<size_t> > mapping_;
+                std::hash<size_t>> mapping_;
 
-  friend class Singleton<TypeInfoResolver>;
   DISALLOW_COPY_AND_ASSIGN(TypeInfoResolver);
 };
 
@@ -117,7 +116,7 @@ const TypeInfo* GetTypeInfo(DataType type) {
 }
 
 void DataTypeTraits<DATE>::AppendDebugStringForValue(const void* val, string* str) {
-  constexpr static const char* kDateFormat = "%F"; // the ISO 8601 date format
+  constexpr static const char* const kDateFormat = "%F"; // the ISO 8601 date format
   static constexpr time_t kSecondsInDay = 24 * 60 * 60;
 
   int32_t days_since_unix_epoch = *reinterpret_cast<const int32_t*>(val);
diff --git a/src/kudu/common/types.h b/src/kudu/common/types.h
index 81eaaecfa..ce6d45089 100644
--- a/src/kudu/common/types.h
+++ b/src/kudu/common/types.h
@@ -15,9 +15,7 @@
 // specific language governing permissions and limitations
 // under the License.
 
-#ifndef KUDU_COMMON_TYPES_H
-#define KUDU_COMMON_TYPES_H
-
+#pragma once
 
 #include <cmath>
 #include <cstdint>
@@ -62,9 +60,9 @@ class TypeInfo {
   // Returns the type used to actually store the data.
   DataType physical_type() const { return physical_type_; }
   const std::string& name() const { return name_; }
-  const size_t size() const { return size_; }
-  void AppendDebugStringForValue(const void *ptr, std::string *str) const;
-  int Compare(const void *lhs, const void *rhs) const;
+  size_t size() const { return size_; }
+  void AppendDebugStringForValue(const void* ptr, std::string* str) const;
+  int Compare(const void* lhs, const void* rhs) const;
   // Returns true if increment(a) is equal to b.
   bool AreConsecutive(const void* a, const void* b) const;
   void CopyMinValue(void* dst) const {
@@ -77,6 +75,7 @@ class TypeInfo {
     return max_value_ != nullptr && Compare(value, max_value_) == 0;
   }
   bool is_virtual() const { return is_virtual_; }
+
  private:
   friend class TypeInfoResolver;
   template<typename Type> explicit TypeInfo(Type t);
@@ -91,10 +90,10 @@ class TypeInfo {
   // Whether or not the type may only be used in projections, not tablet schemas.
   const bool is_virtual_;
 
-  typedef void (*AppendDebugFunc)(const void *, std::string *);
+  typedef void (*AppendDebugFunc)(const void*, std::string*);
   const AppendDebugFunc append_func_;
 
-  typedef int (*CompareFunc)(const void *, const void *);
+  typedef int (*CompareFunc)(const void*, const void*);
   const CompareFunc compare_func_;
 
   typedef bool (*AreConsecutiveFunc)(const void*, const void*);
@@ -104,7 +103,7 @@ class TypeInfo {
 template<DataType Type> struct DataTypeTraits {};
 
 template<DataType Type>
-static int GenericCompare(const void *lhs, const void *rhs) {
+static int GenericCompare(const void* lhs, const void* rhs) {
   typedef typename DataTypeTraits<Type>::cpp_type CppType;
   CppType lhs_int = UnalignedLoad<CppType>(lhs);
   CppType rhs_int = UnalignedLoad<CppType>(rhs);
@@ -136,15 +135,15 @@ static int AreFloatsConsecutive(const void* a, const void* b) {
 
 template<>
 struct DataTypeTraits<UINT8> {
-  static const DataType physical_type = UINT8;
   typedef uint8_t cpp_type;
-  static const char *name() {
+  static constexpr const DataType physical_type = UINT8;
+  static constexpr const char* name() {
     return "uint8";
   }
-  static void AppendDebugStringForValue(const void *val, std::string *str) {
-    str->append(SimpleItoa(*reinterpret_cast<const uint8_t *>(val)));
+  static void AppendDebugStringForValue(const void* val, std::string* str) {
+    str->append(SimpleItoa(*reinterpret_cast<const uint8_t*>(val)));
   }
-  static int Compare(const void *lhs, const void *rhs) {
+  static int Compare(const void* lhs, const void* rhs) {
     return GenericCompare<UINT8>(lhs, rhs);
   }
   static bool AreConsecutive(const void* a, const void* b) {
@@ -156,22 +155,22 @@ struct DataTypeTraits<UINT8> {
   static const cpp_type* max_value() {
     return &MathLimits<cpp_type>::kMax;
   }
-  static bool IsVirtual() {
+  static constexpr bool IsVirtual() {
     return false;
   }
 };
 
 template<>
 struct DataTypeTraits<INT8> {
-  static const DataType physical_type = INT8;
   typedef int8_t cpp_type;
-  static const char *name() {
+  static constexpr const DataType physical_type = INT8;
+  static constexpr const char* name() {
     return "int8";
   }
-  static void AppendDebugStringForValue(const void *val, std::string *str) {
-    str->append(SimpleItoa(*reinterpret_cast<const int8_t *>(val)));
+  static void AppendDebugStringForValue(const void* val, std::string* str) {
+    str->append(SimpleItoa(*reinterpret_cast<const int8_t*>(val)));
   }
-  static int Compare(const void *lhs, const void *rhs) {
+  static int Compare(const void* lhs, const void* rhs) {
     return GenericCompare<INT8>(lhs, rhs);
   }
   static bool AreConsecutive(const void* a, const void* b) {
@@ -183,22 +182,22 @@ struct DataTypeTraits<INT8> {
   static const cpp_type* max_value() {
     return &MathLimits<cpp_type>::kMax;
   }
-  static bool IsVirtual() {
+  static constexpr bool IsVirtual() {
     return false;
   }
 };
 
 template<>
 struct DataTypeTraits<UINT16> {
-  static const DataType physical_type = UINT16;
   typedef uint16_t cpp_type;
-  static const char *name() {
+  static constexpr const DataType physical_type = UINT16;
+  static constexpr const char* name() {
     return "uint16";
   }
-  static void AppendDebugStringForValue(const void *val, std::string *str) {
-    str->append(SimpleItoa(*reinterpret_cast<const uint16_t *>(val)));
+  static void AppendDebugStringForValue(const void* val, std::string* str) {
+    str->append(SimpleItoa(*reinterpret_cast<const uint16_t*>(val)));
   }
-  static int Compare(const void *lhs, const void *rhs) {
+  static int Compare(const void* lhs, const void* rhs) {
     return GenericCompare<UINT16>(lhs, rhs);
   }
   static bool AreConsecutive(const void* a, const void* b) {
@@ -210,22 +209,22 @@ struct DataTypeTraits<UINT16> {
   static const cpp_type* max_value() {
     return &MathLimits<cpp_type>::kMax;
   }
-  static bool IsVirtual() {
+  static constexpr bool IsVirtual() {
     return false;
   }
 };
 
 template<>
 struct DataTypeTraits<INT16> {
-  static const DataType physical_type = INT16;
   typedef int16_t cpp_type;
-  static const char *name() {
+  static constexpr const DataType physical_type = INT16;
+  static constexpr const char* name() {
     return "int16";
   }
-  static void AppendDebugStringForValue(const void *val, std::string *str) {
-    str->append(SimpleItoa(*reinterpret_cast<const int16_t *>(val)));
+  static void AppendDebugStringForValue(const void* val, std::string* str) {
+    str->append(SimpleItoa(*reinterpret_cast<const int16_t*>(val)));
   }
-  static int Compare(const void *lhs, const void *rhs) {
+  static int Compare(const void* lhs, const void* rhs) {
     return GenericCompare<INT16>(lhs, rhs);
   }
   static bool AreConsecutive(const void* a, const void* b) {
@@ -237,22 +236,22 @@ struct DataTypeTraits<INT16> {
   static const cpp_type* max_value() {
     return &MathLimits<cpp_type>::kMax;
   }
-  static bool IsVirtual() {
+  static constexpr bool IsVirtual() {
     return false;
   }
 };
 
 template<>
 struct DataTypeTraits<UINT32> {
-  static const DataType physical_type = UINT32;
   typedef uint32_t cpp_type;
-  static const char *name() {
+  static constexpr const DataType physical_type = UINT32;
+  static constexpr const char* name() {
     return "uint32";
   }
-  static void AppendDebugStringForValue(const void *val, std::string *str) {
-    str->append(SimpleItoa(*reinterpret_cast<const uint32_t *>(val)));
+  static void AppendDebugStringForValue(const void* val, std::string* str) {
+    str->append(SimpleItoa(*reinterpret_cast<const uint32_t*>(val)));
   }
-  static int Compare(const void *lhs, const void *rhs) {
+  static int Compare(const void* lhs, const void* rhs) {
     return GenericCompare<UINT32>(lhs, rhs);
   }
   static bool AreConsecutive(const void* a, const void* b) {
@@ -264,22 +263,22 @@ struct DataTypeTraits<UINT32> {
   static const cpp_type* max_value() {
     return &MathLimits<cpp_type>::kMax;
   }
-  static bool IsVirtual() {
+  static constexpr bool IsVirtual() {
     return false;
   }
 };
 
 template<>
 struct DataTypeTraits<INT32> {
-  static const DataType physical_type = INT32;
   typedef int32_t cpp_type;
-  static const char *name() {
+  static constexpr const DataType physical_type = INT32;
+  static constexpr const char* name() {
     return "int32";
   }
-  static void AppendDebugStringForValue(const void *val, std::string *str) {
-    str->append(SimpleItoa(*reinterpret_cast<const int32_t *>(val)));
+  static void AppendDebugStringForValue(const void* val, std::string* str) {
+    str->append(SimpleItoa(*reinterpret_cast<const int32_t*>(val)));
   }
-  static int Compare(const void *lhs, const void *rhs) {
+  static int Compare(const void* lhs, const void* rhs) {
     return GenericCompare<INT32>(lhs, rhs);
   }
   static bool AreConsecutive(const void* a, const void* b) {
@@ -291,22 +290,22 @@ struct DataTypeTraits<INT32> {
   static const cpp_type* max_value() {
     return &MathLimits<cpp_type>::kMax;
   }
-  static bool IsVirtual() {
+  static constexpr bool IsVirtual() {
     return false;
   }
 };
 
 template<>
 struct DataTypeTraits<UINT64> {
-  static const DataType physical_type = UINT64;
   typedef uint64_t cpp_type;
-  static const char *name() {
+  static constexpr const DataType physical_type = UINT64;
+  static constexpr const char* name() {
     return "uint64";
   }
-  static void AppendDebugStringForValue(const void *val, std::string *str) {
-    str->append(SimpleItoa(*reinterpret_cast<const uint64_t *>(val)));
+  static void AppendDebugStringForValue(const void* val, std::string* str) {
+    str->append(SimpleItoa(*reinterpret_cast<const uint64_t*>(val)));
   }
-  static int Compare(const void *lhs, const void *rhs) {
+  static int Compare(const void* lhs, const void* rhs) {
     return GenericCompare<UINT64>(lhs, rhs);
   }
   static bool AreConsecutive(const void* a, const void* b) {
@@ -318,22 +317,22 @@ struct DataTypeTraits<UINT64> {
   static const cpp_type* max_value() {
     return &MathLimits<cpp_type>::kMax;
   }
-  static bool IsVirtual() {
+  static constexpr bool IsVirtual() {
     return false;
   }
 };
 
 template<>
 struct DataTypeTraits<INT64> {
-  static const DataType physical_type = INT64;
   typedef int64_t cpp_type;
-  static const char *name() {
+  static constexpr const DataType physical_type = INT64;
+  static constexpr const char* name() {
     return "int64";
   }
-  static void AppendDebugStringForValue(const void *val, std::string *str) {
-    str->append(SimpleItoa(*reinterpret_cast<const int64_t *>(val)));
+  static void AppendDebugStringForValue(const void* val, std::string* str) {
+    str->append(SimpleItoa(*reinterpret_cast<const int64_t*>(val)));
   }
-  static int Compare(const void *lhs, const void *rhs) {
+  static int Compare(const void* lhs, const void* rhs) {
     return GenericCompare<INT64>(lhs, rhs);
   }
   static bool AreConsecutive(const void* a, const void* b) {
@@ -345,22 +344,22 @@ struct DataTypeTraits<INT64> {
   static const cpp_type* max_value() {
     return &MathLimits<cpp_type>::kMax;
   }
-  static bool IsVirtual() {
+  static constexpr bool IsVirtual() {
     return false;
   }
 };
 
 template<>
 struct DataTypeTraits<INT128> {
-  static const DataType physical_type = INT128;
   typedef int128_t cpp_type;
-  static const char *name() {
+  static constexpr const DataType physical_type = INT128;
+  static constexpr const char* name() {
     return "int128";
   }
-  static void AppendDebugStringForValue(const void *val, std::string *str) {
+  static void AppendDebugStringForValue(const void* val, std::string* str) {
     str->append(SimpleItoa(UnalignedLoad<int128_t>(val)));
   }
-  static int Compare(const void *lhs, const void *rhs) {
+  static int Compare(const void* lhs, const void* rhs) {
     return GenericCompare<INT128>(lhs, rhs);
   }
   static bool AreConsecutive(const void* a, const void* b) {
@@ -372,22 +371,22 @@ struct DataTypeTraits<INT128> {
   static const cpp_type* max_value() {
     return &INT128_MAX;
   }
-  static bool IsVirtual() {
+  static constexpr bool IsVirtual() {
     return false;
   }
 };
 
 template<>
 struct DataTypeTraits<FLOAT> {
-  static const DataType physical_type = FLOAT;
   typedef float cpp_type;
-  static const char *name() {
+  static constexpr const DataType physical_type = FLOAT;
+  static constexpr const char* name() {
     return "float";
   }
-  static void AppendDebugStringForValue(const void *val, std::string *str) {
-    str->append(SimpleFtoa(*reinterpret_cast<const float *>(val)));
+  static void AppendDebugStringForValue(const void* val, std::string* str) {
+    str->append(SimpleFtoa(*reinterpret_cast<const float*>(val)));
   }
-  static int Compare(const void *lhs, const void *rhs) {
+  static int Compare(const void* lhs, const void* rhs) {
     return GenericCompare<FLOAT>(lhs, rhs);
   }
   static bool AreConsecutive(const void* a, const void* b) {
@@ -399,22 +398,22 @@ struct DataTypeTraits<FLOAT> {
   static const cpp_type* max_value() {
     return &MathLimits<cpp_type>::kPosInf;
   }
-  static bool IsVirtual() {
+  static constexpr bool IsVirtual() {
     return false;
   }
 };
 
 template<>
 struct DataTypeTraits<DOUBLE> {
-  static const DataType physical_type = DOUBLE;
   typedef double cpp_type;
-  static const char *name() {
+  static constexpr const DataType physical_type = DOUBLE;
+  static constexpr const char* name() {
     return "double";
   }
-  static void AppendDebugStringForValue(const void *val, std::string *str) {
-    str->append(SimpleDtoa(*reinterpret_cast<const double *>(val)));
+  static void AppendDebugStringForValue(const void* val, std::string* str) {
+    str->append(SimpleDtoa(*reinterpret_cast<const double*>(val)));
   }
-  static int Compare(const void *lhs, const void *rhs) {
+  static int Compare(const void* lhs, const void* rhs) {
     return GenericCompare<DOUBLE>(lhs, rhs);
   }
   static bool AreConsecutive(const void* a, const void* b) {
@@ -426,32 +425,32 @@ struct DataTypeTraits<DOUBLE> {
   static const cpp_type* max_value() {
     return &MathLimits<cpp_type>::kPosInf;
   }
-  static bool IsVirtual() {
+  static constexpr bool IsVirtual() {
     return false;
   }
 };
 
 template<>
 struct DataTypeTraits<BINARY> {
-  static const DataType physical_type = BINARY;
   typedef Slice cpp_type;
-  static const char *name() {
+  static constexpr const DataType physical_type = BINARY;
+  static constexpr const char* name() {
     return "binary";
   }
-  static void AppendDebugStringForValue(const void *val, std::string *str) {
-    const Slice *s = reinterpret_cast<const Slice *>(val);
+  static void AppendDebugStringForValue(const void* val, std::string* str) {
+    const Slice* s = reinterpret_cast<const Slice*>(val);
     str->push_back('"');
     str->append(strings::CHexEscape(s->ToString()));
     str->push_back('"');
   }
-  static int Compare(const void *lhs, const void *rhs) {
-    const Slice *lhs_slice = reinterpret_cast<const Slice *>(lhs);
-    const Slice *rhs_slice = reinterpret_cast<const Slice *>(rhs);
+  static int Compare(const void* lhs, const void* rhs) {
+    const Slice* lhs_slice = reinterpret_cast<const Slice*>(lhs);
+    const Slice* rhs_slice = reinterpret_cast<const Slice*>(rhs);
     return lhs_slice->compare(*rhs_slice);
   }
   static bool AreConsecutive(const void* a, const void* b) {
-    const Slice *a_slice = reinterpret_cast<const Slice *>(a);
-    const Slice *b_slice = reinterpret_cast<const Slice *>(b);
+    const Slice* a_slice = reinterpret_cast<const Slice*>(a);
+    const Slice* b_slice = reinterpret_cast<const Slice*>(b);
     size_t a_size = a_slice->size();
     size_t b_size = b_slice->size();
 
@@ -469,22 +468,22 @@ struct DataTypeTraits<BINARY> {
   static const cpp_type* max_value() {
     return nullptr;
   }
-  static bool IsVirtual() {
+  static constexpr bool IsVirtual() {
     return false;
   }
 };
 
 template<>
 struct DataTypeTraits<BOOL> {
-  static const DataType physical_type = BOOL;
   typedef bool cpp_type;
-  static const char* name() {
+  static constexpr const DataType physical_type = BOOL;
+  static constexpr const char* name() {
     return "bool";
   }
   static void AppendDebugStringForValue(const void* val, std::string* str) {
-    str->append(*reinterpret_cast<const bool *>(val) ? "true" : "false");
+    str->append(*reinterpret_cast<const bool*>(val) ? "true" : "false");
   }
-  static int Compare(const void *lhs, const void *rhs) {
+  static int Compare(const void* lhs, const void* rhs) {
     return GenericCompare<BOOL>(lhs, rhs);
   }
   static bool AreConsecutive(const void* a, const void* b) {
@@ -498,7 +497,7 @@ struct DataTypeTraits<BOOL> {
     static bool b = true;
     return &b;
   }
-  static bool IsVirtual() {
+  static constexpr bool IsVirtual() {
     return false;
   }
 };
@@ -508,13 +507,13 @@ struct DataTypeTraits<BOOL> {
 template<DataType PhysicalType>
 struct DerivedTypeTraits {
   typedef typename DataTypeTraits<PhysicalType>::cpp_type cpp_type;
-  static const DataType physical_type = PhysicalType;
+  static constexpr const DataType physical_type = PhysicalType;
 
-  static void AppendDebugStringForValue(const void *val, std::string *str) {
+  static void AppendDebugStringForValue(const void* val, std::string* str) {
     DataTypeTraits<PhysicalType>::AppendDebugStringForValue(val, str);
   }
 
-  static int Compare(const void *lhs, const void *rhs) {
+  static int Compare(const void* lhs, const void* rhs) {
     return DataTypeTraits<PhysicalType>::Compare(lhs, rhs);
   }
 
@@ -529,18 +528,18 @@ struct DerivedTypeTraits {
   static const cpp_type* max_value() {
     return DataTypeTraits<PhysicalType>::max_value();
   }
-  static bool IsVirtual() {
+  static constexpr bool IsVirtual() {
     return DataTypeTraits<PhysicalType>::IsVirtual();
   }
 };
 
 template<>
 struct DataTypeTraits<STRING> : public DerivedTypeTraits<BINARY>{
-  static const char* name() {
+  static constexpr const char* name() {
     return "string";
   }
-  static void AppendDebugStringForValue(const void *val, std::string *str) {
-    const Slice *s = reinterpret_cast<const Slice *>(val);
+  static void AppendDebugStringForValue(const void* val, std::string* str) {
+    const Slice* s = reinterpret_cast<const Slice*>(val);
     str->push_back('"');
     str->append(strings::Utf8SafeCEscape(s->ToString()));
     str->push_back('"');
@@ -550,16 +549,16 @@ struct DataTypeTraits<STRING> : public DerivedTypeTraits<BINARY>{
 
 template<>
 struct DataTypeTraits<UNIXTIME_MICROS> : public DerivedTypeTraits<INT64>{
-  static const int kMicrosInSecond = 1000L * 1000L;
+  constexpr static const int kMicrosInSecond = 1000L * 1000L;
   constexpr static const char* kDateFormat = "%Y-%m-%dT%H:%M:%S";
   constexpr static const char* kDateMicrosAndTzFormat = "%s.%06dZ";
 
-  static const char* name() {
+  static constexpr const char* name() {
     return "unixtime_micros";
   }
 
   static void AppendDebugStringForValue(const void* val, std::string* str) {
-    int64_t timestamp_micros = *reinterpret_cast<const int64_t *>(val);
+    int64_t timestamp_micros = *reinterpret_cast<const int64_t*>(val);
     time_t secs_since_epoch = timestamp_micros / kMicrosInSecond;
     // If the time is negative we need to take into account that any microseconds
     // will actually decrease the time in seconds by one.
@@ -580,11 +579,11 @@ struct DataTypeTraits<UNIXTIME_MICROS> : public DerivedTypeTraits<INT64>{
 
 template<>
 struct DataTypeTraits<DATE> : public DerivedTypeTraits<INT32>{
+  typedef int32_t cpp_type;
   static constexpr int32_t kMinValue = -719162; // mktime(0001-01-01)
   static constexpr int32_t kMaxValue = 2932896; // mktime(9999-12-31)
-  typedef int32_t cpp_type;
 
-  static const char* name() {
+  static constexpr const char* name() {
     return "date";
   }
 
@@ -605,13 +604,13 @@ struct DataTypeTraits<DATE> : public DerivedTypeTraits<INT32>{
 
 template<>
 struct DataTypeTraits<DECIMAL32> : public DerivedTypeTraits<INT32>{
-  static const char* name() {
+  static constexpr const char* name() {
     return "decimal";
   }
   // AppendDebugStringForValue appends the (string representation of) the
   // underlying integer value with the "_D32" suffix as there's no "full"
   // type information available to format it.
-  static void AppendDebugStringForValue(const void *val, std::string *str) {
+  static void AppendDebugStringForValue(const void* val, std::string* str) {
     DataTypeTraits<physical_type>::AppendDebugStringForValue(val, str);
     str->append("_D32");
   }
@@ -619,13 +618,13 @@ struct DataTypeTraits<DECIMAL32> : public DerivedTypeTraits<INT32>{
 
 template<>
 struct DataTypeTraits<DECIMAL64> : public DerivedTypeTraits<INT64>{
-  static const char* name() {
+  static constexpr const char* name() {
     return "decimal";
   }
   // AppendDebugStringForValue appends the (string representation of) the
   // underlying integer value with the "_D64" suffix as there's no "full"
   // type information available to format it.
-  static void AppendDebugStringForValue(const void *val, std::string *str) {
+  static void AppendDebugStringForValue(const void* val, std::string* str) {
     DataTypeTraits<physical_type>::AppendDebugStringForValue(val, str);
     str->append("_D64");
   }
@@ -633,13 +632,13 @@ struct DataTypeTraits<DECIMAL64> : public DerivedTypeTraits<INT64>{
 
 template<>
 struct DataTypeTraits<DECIMAL128> : public DerivedTypeTraits<INT128>{
-  static const char* name() {
+  static constexpr const char* name() {
     return "decimal";
   }
   // AppendDebugStringForValue appends the (string representation of) the
   // underlying integer value with the "_D128" suffix as there's no "full"
   // type information available to format it.
-  static void AppendDebugStringForValue(const void *val, std::string *str) {
+  static void AppendDebugStringForValue(const void* val, std::string* str) {
     DataTypeTraits<physical_type>::AppendDebugStringForValue(val, str);
     str->append("_D128");
   }
@@ -647,21 +646,21 @@ struct DataTypeTraits<DECIMAL128> : public DerivedTypeTraits<INT128>{
 
 template<>
 struct DataTypeTraits<IS_DELETED> : public DerivedTypeTraits<BOOL>{
-  static const char* name() {
+  static constexpr const char* name() {
     return "is_deleted";
   }
-  static bool IsVirtual() {
+  static constexpr bool IsVirtual() {
     return true;
   }
 };
 
 template<>
 struct DataTypeTraits<VARCHAR> : public DerivedTypeTraits<BINARY>{
-  static const char* name() {
+  static constexpr const char* name() {
     return "varchar";
   }
-  static void AppendDebugStringForValue(const void *val, std::string *str) {
-    const Slice *s = reinterpret_cast<const Slice *>(val);
+  static void AppendDebugStringForValue(const void* val, std::string* str) {
+    const Slice* s = reinterpret_cast<const Slice*>(val);
     str->push_back('"');
     str->append(strings::Utf8SafeCEscape(s->ToString()));
     str->push_back('"');
@@ -673,13 +672,13 @@ template<DataType datatype>
 struct TypeTraits : public DataTypeTraits<datatype> {
   typedef typename DataTypeTraits<datatype>::cpp_type cpp_type;
 
-  static const DataType type = datatype;
-  static const size_t size = sizeof(cpp_type);
+  static constexpr const DataType type = datatype;
+  static constexpr const size_t size = sizeof(cpp_type);
 };
 
-class Variant {
+class Variant final {
  public:
-  Variant(DataType type, const void *value) {
+  Variant(DataType type, const void* value) {
     Reset(type, value);
   }
 
@@ -702,71 +701,70 @@ class Variant {
   //      Slice slice("Hello World");
   //      variant.set(UINT16, &u16);
   //      variant.set(STRING, &slice);
-  void Reset(DataType type, const void *value) {
-    CHECK(value != NULL) << "Variant value must be not NULL";
+  void Reset(DataType type, const void* value) {
+    DCHECK(value) << "variant value must be not NULL";
     Clear();
     type_ = type;
     switch (type_) {
       case UNKNOWN_DATA:
         LOG(FATAL) << "Unreachable";
+        break;
       case IS_DELETED:
       case BOOL:
-        numeric_.b1 = *static_cast<const bool *>(value);
+        numeric_.b1 = *static_cast<const bool*>(value);
         break;
       case INT8:
-        numeric_.i8 = *static_cast<const int8_t *>(value);
+        numeric_.i8 = *static_cast<const int8_t*>(value);
         break;
       case UINT8:
-        numeric_.u8 = *static_cast<const uint8_t *>(value);
+        numeric_.u8 = *static_cast<const uint8_t*>(value);
         break;
       case INT16:
-        numeric_.i16 = *static_cast<const int16_t *>(value);
+        numeric_.i16 = *static_cast<const int16_t*>(value);
         break;
       case UINT16:
-        numeric_.u16 = *static_cast<const uint16_t *>(value);
+        numeric_.u16 = *static_cast<const uint16_t*>(value);
         break;
       case DATE:
       case DECIMAL32:
       case INT32:
-        numeric_.i32 = *static_cast<const int32_t *>(value);
+        numeric_.i32 = *static_cast<const int32_t*>(value);
         break;
       case UINT32:
-        numeric_.u32 = *static_cast<const uint32_t *>(value);
+        numeric_.u32 = *static_cast<const uint32_t*>(value);
         break;
       case DECIMAL64:
       case UNIXTIME_MICROS:
       case INT64:
-        numeric_.i64 = *static_cast<const int64_t *>(value);
+        numeric_.i64 = *static_cast<const int64_t*>(value);
         break;
       case UINT64:
-        numeric_.u64 = *static_cast<const uint64_t *>(value);
+        numeric_.u64 = *static_cast<const uint64_t*>(value);
         break;
       case DECIMAL128:
       case INT128:
         numeric_.i128 = UnalignedLoad<int128_t>(value);
         break;
       case FLOAT:
-        numeric_.float_val = *static_cast<const float *>(value);
+        numeric_.float_val = *static_cast<const float*>(value);
         break;
       case DOUBLE:
-        numeric_.double_val = *static_cast<const double *>(value);
+        numeric_.double_val = *static_cast<const double*>(value);
         break;
-      case STRING: // Fallthrough intended.
+      case STRING:
       case VARCHAR:
       case BINARY:
-        {
-          const Slice *str = static_cast<const Slice *>(value);
-          // In the case that str->size() == 0, then the 'Clear()' above has already
+        if (const Slice* str = static_cast<const Slice*>(value); !str->empty()) {
+          // If str->empty(), the 'Clear()' above has already
           // set vstr_ to Slice(""). Otherwise, we need to allocate and copy the
           // user's data.
-          if (str->size() > 0) {
-            auto blob = new uint8_t[str->size()];
-            memcpy(blob, str->data(), str->size());
-            vstr_ = Slice(blob, str->size());
-          }
+          auto* blob = new uint8_t[str->size()];
+          memcpy(blob, str->data(), str->size());
+          vstr_ = Slice(blob, str->size());
         }
         break;
-      default: LOG(FATAL) << "Unknown data type: " << type_;
+      default:
+        LOG(FATAL) << "Unknown data type: " << type_;
     }
   }
 
@@ -781,7 +779,7 @@ class Variant {
   // Set the variant to a STRING type.
   // The specified data block will be copied, and released by the variant
   // on the next set/clear call.
-  void Reset(const char *data, size_t size) {
+  void Reset(const char* data, size_t size) {
     Slice slice(data, size);
     Reset(STRING, &slice);
   }
@@ -796,53 +794,67 @@ class Variant {
   // The return value will be valid until the next set() is called.
   //
   //  Examples:
-  //    static_cast<const int32_t *>(variant.value())
-  //    static_cast<const Slice *>(variant.value())
-  const void *value() const {
+  //    static_cast<const int32_t*>(variant.value())
+  //    static_cast<const Slice*>(variant.value())
+  const void* value() const {
     switch (type_) {
-      case UNKNOWN_DATA: LOG(FATAL) << "Attempted to access value of unknown data type";
+      case UNKNOWN_DATA:
+        LOG(FATAL) << "Attempted to access value of unknown data type";
+        return nullptr;
       case IS_DELETED:
-      case BOOL:         return &(numeric_.b1);
-      case INT8:         return &(numeric_.i8);
-      case UINT8:        return &(numeric_.u8);
-      case INT16:        return &(numeric_.i16);
-      case UINT16:       return &(numeric_.u16);
+      case BOOL:
+        return &numeric_.b1;
+      case INT8:
+        return &numeric_.i8;
+      case UINT8:
+        return &numeric_.u8;
+      case INT16:
+        return &numeric_.i16;
+      case UINT16:
+        return &numeric_.u16;
       case DATE:
       case DECIMAL32:
-      case INT32:        return &(numeric_.i32);
-      case UINT32:       return &(numeric_.u32);
+      case INT32:
+        return &numeric_.i32;
+      case UINT32:
+        return &numeric_.u32;
       case DECIMAL64:
       case UNIXTIME_MICROS:
-      case INT64:        return &(numeric_.i64);
-      case UINT64:       return &(numeric_.u64);
+      case INT64:
+        return &numeric_.i64;
+      case UINT64:
+        return &numeric_.u64;
       case DECIMAL128:
-      case INT128:       return &(numeric_.i128);
-      case FLOAT:        return (&numeric_.float_val);
-      case DOUBLE:       return (&numeric_.double_val);
+      case INT128:
+        return &numeric_.i128;
+      case FLOAT:
+        return &numeric_.float_val;
+      case DOUBLE:
+        return &numeric_.double_val;
       case STRING:
       case VARCHAR:
-      case BINARY:       return &vstr_;
-      default: LOG(FATAL) << "Unknown data type: " << type_;
+      case BINARY:
+        return &vstr_;
+      default:
+        LOG(FATAL) << "Unknown data type: " << type_;
+        return nullptr;
     }
-    CHECK(false) << "not reached!";
-    return NULL;
   }
 
-  bool Equals(const Variant *other) const {
-    if (other == NULL || type_ != other->type_)
+  bool Equals(const Variant* other) const {
+    if (other == nullptr || type_ != other->type_) {
       return false;
+    }
     return GetTypeInfo(type_)->Compare(value(), other->value()) == 0;
   }
 
  private:
-  DISALLOW_COPY_AND_ASSIGN(Variant);
-
   void Clear() {
     // No need to delete[] zero-length vstr_, because we always ensure that
     // such a string would point to a constant "" rather than an allocated piece
     // of memory.
-    if (vstr_.size() > 0) {
-      delete[] vstr_.mutable_data();
+    if (!vstr_.empty()) {
+      delete [] vstr_.mutable_data();
       vstr_.clear();
     }
   }
@@ -865,8 +877,8 @@ class Variant {
   DataType type_;
   NumericValue numeric_;
   Slice vstr_;
+
+  DISALLOW_COPY_AND_ASSIGN(Variant);
 };
 
 }  // namespace kudu
-
-#endif