You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@kudu.apache.org by to...@apache.org on 2017/11/22 06:10:01 UTC

[4/6] kudu git commit: schema: fast-path for Schema::KeyEquals, etc.

schema: fast-path for Schema::KeyEquals, etc.

If two schemas are the same object, then KeyEquals can be fast-pathed.
The same goes for various ColumnSchema equality checks.

This hasn't been a hot path in release builds, but I noticed a lot of wasted
CPU in a debug build evaluating Schema::KeyEquals, and my suspicion is that in
a great number of cases the objects are identical. Even in release builds, may
as well avoid the unnecessary cycles.

Change-Id: Ia5fadfd70ea651b9105837535f21a34c6e0af6ae
Reviewed-on: http://gerrit.cloudera.org:8080/8627
Reviewed-by: Alexey Serbin <as...@cloudera.com>
Tested-by: Kudu Jenkins


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

Branch: refs/heads/master
Commit: 0362ec7681040231394eabf9026f10743d6d28be
Parents: 3a22437
Author: Todd Lipcon <to...@apache.org>
Authored: Tue Nov 21 15:12:48 2017 -0800
Committer: Todd Lipcon <to...@apache.org>
Committed: Wed Nov 22 02:29:30 2017 +0000

----------------------------------------------------------------------
 src/kudu/common/schema.h | 5 +++++
 1 file changed, 5 insertions(+)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/kudu/blob/0362ec76/src/kudu/common/schema.h
----------------------------------------------------------------------
diff --git a/src/kudu/common/schema.h b/src/kudu/common/schema.h
index 8bfb76b..362b1a7 100644
--- a/src/kudu/common/schema.h
+++ b/src/kudu/common/schema.h
@@ -243,11 +243,13 @@ class ColumnSchema {
   }
 
   bool EqualsPhysicalType(const ColumnSchema& other) const {
+    if (this == &other) return true;
     return is_nullable_ == other.is_nullable_ &&
            type_info()->physical_type() == other.type_info()->physical_type();
   }
 
   bool EqualsType(const ColumnSchema &other) const {
+    if (this == &other) return true;
     return is_nullable_ == other.is_nullable_ &&
            type_info()->type() == other.type_info()->type();
   }
@@ -263,6 +265,8 @@ class ColumnSchema {
 
   bool Equals(const ColumnSchema &other,
               int flags = COMPARE_ALL) const {
+    if (this == &other) return true;
+
     if ((flags & COMPARE_NAME) && this->name_ != other.name_)
       return false;
 
@@ -703,6 +707,7 @@ class Schema {
   bool KeyEquals(const Schema& other,
                  int flags
                     = ColumnSchema::COMPARE_NAME | ColumnSchema::COMPARE_TYPE) const {
+    if (this == &other) return true;
     if (this->num_key_columns_ != other.num_key_columns_) return false;
     for (size_t i = 0; i < this->num_key_columns_; i++) {
       if (!this->cols_[i].Equals(other.cols_[i], flags)) return false;