Uploaded image for project: 'Commons Math'
  1. Commons Math
  2. MATH-725

use initialized static final arrays, instead of initializing it in constructors

    XMLWordPrintableJSON

Details

    • Improvement
    • Status: Closed
    • Minor
    • Resolution: Incomplete
    • 2.2
    • 3.0
    • None
    • None

    Description

      The Well PRNG's implementations have arrays iRm1, iRm2, iRm3, i1, i2, i3. All these arrays are unmodifiable, so we can replace this arrays initialization block

      final int w = 32;
      final int r = (k + w - 1) / w;
      this.v = new int[r];
      this.index = 0;

      // precompute indirection index tables. These tables are used for optimizing access
      // they allow saving computations like "(j + r - 2) % r" with costly modulo operations
      iRm1 = new int[r];
      iRm2 = new int[r];
      i1 = new int[r];
      i2 = new int[r];
      i3 = new int[r];
      for (int j = 0; j < r; ++j)

      { iRm1[j] = (j + r - 1) % r; iRm2[j] = (j + r - 2) % r; i1[j] = (j + m1) % r; i2[j] = (j + m2) % r; i3[j] = (j + m3) % r; }

      with inline initialized static final arrays.

      This is much better and faster implementation, freed from unnecessary costly calculations (such as %).

      Another solution: leave as is, but make all these arrays static.

      Attachments

        Activity

          People

            Unassigned Unassigned
            filosofem Eldar Agalarov
            Votes:
            0 Vote for this issue
            Watchers:
            0 Start watching this issue

            Dates

              Created:
              Updated:
              Resolved:

              Time Tracking

                Estimated:
                Original Estimate - 1h
                1h
                Remaining:
                Remaining Estimate - 1h
                1h
                Logged:
                Time Spent - Not Specified
                Not Specified