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).
This commit is contained in:
Jonas Jenwald 2018-08-16 20:34:45 +02:00
parent ad3e937816
commit 45d6651976

View File

@ -156,11 +156,11 @@ if (typeof PDFJSDev === 'undefined' || !PDFJSDev.test('MOZCENTRAL')) {
FontLoader.prototype.queueLoadingCallback =
function FontLoader_queueLoadingCallback(callback) {
function LoadLoader_completeRequest() {
assert(!request.end, 'completeRequest() cannot be called twice');
request.end = Date.now();
assert(!request.done, 'completeRequest() cannot be called twice.');
request.done = true;
// sending all completed requests in order how they were queued
while (context.requests.length > 0 && context.requests[0].end) {
// Sending all completed requests in order of how they were queued.
while (context.requests.length > 0 && context.requests[0].done) {
var otherRequest = context.requests.shift();
setTimeout(otherRequest.callback, 0);
}
@ -170,9 +170,9 @@ if (typeof PDFJSDev === 'undefined' || !PDFJSDev.test('MOZCENTRAL')) {
var requestId = 'pdfjs-font-loading-' + (context.nextRequestId++);
var request = {
id: requestId,
done: false,
complete: LoadLoader_completeRequest,
callback,
started: Date.now(),
};
context.requests.push(request);
return request;