LiangliangSui commented on code in PR #1511:
URL: https://github.com/apache/incubator-fury/pull/1511#discussion_r1564658362


##########
java/fury-core/src/main/java/org/apache/fury/resolver/ClassResolver.java:
##########
@@ -431,15 +429,14 @@ public void register(Class<?> cls, int classId) {
     Preconditions.checkArgument(classId >= 0 && classId < Short.MAX_VALUE);
     Preconditions.checkArgument(
         !extRegistry.registeredClassIdMap.containsKey(cls),

Review Comment:
   ```java
       Preconditions.checkArgument(
           !extRegistry.registeredClassIdMap.containsKey(cls),
           "Class %s already registered with id %s.",
           cls,
           extRegistry.registeredClassIdMap.get(cls));
       Preconditions.checkArgument(
           !extRegistry.registeredClasses.containsKey(cls.getName()),
           "Class %s with name %s has been registered, registering class with 
same name are not allowed.",
           extRegistry.registeredClasses.get(cls.getName()),
           cls.getName());
   ```
   
   ```java
       if (extRegistry.registeredClassIdMap.containsKey(cls)) {
         throw new IllegalArgumentException(
             String.format(
                 "Class %s already registered with id %s.",
                 cls, extRegistry.registeredClassIdMap.get(cls)));
       }
   
       if (extRegistry.registeredClasses.containsKey(cls.getName())) {
         throw new IllegalArgumentException(
             String.format(
                 "Class %s with name %s has been registered, registering class 
with same name are not allowed.",
                 extRegistry.registeredClasses.get(cls.getName()), 
cls.getName()));
       }
   ```
   
   The former `extRegistry.registeredClassIdMap.get` will definitely be 
executed, while the latter will only be executed when there is an exception. We 
can save the cost of `extRegistry.registeredClassIdMap.get`.



-- 
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.

To unsubscribe, e-mail: [email protected]

For queries about this service, please contact Infrastructure at:
[email protected]


---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]

Reply via email to