You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@groovy.apache.org by su...@apache.org on 2021/09/19 10:52:04 UTC

[groovy] branch danielsun/tweak-compare-bigdecimal updated (68978c9 -> a9b7578)

This is an automated email from the ASF dual-hosted git repository.

sunlan pushed a change to branch danielsun/tweak-compare-bigdecimal
in repository https://gitbox.apache.org/repos/asf/groovy.git.


 discard 68978c9  Trivial tweak for comparing strings
     new a9b7578  Trivial tweak for comparing strings

This update added new revisions after undoing existing revisions.
That is to say, some revisions that were in the old version of the
branch are not in the new version.  This situation occurs
when a user --force pushes a change and generates a repository
containing something like this:

 * -- * -- B -- O -- O -- O   (68978c9)
            \
             N -- N -- N   refs/heads/danielsun/tweak-compare-bigdecimal (a9b7578)

You should already have received notification emails for all of the O
revisions, and so the following emails describe only the N revisions
from the common base, B.

Any revisions marked "omit" are not gone; other references still
refer to them.  Any revisions marked "discard" are gone forever.

The 1 revisions listed above as "new" are entirely new to this
repository and will be described in separate emails.  The revisions
listed as "add" were already present in the repository and have only
been added to this reference.


Summary of changes:
 src/main/java/org/codehaus/groovy/runtime/ScriptBytecodeAdapter.java | 4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)

[groovy] 01/01: Trivial tweak for comparing strings

Posted by su...@apache.org.
This is an automated email from the ASF dual-hosted git repository.

sunlan pushed a commit to branch danielsun/tweak-compare-bigdecimal
in repository https://gitbox.apache.org/repos/asf/groovy.git

commit a9b75788b36c3661a16affaefe263099f64e3bb6
Author: Daniel Sun <su...@apache.org>
AuthorDate: Sun Sep 19 18:50:21 2021 +0800

    Trivial tweak for comparing strings
---
 .../codehaus/groovy/runtime/ScriptBytecodeAdapter.java  | 17 +++++++++++++++++
 1 file changed, 17 insertions(+)

diff --git a/src/main/java/org/codehaus/groovy/runtime/ScriptBytecodeAdapter.java b/src/main/java/org/codehaus/groovy/runtime/ScriptBytecodeAdapter.java
index 02bfbf2..ae9125d 100644
--- a/src/main/java/org/codehaus/groovy/runtime/ScriptBytecodeAdapter.java
+++ b/src/main/java/org/codehaus/groovy/runtime/ScriptBytecodeAdapter.java
@@ -20,6 +20,7 @@ package org.codehaus.groovy.runtime;
 
 import groovy.lang.Closure;
 import groovy.lang.EmptyRange;
+import groovy.lang.GString;
 import groovy.lang.GroovyInterceptable;
 import groovy.lang.GroovyObject;
 import groovy.lang.GroovyRuntimeException;
@@ -728,8 +729,10 @@ public class ScriptBytecodeAdapter {
 
     public static boolean compareEqual(Object left, Object right) {
         if (left==right) return true;
+
         Class<?> leftClass = left==null?null:left.getClass();
         Class<?> rightClass = right==null?null:right.getClass();
+
         if (leftClass ==Integer.class && rightClass==Integer.class) {
             return left.equals(right);
         }
@@ -745,6 +748,20 @@ public class ScriptBytecodeAdapter {
         if (leftClass == BigInteger.class && rightClass == BigInteger.class) {
             return ((BigInteger) left).compareTo((BigInteger) right) == 0;
         }
+
+        if (leftClass == String.class && rightClass == String.class
+                || left instanceof GString && right instanceof GString
+                || leftClass == String.class && right instanceof GString
+                || left instanceof GString && rightClass == String.class) {
+            if (leftClass != String.class) {
+                left = left.toString();
+            }
+            if (rightClass != String.class) {
+                right = right.toString();
+            }
+            return left.equals(right);
+        }
+
         return DefaultTypeTransformation.compareEqual(left, right);
     }