Skip to content

Commit 45d6651

Browse files
committed
Refactor unused Date.now() calls in FontLoader.queueLoadingCallback
The `started` timestamp is completely usused, and the `end` timestamp is currently[1] being used essentially like a boolean value. Hence this code can be simplified to use an actual boolean value instead, which avoids potentially hundreds (or even thousands) of unnecessary `Date.now()` calls. --- [1] Looking briefly at the history of this code, I cannot tell if the timestamps themselves were ever used for anything (except for tracking "boolean" state).
1 parent ad3e937 commit 45d6651

File tree

1 file changed

+5
-5
lines changed

1 file changed

+5
-5
lines changed

src/display/font_loader.js

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -156,11 +156,11 @@ if (typeof PDFJSDev === 'undefined' || !PDFJSDev.test('MOZCENTRAL')) {
156156
FontLoader.prototype.queueLoadingCallback =
157157
function FontLoader_queueLoadingCallback(callback) {
158158
function LoadLoader_completeRequest() {
159-
assert(!request.end, 'completeRequest() cannot be called twice');
160-
request.end = Date.now();
159+
assert(!request.done, 'completeRequest() cannot be called twice.');
160+
request.done = true;
161161

162-
// sending all completed requests in order how they were queued
163-
while (context.requests.length > 0 && context.requests[0].end) {
162+
// Sending all completed requests in order of how they were queued.
163+
while (context.requests.length > 0 && context.requests[0].done) {
164164
var otherRequest = context.requests.shift();
165165
setTimeout(otherRequest.callback, 0);
166166
}
@@ -170,9 +170,9 @@ if (typeof PDFJSDev === 'undefined' || !PDFJSDev.test('MOZCENTRAL')) {
170170
var requestId = 'pdfjs-font-loading-' + (context.nextRequestId++);
171171
var request = {
172172
id: requestId,
173+
done: false,
173174
complete: LoadLoader_completeRequest,
174175
callback,
175-
started: Date.now(),
176176
};
177177
context.requests.push(request);
178178
return request;

0 commit comments

Comments
 (0)