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

Code before:

    // When stroking the transform has to be applied to the line width too.
    // So we can only optimize if the transform is an identity.
    if (
      op !== OPS.stroke &&
      op !== OPS.closeStroke &&
      op !== OPS.fillStroke &&
      op !== OPS.eoFillStroke &&
      op !== OPS.closeFillStroke &&
      op !== OPS.closeEOFillStroke
    ) {
      return true;
    }
    const iFirstTransform = context.iCurr - 2;
    const transform = argsArray[iFirstTransform];
    return (
      transform[0] === 1 &&
      transform[1] === 0 &&
      transform[2] === 0 &&
      transform[3] === 1
    );
  },
  () => false,
  function foundSameConstructPathOP(context, i) {
    const fnArray = context.fnArray,
      argsArray = context.argsArray;
    const curr = context.iCurr;
    const iFirstSave = curr - 3;
    const iFirstTransform = curr - 2;
    const iFirstConstructPath = curr - 1;
    const args = argsArray[iFirstConstructPath];
    const transform = argsArray[iFirstTransform];
    const [, [buffer], minMax] = args;

    Util.scaleMinMax(transform, minMax);
    for (let k = 0, kk = buffer.length; k < kk; ) {
      switch (buffer[k++]) {
        case DrawOPS.moveTo:
        case DrawOPS.lineTo:
          Util.applyTransformInPlace(buffer.subarray(k), transform);
          k += 2;
          break;
        case DrawOPS.curveTo:
          Util.applyTransformToBezierInPlace(buffer.subarray(k), transform);
          k += 6;
          break;
      }
    }
    // Replace queue items.
    fnArray.splice(iFirstSave, 4, OPS.constructPath);
    argsArray.splice(iFirstSave, 4, args);

Review comment (suggestion):
Nit:
```suggestion
    const { fnArray, argsArray } = context;
```

Code after:

    // When stroking the transform has to be applied to the line width too.
    // So we can only optimize if the transform is an identity.
    if (
      op !== OPS.stroke &&
      op !== OPS.closeStroke &&
      op !== OPS.fillStroke &&
      op !== OPS.eoFillStroke &&
      op !== OPS.closeFillStroke &&
      op !== OPS.closeEOFillStroke
    ) {
      return true;
    }
    const iFirstTransform = context.iCurr - 2;
    const transform = argsArray[iFirstTransform];
    return (
      transform[0] === 1 &&
      transform[1] === 0 &&
      transform[2] === 0 &&
      transform[3] === 1
    );
  },
  () => false,
  (context, i) => {
    const { fnArray, argsArray } = context;
    const curr = context.iCurr;
    const iFirstSave = curr - 3;
    const iFirstTransform = curr - 2;
    const iFirstConstructPath = curr - 1;
    const args = argsArray[iFirstConstructPath];
    const transform = argsArray[iFirstTransform];
    const [, [buffer], minMax] = args;

    Util.scaleMinMax(transform, minMax);
    for (let k = 0, kk = buffer.length; k < kk; ) {
      switch (buffer[k++]) {
        case DrawOPS.moveTo:
        case DrawOPS.lineTo:
          Util.applyTransformInPlace(buffer.subarray(k), transform);
          k += 2;
          break;
        case DrawOPS.curveTo:
          Util.applyTransformToBezierInPlace(buffer.subarray(k), transform);
          k += 6;
          break;
      }
    }
    // Replace queue items.
    fnArray.splice(iFirstSave, 4, OPS.constructPath);
    argsArray.splice(iFirstSave, 4, args);