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:50:42 UTC

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

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 c4bce18  Trivial tweak for comparing `CharSequence` instances
     new 68978c9  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   (c4bce18)
            \
             N -- N -- N   refs/heads/danielsun/tweak-compare-bigdecimal (68978c9)

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:
 .../java/org/codehaus/groovy/runtime/ScriptBytecodeAdapter.java     | 6 +++++-
 1 file changed, 5 insertions(+), 1 deletion(-)

[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 68978c976f7813466550871de22a86c73fe150ca
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..894ebfd 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
+                || left instanceof GString && rightClass == String.class
+                || leftClass == String.class && right instanceof GString) {
+            if (leftClass != String.class) {
+                left = left.toString();
+            }
+            if (rightClass != String.class) {
+                right = right.toString();
+            }
+            return left.equals(right);
+        }
+
         return DefaultTypeTransformation.compareEqual(left, right);
     }