Uploaded image for project: 'JDK'
  1. JDK
  2. JDK-6223413

Dead store to local variable in method java.math.MutableBigInteger.binaryGCD(MutableBigInteger)

    XMLWordPrintable

Details

    • b23
    • generic
    • generic

    Description

      In method java.math.Mutable.binaryGCD(MutableBigInteger) there is an assignment to a local object called q, but it is never used in the method.

          private MutableBigInteger binaryGCD(MutableBigInteger v) {
              // Algorithm B from Knuth section 4.5.2
              MutableBigInteger u = this;
              MutableBigInteger q = new MutableBigInteger(), // <----- here
                  r = new MutableBigInteger();
              // step B1
              int s1 = u.getLowestSetBit();
              int s2 = v.getLowestSetBit();
              int k = (s1 < s2) ? s1 : s2;
              if (k != 0) {
                  u.rightShift(k);
                  v.rightShift(k);
              }

              // step B2
              boolean uOdd = (k==s1);
              MutableBigInteger t = uOdd ? v: u;
              int tsign = uOdd ? -1 : 1;

              int lb;
              while ((lb = t.getLowestSetBit()) >= 0) {
                  // steps B3 and B4
                  t.rightShift(lb);
                  // step B5
                  if (tsign > 0)
                      u = t;
                  else
                      v = t;

                  // Special case one word numbers
                  if (u.intLen < 2 && v.intLen < 2) {
                      int x = u.value[u.offset];
                      int y = v.value[v.offset];
                      x = binaryGcd(x, y);
                      r.value[0] = x;
                      r.intLen = 1;
                      r.offset = 0;
                      if (k > 0)
                          r.leftShift(k);
                      return r;
                  }
            
                  // step B6
                  if ((tsign = u.difference(v)) == 0)
                      break;
                  t = (tsign >= 0) ? u : v;
              }

              if (k > 0)
                  u.leftShift(k);
              return u;
          }

      The binaryGCD method is launched by the hybridGCD method, the hybridGCD method is launched by the BigInteger's public gcd method. By removing q in the snippet above, we can save both memory (the object itself) and execution time (the constructor), so the public BigInteger gcd(BigInteger val) can benefit from a fix.

      ###@###.### 2005-1-31 10:13:08 GMT

      Attachments

        Activity

          People

            darcy Joe Darcy
            jloefflm Johann Löfflmann (Inactive)
            Votes:
            0 Vote for this issue
            Watchers:
            0 Start watching this issue

            Dates

              Created:
              Updated:
              Resolved:
              Imported:
              Indexed: