Uploaded image for project: 'Spigot'
  1. Spigot
  2. SPIGOT-1388

NibbleArray - unpredictable branch

XMLWordPrintable

    • Icon: New Feature New Feature
    • Resolution: Fixed
    • Icon: Minor Minor
    • None
    • None

      This removes the unpredictable branch in the NibbleArray. Since those two functions are used pretty often this branch costs pretty much.

      It also reduces method code size to ease inlining.

          public int a(int i) {
              int j = this.c(i);
      
              // Changes start
              int shift = shift(i);
              int aval = this.a[j];
              return (aval >> shift) & 15;
              // Changes end
          }
      
          public void a(int i, int j) {
              int k = this.c(i);
              
              // Changes start
              int shift = shift(i);
              int aval = this.a[k];
              aval &= ~(15<<shift);
              aval |= (j & 15) << shift;
              this.a[k] = (byte) aval; // Note: Using long[] would increase performance even more.
              // Changes end
          }
      
          // Changes start
          private int shift(int i) {
          	return (i & 1) >> 2;
          }
          // Changes end
      

            md_5 md_5
            michaelzangl Michael Zangl
            Votes:
            0 Vote for this issue
            Watchers:
            5 Start watching this issue

              Created:
              Updated:
              Resolved: