You are viewing a plain text version of this content. The canonical link for it is here.
Posted to notifications@geode.apache.org by GitBox <gi...@apache.org> on 2021/06/15 17:33:02 UTC

[GitHub] [geode] jdeppe-pivotal commented on a change in pull request #6599: GEODE-9287: Always use Coder for Radish String/byte[] conversion

jdeppe-pivotal commented on a change in pull request #6599:
URL: https://github.com/apache/geode/pull/6599#discussion_r652009305



##########
File path: geode-apis-compatible-with-redis/src/main/java/org/apache/geode/redis/internal/executor/server/InfoExecutor.java
##########
@@ -50,44 +61,29 @@ private boolean containsSectionParameter(List<byte[]> commands) {
     return commands.size() == 2;
   }
 
-  private String getSpecifiedSection(ExecutionHandlerContext context,
-      List<byte[]> commands) {
-    String result;
-    String section = Coder.bytesToString(commands.get(1)).toLowerCase();
-    switch (section) {
-      case "server":
-        result = getServerSection(context);
-        break;
-      case "cluster":
-        result = getClusterSection();
-        break;
-      case "persistence":
-        result = getPersistenceSection();
-        break;
-      case "replication":
-        result = getReplicationSection();
-        break;
-      case "stats":
-        result = getStatsSection(context);
-        break;
-      case "clients":
-        result = getClientsSection(context);
-        break;
-      case "memory":
-        result = getMemorySection(context);
-        break;
-      case "keyspace":
-        result = getKeyspaceSection(context);
-        break;
-      case "default":
-      case "all":
-        result = getAllSections(context);
-        break;
-      default:
-        result = "";
-        break;
+  private String getSpecifiedSection(ExecutionHandlerContext context, List<byte[]> commands) {

Review comment:
       I was curious about this too. It looks like `switch` still ends up calling `String.equals` for each case, although it might seem that this should only be necessary once. Worst case for the new code is if the most common case is the last check as each `if` needs to be evaluated. However, doing a quick jmh benchmark with an even distribution, seems to show that the new code would be about 8x faster than the old code. For more details: https://blog.jamesdbloom.com/JavaCodeToByteCode_PartOne.html#switch
   




-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

For queries about this service, please contact Infrastructure at:
users@infra.apache.org