chanbinme opened a new pull request, #20368:
URL: https://github.com/apache/kafka/pull/20368

   ### Motivation
   The `snapshottableSize(long epoch)` method previously contained unnecessary 
nested conditions and multiple redundant `return baseSize();` statements. This 
refactor aims to simplify the method's control flow and improve code 
readability.
   
   ### Changes
   - Changed the condition from `epoch == LATEST_EPOCH` to `epoch != 
LATEST_EPOCH` to avoid unnecessary else block usage.
   - Consolidated the redundant `return baseSize();` statements into a single 
return at the end of the method.
   - Ensured the iterator logic executes only when necessary, resulting in 
clearer control flow.
   
   ### Before
   ```java
   int snapshottableSize(long epoch) {
       if (epoch == LATEST_EPOCH) {
           return baseSize();
       } else {
           Iterator<Snapshot> iterator = snapshotRegistry.iterator(epoch);
           while(iterator.hasNext()) {
               Snapshot snapshot = iterator.next();
               HashTier<T> tier = 
snapshot.getDelta(SnapshottableHashTable.this);
               if (tier != null) {
                   return tier.size;
               }
           }
           return baseSize();
       }
   }
   ```
   
   ### After
   ```java
   int snapshottableSize(long epoch) {
       if (epoch != LATEST_EPOCH) {
           Iterator<Snapshot> iterator = snapshotRegistry.iterator(epoch);
           while(iterator.hasNext()) {
               Snapshot snapshot = iterator.next();
               HashTier<T> tier = 
snapshot.getDelta(SnapshottableHashTable.this);
               if (tier != null) {
                   return tier.size;
               }
           }
       }
       return baseSize();
   }
   ```
   
   ---
   
   Please let me know if any further adjustments are needed.  
   Thank you for your review!


-- 
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: jira-unsubscr...@kafka.apache.org

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

Reply via email to