kafka-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From ewe...@apache.org
Subject kafka git commit: KAFKA-6218: Optimize condition in if statement to reduce the number of comparisons
Date Thu, 16 Nov 2017 23:06:37 GMT
Repository: kafka
Updated Branches:
  refs/heads/trunk d9cbc6b1a -> 002612154


KAFKA-6218: Optimize condition in if statement to reduce the number of comparisons

Changed the condition in **if** statement
**(schema.name() == null || !(schema.name().equals(LOGICAL_NAME)))** which
requires two comparisons in worst case with
**(!LOGICAL_NAME.equals(schema.name()))**  which requires single comparison
in all cases and _avoids null pointer exception.
![kafka_optimize_if](https://user-images.githubusercontent.com/32234013/32872271-afe0b954-ca3a-11e7-838d-6a3bc416b807.JPG)
_

Author: sachinbhalekar <sachinbansibhalekar@gmail.com>
Author: sachinbhalekar <32234013+sachinbhalekar@users.noreply.github.com>

Reviewers: Randall Hauch <rhauch@gmail.com>, Ewen Cheslack-Postava <ewen@confluent.io>

Closes #4225 from sachinbhalekar/trunk


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

Branch: refs/heads/trunk
Commit: 00261215436e50fa894f765c1b123f9a780380b1
Parents: d9cbc6b
Author: sachinbhalekar <sachinbansibhalekar@gmail.com>
Authored: Thu Nov 16 15:04:27 2017 -0800
Committer: Ewen Cheslack-Postava <me@ewencp.org>
Committed: Thu Nov 16 15:04:27 2017 -0800

----------------------------------------------------------------------
 .../api/src/main/java/org/apache/kafka/connect/data/Date.java    | 4 ++--
 .../api/src/main/java/org/apache/kafka/connect/data/Time.java    | 4 ++--
 .../src/main/java/org/apache/kafka/connect/data/Timestamp.java   | 4 ++--
 3 files changed, 6 insertions(+), 6 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/kafka/blob/00261215/connect/api/src/main/java/org/apache/kafka/connect/data/Date.java
----------------------------------------------------------------------
diff --git a/connect/api/src/main/java/org/apache/kafka/connect/data/Date.java b/connect/api/src/main/java/org/apache/kafka/connect/data/Date.java
index 7a6fb3f..e87188c 100644
--- a/connect/api/src/main/java/org/apache/kafka/connect/data/Date.java
+++ b/connect/api/src/main/java/org/apache/kafka/connect/data/Date.java
@@ -55,7 +55,7 @@ public class Date {
      * @return the encoded value
      */
     public static int fromLogical(Schema schema, java.util.Date value) {
-        if (schema.name() == null || !(schema.name().equals(LOGICAL_NAME)))
+        if (!(LOGICAL_NAME.equals(schema.name())))
             throw new DataException("Requested conversion of Date object but the schema does
not match.");
         Calendar calendar = Calendar.getInstance(UTC);
         calendar.setTime(value);
@@ -68,7 +68,7 @@ public class Date {
     }
 
     public static java.util.Date toLogical(Schema schema, int value) {
-        if (schema.name() == null || !(schema.name().equals(LOGICAL_NAME)))
+        if (!(LOGICAL_NAME.equals(schema.name())))
             throw new DataException("Requested conversion of Date object but the schema does
not match.");
         return new java.util.Date(value * MILLIS_PER_DAY);
     }

http://git-wip-us.apache.org/repos/asf/kafka/blob/00261215/connect/api/src/main/java/org/apache/kafka/connect/data/Time.java
----------------------------------------------------------------------
diff --git a/connect/api/src/main/java/org/apache/kafka/connect/data/Time.java b/connect/api/src/main/java/org/apache/kafka/connect/data/Time.java
index b403ac1..ad642e4 100644
--- a/connect/api/src/main/java/org/apache/kafka/connect/data/Time.java
+++ b/connect/api/src/main/java/org/apache/kafka/connect/data/Time.java
@@ -55,7 +55,7 @@ public class Time {
      * @return the encoded value
      */
     public static int fromLogical(Schema schema, java.util.Date value) {
-        if (schema.name() == null || !(schema.name().equals(LOGICAL_NAME)))
+        if (!(LOGICAL_NAME.equals(schema.name())))
             throw new DataException("Requested conversion of Time object but the schema does
not match.");
         Calendar calendar = Calendar.getInstance(UTC);
         calendar.setTime(value);
@@ -67,7 +67,7 @@ public class Time {
     }
 
     public static java.util.Date toLogical(Schema schema, int value) {
-        if (schema.name() == null || !(schema.name().equals(LOGICAL_NAME)))
+        if (!(LOGICAL_NAME.equals(schema.name())))
             throw new DataException("Requested conversion of Date object but the schema does
not match.");
         if (value  < 0 || value > MILLIS_PER_DAY)
             throw new DataException("Time values must use number of milliseconds greater
than 0 and less than 86400000");

http://git-wip-us.apache.org/repos/asf/kafka/blob/00261215/connect/api/src/main/java/org/apache/kafka/connect/data/Timestamp.java
----------------------------------------------------------------------
diff --git a/connect/api/src/main/java/org/apache/kafka/connect/data/Timestamp.java b/connect/api/src/main/java/org/apache/kafka/connect/data/Timestamp.java
index 8c426f4..2da6107 100644
--- a/connect/api/src/main/java/org/apache/kafka/connect/data/Timestamp.java
+++ b/connect/api/src/main/java/org/apache/kafka/connect/data/Timestamp.java
@@ -46,13 +46,13 @@ public class Timestamp {
      * @return the encoded value
      */
     public static long fromLogical(Schema schema, java.util.Date value) {
-        if (schema.name() == null || !(schema.name().equals(LOGICAL_NAME)))
+        if (!(LOGICAL_NAME.equals(schema.name())))
             throw new DataException("Requested conversion of Timestamp object but the schema
does not match.");
         return value.getTime();
     }
 
     public static java.util.Date toLogical(Schema schema, long value) {
-        if (schema.name() == null || !(schema.name().equals(LOGICAL_NAME)))
+        if (!(LOGICAL_NAME.equals(schema.name())))
             throw new DataException("Requested conversion of Timestamp object but the schema
does not match.");
         return new java.util.Date(value);
     }


Mime
View raw message