Details

    • Type: Sub-task Sub-task
    • Status: Open Open
    • Priority: Major Major
    • Resolution: Unresolved
    • Affects Version/s: None
    • Fix Version/s: 3.0
    • Component/s: groovy-runtime
    • Labels:
      None
    • Environment:
      N/A
    • Testcase included:
      yes
    • Patch Submitted:
      Yes
    • Number of attachments :
      1

      Description

      groovy:000> 1000 * 1000000000
      ===> 1000000000000
      

      More info in mail thread http://www.nabble.com/Patch:-Dynamic-type-promotion-td22976282.html

      Patch attached. Diffstat:

      main/org/codehaus/groovy/runtime/DefaultGroovyMethods.java        |   23 -
      main/org/codehaus/groovy/runtime/InvokerHelper.java               |   20 -
      main/org/codehaus/groovy/runtime/typehandling/BigIntegerMath.java |   26 +
      main/org/codehaus/groovy/runtime/typehandling/IntegerMath.java    |   70 ++++
      main/org/codehaus/groovy/runtime/typehandling/LongMath.java       |   85 ++++--
      main/org/codehaus/groovy/runtime/typehandling/NumberMath.java     |   90 ++++--
      test/groovy/operator/IntegerOperatorsTest.groovy                  |  141 +++++++++-
      7 files changed, 369 insertions(+), 86 deletions(-)
      

      I'll also keep an updated patch available at http://dl.getdropbox.com/u/283098/patches/groovy_dynamic_type_promotion.patch

      Here's an overview of the patch:

      • Added test cases to IntegerOperatorsTest.groovy
      • Modified NumberMath toBigInteger and toBigDecimal methods to call into DefaultGroovyMethods versions
      • Modified IntegerMath to support dynamic type promotion for abs, add, subtract, multiply, unary minus and left shift.
      • Modified BigIntegerMath to support left shift and right shift. It does not support unsigned right shift (>>>).
      • Modified LongMath to support dynamic type promotion for abs, add, subtract, multiply, unary minus and left shift. Also changed a few "new Long" to "Long.valueOf" since it can be faster.
      • Modified DefaultGroovyMethods.abs to call into NumberMath. Optimized toBigInteger so that it doesn't do unnecessary string conversions. Tweaked a few comments.
      • Modified InvokerHelper.unaryMinus. Tweaked some valueOf.
      • Modified semantics for the shift operators. It's now type coerced/promoted the same as other binary operators. Negative shifts are not allowed.

        Activity

        Hide
        Pascal Schumacher added a comment -

        Is this something for 3.0 or is it not relevant any longer and should be closed?

        Show
        Pascal Schumacher added a comment - Is this something for 3.0 or is it not relevant any longer and should be closed?
        Hide
        blackdrag blackdrag added a comment -

        Actually I would like this be turned into kind of a library. Then people can turn use it if they want. By default I wouldn't want this, since it means a performance problem. In 1.5 and before the difference was probably near zero, but for indy for example I know that not knowing the return type of an operation on two primitives means boxing and unboxing actions that not all are removed by the JIT, thus are a serious slow down.

        Show
        blackdrag blackdrag added a comment - Actually I would like this be turned into kind of a library. Then people can turn use it if they want. By default I wouldn't want this, since it means a performance problem. In 1.5 and before the difference was probably near zero, but for indy for example I know that not knowing the return type of an operation on two primitives means boxing and unboxing actions that not all are removed by the JIT, thus are a serious slow down.

          People

          • Assignee:
            Unassigned
            Reporter:
            Olov Lassus
          • Votes:
            0 Vote for this issue
            Watchers:
            2 Start watching this issue

            Dates

            • Created:
              Updated: