Skip to content

Commit

Permalink
Simplify initialization of static class properties in the worker-th…
Browse files Browse the repository at this point in the history
…read

Now that we no longer depend on the old Babel version in SystemJS we can remove the `static get ...` work-arounds used to define constants, which leads to slightly more compact code.
  • Loading branch information
Snuffleupagus committed Apr 22, 2023
1 parent 7869f4c commit 4a6a51a
Show file tree
Hide file tree
Showing 6 changed files with 16 additions and 58 deletions.
12 changes: 3 additions & 9 deletions src/core/evaluator.js
Original file line number Diff line number Diff line change
Expand Up @@ -182,13 +182,9 @@ function incrementCachedImageMaskCount(data) {

// Trying to minimize Date.now() usage and check every 100 time.
class TimeSlotManager {
static get TIME_SLOT_DURATION_MS() {
return shadow(this, "TIME_SLOT_DURATION_MS", 20);
}
static TIME_SLOT_DURATION_MS = 20;

static get CHECK_TIME_EVERY() {
return shadow(this, "CHECK_TIME_EVERY", 100);
}
static CHECK_TIME_EVERY = 100;

constructor() {
this.reset();
Expand Down Expand Up @@ -4838,9 +4834,7 @@ class EvaluatorPreprocessor {
return shadow(this, "opMap", getOPMap());
}

static get MAX_INVALID_PATH_OPS() {
return shadow(this, "MAX_INVALID_PATH_OPS", 10);
}
static MAX_INVALID_PATH_OPS = 10;

constructor(stream, xref, stateManager = new StateManager()) {
// TODO(mduan): pass array of knownCommands rather than this.opMap
Expand Down
4 changes: 1 addition & 3 deletions src/core/function.js
Original file line number Diff line number Diff line change
Expand Up @@ -513,9 +513,7 @@ function isPDFFunction(v) {
}

class PostScriptStack {
static get MAX_STACK_SIZE() {
return shadow(this, "MAX_STACK_SIZE", 100);
}
static MAX_STACK_SIZE = 100;

constructor(initialStack) {
this.stack = initialStack ? Array.from(initialStack) : [];
Expand Down
13 changes: 3 additions & 10 deletions src/core/image_utils.js
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,6 @@
import {
assert,
MAX_IMAGE_SIZE_TO_CACHE,
shadow,
unreachable,
warn,
} from "../shared/util.js";
Expand Down Expand Up @@ -173,17 +172,11 @@ class RegionalImageCache extends BaseLocalCache {
}

class GlobalImageCache {
static get NUM_PAGES_THRESHOLD() {
return shadow(this, "NUM_PAGES_THRESHOLD", 2);
}
static NUM_PAGES_THRESHOLD = 2;

static get MIN_IMAGES_TO_CACHE() {
return shadow(this, "MIN_IMAGES_TO_CACHE", 10);
}
static MIN_IMAGES_TO_CACHE = 10;

static get MAX_BYTE_SIZE() {
return shadow(this, "MAX_BYTE_SIZE", 5 * MAX_IMAGE_SIZE_TO_CACHE);
}
static MAX_BYTE_SIZE = 5 * MAX_IMAGE_SIZE_TO_CACHE;

constructor() {
if (typeof PDFJSDev === "undefined" || PDFJSDev.test("TESTING")) {
Expand Down
16 changes: 3 additions & 13 deletions src/core/operator_list.js
Original file line number Diff line number Diff line change
Expand Up @@ -13,13 +13,7 @@
* limitations under the License.
*/

import {
ImageKind,
OPS,
RenderingIntentFlag,
shadow,
warn,
} from "../shared/util.js";
import { ImageKind, OPS, RenderingIntentFlag, warn } from "../shared/util.js";

function addState(parentState, pattern, checkFn, iterateFn, processFn) {
let state = parentState;
Expand Down Expand Up @@ -586,14 +580,10 @@ class QueueOptimizer extends NullOptimizer {
}

class OperatorList {
static get CHUNK_SIZE() {
return shadow(this, "CHUNK_SIZE", 1000);
}
static CHUNK_SIZE = 1000;

// Close to chunk size.
static get CHUNK_SIZE_ABOUT() {
return shadow(this, "CHUNK_SIZE_ABOUT", this.CHUNK_SIZE - 5);
}
static CHUNK_SIZE_ABOUT = this.CHUNK_SIZE - 5;

constructor(intent = 0, streamSink) {
this._streamSink = streamSink;
Expand Down
17 changes: 4 additions & 13 deletions src/core/pattern.js
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,6 @@ import {
assert,
FormatError,
info,
shadow,
unreachable,
Util,
warn,
Expand Down Expand Up @@ -89,9 +88,7 @@ class Pattern {
class BaseShading {
// A small number to offset the first/last color stops so we can insert ones
// to support extend. Number.MIN_VALUE is too small and breaks the extend.
static get SMALL_NUMBER() {
return shadow(this, "SMALL_NUMBER", 1e-6);
}
static SMALL_NUMBER = 1e-6;

constructor() {
if (this.constructor === BaseShading) {
Expand Down Expand Up @@ -374,18 +371,12 @@ const getB = (function getBClosure() {
})();

class MeshShading extends BaseShading {
static get MIN_SPLIT_PATCH_CHUNKS_AMOUNT() {
return shadow(this, "MIN_SPLIT_PATCH_CHUNKS_AMOUNT", 3);
}
static MIN_SPLIT_PATCH_CHUNKS_AMOUNT = 3;

static get MAX_SPLIT_PATCH_CHUNKS_AMOUNT() {
return shadow(this, "MAX_SPLIT_PATCH_CHUNKS_AMOUNT", 20);
}
static MAX_SPLIT_PATCH_CHUNKS_AMOUNT = 20;

// Count of triangles per entire mesh bounds.
static get TRIANGLE_DENSITY() {
return shadow(this, "TRIANGLE_DENSITY", 20);
}
static TRIANGLE_DENSITY = 20;

constructor(
stream,
Expand Down
12 changes: 2 additions & 10 deletions src/display/pattern_helper.js
Original file line number Diff line number Diff line change
Expand Up @@ -13,13 +13,7 @@
* limitations under the License.
*/

import {
FormatError,
info,
shadow,
unreachable,
Util,
} from "../shared/util.js";
import { FormatError, info, unreachable, Util } from "../shared/util.js";
import { getCurrentTransform } from "./display_utils.js";

const PathType = {
Expand Down Expand Up @@ -462,9 +456,7 @@ const PaintType = {

class TilingPattern {
// 10in @ 300dpi shall be enough.
static get MAX_PATTERN_SIZE() {
return shadow(this, "MAX_PATTERN_SIZE", 3000);
}
static MAX_PATTERN_SIZE = 3000;

constructor(IR, color, ctx, canvasGraphicsFactory, baseTransform) {
this.operatorList = IR[2];
Expand Down

0 comments on commit 4a6a51a

Please sign in to comment.