Move StatTimer
from src/shared/util.js
to src/display/dom_utils.js
Since the `StatTimer` is not used in the worker, duplicating this code on both the main and worker sides seem completely unnecessary.
This commit is contained in:
parent
f299473697
commit
6b1eda3e12
@ -15,15 +15,14 @@
|
||||
/* globals requirejs, __non_webpack_require__ */
|
||||
|
||||
import {
|
||||
assert, createPromiseCapability, getVerbosityLevel, info,
|
||||
InvalidPDFException, isArrayBuffer, isSameOrigin, loadJpegStream,
|
||||
MessageHandler, MissingPDFException, NativeImageDecoding, PageViewport,
|
||||
PasswordException, StatTimer, stringToBytes, UnexpectedResponseException,
|
||||
UnknownErrorException, Util, warn
|
||||
assert, createPromiseCapability, getVerbosityLevel, info, InvalidPDFException,
|
||||
isArrayBuffer, isSameOrigin, loadJpegStream, MessageHandler,
|
||||
MissingPDFException, NativeImageDecoding, PageViewport, PasswordException,
|
||||
stringToBytes, UnexpectedResponseException, UnknownErrorException, Util, warn
|
||||
} from '../shared/util';
|
||||
import {
|
||||
DOMCanvasFactory, DOMCMapReaderFactory, getDefaultSetting,
|
||||
RenderingCancelledException
|
||||
RenderingCancelledException, StatTimer
|
||||
} from './dom_utils';
|
||||
import { FontFaceObject, FontLoader } from './font_loader';
|
||||
import { CanvasGraphics } from './canvas';
|
||||
|
@ -461,6 +461,66 @@ function isExternalLinkTargetSet() {
|
||||
}
|
||||
}
|
||||
|
||||
var StatTimer = (function StatTimerClosure() {
|
||||
function rpad(str, pad, length) {
|
||||
while (str.length < length) {
|
||||
str += pad;
|
||||
}
|
||||
return str;
|
||||
}
|
||||
function StatTimer() {
|
||||
this.started = Object.create(null);
|
||||
this.times = [];
|
||||
this.enabled = true;
|
||||
}
|
||||
StatTimer.prototype = {
|
||||
time: function StatTimer_time(name) {
|
||||
if (!this.enabled) {
|
||||
return;
|
||||
}
|
||||
if (name in this.started) {
|
||||
warn('Timer is already running for ' + name);
|
||||
}
|
||||
this.started[name] = Date.now();
|
||||
},
|
||||
timeEnd: function StatTimer_timeEnd(name) {
|
||||
if (!this.enabled) {
|
||||
return;
|
||||
}
|
||||
if (!(name in this.started)) {
|
||||
warn('Timer has not been started for ' + name);
|
||||
}
|
||||
this.times.push({
|
||||
'name': name,
|
||||
'start': this.started[name],
|
||||
'end': Date.now(),
|
||||
});
|
||||
// Remove timer from started so it can be called again.
|
||||
delete this.started[name];
|
||||
},
|
||||
toString: function StatTimer_toString() {
|
||||
var i, ii;
|
||||
var times = this.times;
|
||||
var out = '';
|
||||
// Find the longest name for padding purposes.
|
||||
var longest = 0;
|
||||
for (i = 0, ii = times.length; i < ii; ++i) {
|
||||
var name = times[i]['name'];
|
||||
if (name.length > longest) {
|
||||
longest = name.length;
|
||||
}
|
||||
}
|
||||
for (i = 0, ii = times.length; i < ii; ++i) {
|
||||
var span = times[i];
|
||||
var duration = span.end - span.start;
|
||||
out += rpad(span['name'], ' ', longest) + ' ' + duration + 'ms\n';
|
||||
}
|
||||
return out;
|
||||
},
|
||||
};
|
||||
return StatTimer;
|
||||
})();
|
||||
|
||||
export {
|
||||
CustomStyle,
|
||||
RenderingCancelledException,
|
||||
@ -474,4 +534,5 @@ export {
|
||||
DOMCMapReaderFactory,
|
||||
DOMSVGFactory,
|
||||
SimpleXMLParser,
|
||||
StatTimer,
|
||||
};
|
||||
|
@ -73,4 +73,4 @@ exports.RenderingCancelledException =
|
||||
pdfjsDisplayDOMUtils.RenderingCancelledException;
|
||||
exports.getFilenameFromUrl = pdfjsDisplayDOMUtils.getFilenameFromUrl;
|
||||
exports.addLinkAttributes = pdfjsDisplayDOMUtils.addLinkAttributes;
|
||||
exports.StatTimer = pdfjsSharedUtil.StatTimer;
|
||||
exports.StatTimer = pdfjsDisplayDOMUtils.StatTimer;
|
||||
|
@ -1118,66 +1118,6 @@ function createPromiseCapability() {
|
||||
return capability;
|
||||
}
|
||||
|
||||
var StatTimer = (function StatTimerClosure() {
|
||||
function rpad(str, pad, length) {
|
||||
while (str.length < length) {
|
||||
str += pad;
|
||||
}
|
||||
return str;
|
||||
}
|
||||
function StatTimer() {
|
||||
this.started = Object.create(null);
|
||||
this.times = [];
|
||||
this.enabled = true;
|
||||
}
|
||||
StatTimer.prototype = {
|
||||
time: function StatTimer_time(name) {
|
||||
if (!this.enabled) {
|
||||
return;
|
||||
}
|
||||
if (name in this.started) {
|
||||
warn('Timer is already running for ' + name);
|
||||
}
|
||||
this.started[name] = Date.now();
|
||||
},
|
||||
timeEnd: function StatTimer_timeEnd(name) {
|
||||
if (!this.enabled) {
|
||||
return;
|
||||
}
|
||||
if (!(name in this.started)) {
|
||||
warn('Timer has not been started for ' + name);
|
||||
}
|
||||
this.times.push({
|
||||
'name': name,
|
||||
'start': this.started[name],
|
||||
'end': Date.now(),
|
||||
});
|
||||
// Remove timer from started so it can be called again.
|
||||
delete this.started[name];
|
||||
},
|
||||
toString: function StatTimer_toString() {
|
||||
var i, ii;
|
||||
var times = this.times;
|
||||
var out = '';
|
||||
// Find the longest name for padding purposes.
|
||||
var longest = 0;
|
||||
for (i = 0, ii = times.length; i < ii; ++i) {
|
||||
var name = times[i]['name'];
|
||||
if (name.length > longest) {
|
||||
longest = name.length;
|
||||
}
|
||||
}
|
||||
for (i = 0, ii = times.length; i < ii; ++i) {
|
||||
var span = times[i];
|
||||
var duration = span.end - span.start;
|
||||
out += rpad(span['name'], ' ', longest) + ' ' + duration + 'ms\n';
|
||||
}
|
||||
return out;
|
||||
},
|
||||
};
|
||||
return StatTimer;
|
||||
})();
|
||||
|
||||
var createBlob = function createBlob(data, contentType) {
|
||||
if (typeof Blob !== 'undefined') {
|
||||
return new Blob([data], { type: contentType, });
|
||||
@ -1668,7 +1608,6 @@ export {
|
||||
PageViewport,
|
||||
PasswordException,
|
||||
PasswordResponses,
|
||||
StatTimer,
|
||||
StreamType,
|
||||
TextRenderingMode,
|
||||
UnexpectedResponseException,
|
||||
|
Loading…
Reference in New Issue
Block a user