Repository: mozilla/pdf.js
File: src/core/pattern.js (JavaScript)

Code before:
    // Use lcm(1,2,3,4,5,6,7,8,10) = 840 (including 9 increases this to 2520)
    // to catch evenly spaced stops. oeis.org/A003418
    const NUMBER_OF_SAMPLES = 840;
    const step = (t1 - t0) / NUMBER_OF_SAMPLES;

    const colorStops = (this.colorStops = []);

    // Protect against bad domains.
    if (t0 >= t1 || step <= 0) {
      // Acrobat doesn't seem to handle these cases so we'll ignore for
      // now.
      info("Bad shading domain.");
      return;
    }

    const color = new Float32Array(cs.numComps),
      ratio = new Float32Array(1);

    let iBase = 0;
    ratio[0] = t0;
    fn(ratio, 0, color, 0);
    const rgbBuffer = new Uint8ClampedArray(3);
    cs.getRgb(color, 0, rgbBuffer);
    let rBase = rgbBuffer[0];
    let gBase = rgbBuffer[1];
    let bBase = rgbBuffer[2];
    colorStops.push([0, Util.makeHexColor(rBase, gBase, bBase)]);

    let iPrev = 1;
    ratio[0] = t0 + step;
    fn(ratio, 0, color, 0);
    cs.getRgb(color, 0, rgbBuffer);
    let rPrev = rgbBuffer[0];
    let gPrev = rgbBuffer[1];
    let bPrev = rgbBuffer[2];

    // Slopes are rise / run.
    // A max slope is from the least value the base component could have been
    // to the greatest value the current component could have been.
    // A min slope is from the greatest value the base component could have been
    // to the least value the current component could have been.
    // Each component could have been rounded up to .5 from its original value
    // so the conservative deltas are +-1 (+-.5 for base and -+.5 for current).

    // The run is iPrev - iBase = 1, so omitted.
    let maxSlopeR = rPrev - rBase + 1;
    let maxSlopeG = gPrev - gBase + 1;
    let maxSlopeB = bPrev - bBase + 1;
    let minSlopeR = rPrev - rBase - 1;
    let minSlopeG = gPrev - gBase - 1;
    let minSlopeB = bPrev - bBase - 1;

Review comment (suggestion):
Nit: Could we shorten this with destructuring?
```suggestion
    let [rBase, gBase, bBase] = rgbBuffer;
```

Code after:
    // Use lcm(1,2,3,4,5,6,7,8,10) = 840 (including 9 increases this to 2520)
    // to catch evenly spaced stops. oeis.org/A003418
    const NUMBER_OF_SAMPLES = 840;
    const step = (t1 - t0) / NUMBER_OF_SAMPLES;

    const colorStops = (this.colorStops = []);

    // Protect against bad domains.
    if (t0 >= t1 || step <= 0) {
      // Acrobat doesn't seem to handle these cases so we'll ignore for
      // now.
      info("Bad shading domain.");
      return;
    }

    const color = new Float32Array(cs.numComps),
      ratio = new Float32Array(1);

    let iBase = 0;
    ratio[0] = t0;
    fn(ratio, 0, color, 0);
    const rgbBuffer = new Uint8ClampedArray(3);
    cs.getRgb(color, 0, rgbBuffer);
    let [rBase, gBase, bBase] = rgbBuffer;
    colorStops.push([0, Util.makeHexColor(rBase, gBase, bBase)]);

    let iPrev = 1;
    ratio[0] = t0 + step;
    fn(ratio, 0, color, 0);
    cs.getRgb(color, 0, rgbBuffer);
    let [rPrev, gPrev, bPrev] = rgbBuffer;

    // Slopes are rise / run.
    // A max slope is from the least value the base component could have been
    // to the greatest value the current component could have been.
    // A min slope is from the greatest value the base component could have been
    // to the least value the current component could have been.
    // Each component could have been rounded up to .5 from its original value
    // so the conservative deltas are +-1 (+-.5 for base and -+.5 for current).

    // The run is iPrev - iBase = 1, so omitted.
    let maxSlopeR = rPrev - rBase + 1;
    let maxSlopeG = gPrev - gBase + 1;
    let maxSlopeB = bPrev - bBase + 1;
    let minSlopeR = rPrev - rBase - 1;
    let minSlopeG = gPrev - gBase - 1;
    let minSlopeB = bPrev - bBase - 1;

    for (let i = 2; i < NUMBER_OF_SAMPLES; i++) {
      ratio[0] = t0 + i * step;
      fn(ratio, 0, color, 0);