HarshMehta112 opened a new issue, #37159:
URL: https://github.com/apache/shardingsphere/issues/37159

   ### What would you like to be improved?
   
   - orElse(...) eagerly evaluates its argument, meaning the fallback 
expression is computed even when the Optional contains a value.
   - Causing DefaultYamlTupleProcessor to be created even when a suitable 
ShardingSphereYamlTupleProcessor is found.
   
   - Using orElseGet(...) (or the or(...) API) avoids this by evaluating the 
fallback only when needed, making the code more efficient and idiomatic.
   
   
https://github.com/apache/shardingsphere/blob/555c858f8a307169f37c85b932a02fc80bbdec25/infra/util/src/main/java/org/apache/shardingsphere/infra/util/yaml/representer/ShardingSphereYamlRepresenter.java#L54
   
   ### How should we improve?
   Suggested improvement (lazy evaluation)
   ```
   @Override
   protected NodeTuple representJavaBeanProperty(
           final Object javaBean, final Property property, final Object 
propertyValue, final Tag customTag) {
       
       NodeTuple nodeTuple = super.representJavaBeanProperty(javaBean, 
property, propertyValue, customTag);
       return 
TypedSPILoader.findService(ShardingSphereYamlTupleProcessor.class, 
property.getName())
               .map(processor -> processor.process(nodeTuple))
               .orElseGet(() -> new 
DefaultYamlTupleProcessor().process(nodeTuple));
   }
   ```


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

Reply via email to