Copilot commented on code in PR #37241:
URL: https://github.com/apache/shardingsphere/pull/37241#discussion_r2575608149


##########
parser/sql/statement/core/src/main/java/org/apache/shardingsphere/sql/parser/statement/core/util/SQLUtils.java:
##########
@@ -66,21 +66,26 @@ public final class SQLUtils {
      */
     public static Number getExactlyNumber(final String value, final int radix) 
{
         try {
-            return getBigInteger(value, radix);
+            return getExactlyNumber(new BigInteger(value, radix));
         } catch (final NumberFormatException ex) {
             return new BigDecimal(value);
         }
     }
     
-    private static Number getBigInteger(final String value, final int radix) {
-        BigInteger result = new BigInteger(value, radix);
-        if (result.compareTo(new 
BigInteger(String.valueOf(Integer.MIN_VALUE))) >= 0 && result.compareTo(new 
BigInteger(String.valueOf(Integer.MAX_VALUE))) <= 0) {
-            return result.intValue();
+    /**
+     * Get exactly number.
+     *
+     * @param value to be converted value
+     * @return converted value
+     */
+    public static Number getExactlyNumber(final BigInteger value) {
+        if (value.compareTo(new BigInteger(String.valueOf(Integer.MIN_VALUE))) 
>= 0 && value.compareTo(new BigInteger(String.valueOf(Integer.MAX_VALUE))) <= 
0) {
+            return value.intValue();
         }
-        if (result.compareTo(new BigInteger(String.valueOf(Long.MIN_VALUE))) 
>= 0 && result.compareTo(new BigInteger(String.valueOf(Long.MAX_VALUE))) <= 0) {
-            return result.longValue();
+        if (value.compareTo(new BigInteger(String.valueOf(Long.MIN_VALUE))) >= 
0 && value.compareTo(new BigInteger(String.valueOf(Long.MAX_VALUE))) <= 0) {
+            return value.longValue();
         }
-        return result;
+        return value;

Review Comment:
   Creating unnecessary BigInteger objects for comparisons reduces performance. 
Consider using constants or caching these values instead of converting 
MIN_VALUE and MAX_VALUE to strings and then to BigInteger for every comparison.
   
   For example:
   ```java
   private static final BigInteger INTEGER_MIN = 
BigInteger.valueOf(Integer.MIN_VALUE);
   private static final BigInteger INTEGER_MAX = 
BigInteger.valueOf(Integer.MAX_VALUE);
   private static final BigInteger LONG_MIN = 
BigInteger.valueOf(Long.MIN_VALUE);
   private static final BigInteger LONG_MAX = 
BigInteger.valueOf(Long.MAX_VALUE);
   
   public static Number getExactlyNumber(final BigInteger value) {
       if (value.compareTo(INTEGER_MIN) >= 0 && value.compareTo(INTEGER_MAX) <= 
0) {
           return value.intValue();
       }
       if (value.compareTo(LONG_MIN) >= 0 && value.compareTo(LONG_MAX) <= 0) {
           return value.longValue();
       }
       return value;
   }
   ```



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