Reduce usage of the arrayByteLength
helper function
We're using this helper function when reading data from the [`PDFWorkerStreamReader.read`](a49d1d1615/src/core/worker_stream.js (L90-L98)
) and [`PDFWorkerStreamRangeReader.read`](a49d1d1615/src/core/worker_stream.js (L122-L128)
) methods, and as can be seen they always return `ArrayBuffer` data. Hence we can simply get the `byteLength` directly, and don't need to use the helper function. Note that at the time when `arrayByteLength` was added we still supported browsers without TypedArray functionality, and we'd then simulate them using regular Arrays.
This commit is contained in:
parent
323d3d246a
commit
96d338e437
@ -14,8 +14,8 @@
|
|||||||
*/
|
*/
|
||||||
|
|
||||||
import {
|
import {
|
||||||
arrayByteLength,
|
|
||||||
arraysToBytes,
|
arraysToBytes,
|
||||||
|
assert,
|
||||||
createPromiseCapability,
|
createPromiseCapability,
|
||||||
} from "../shared/util.js";
|
} from "../shared/util.js";
|
||||||
import { MissingDataException } from "./core_utils.js";
|
import { MissingDataException } from "./core_utils.js";
|
||||||
@ -299,12 +299,22 @@ class ChunkedStreamManager {
|
|||||||
resolve(chunkData);
|
resolve(chunkData);
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
if (
|
||||||
|
typeof PDFJSDev === "undefined" ||
|
||||||
|
PDFJSDev.test("!PRODUCTION || TESTING")
|
||||||
|
) {
|
||||||
|
assert(
|
||||||
|
value instanceof ArrayBuffer,
|
||||||
|
"readChunk (sendRequest) - expected an ArrayBuffer."
|
||||||
|
);
|
||||||
|
}
|
||||||
|
loaded += value.byteLength;
|
||||||
|
|
||||||
chunks.push(value);
|
|
||||||
loaded += arrayByteLength(value);
|
|
||||||
if (rangeReader.isStreamingSupported) {
|
if (rangeReader.isStreamingSupported) {
|
||||||
this.onProgress({ loaded });
|
this.onProgress({ loaded });
|
||||||
}
|
}
|
||||||
|
|
||||||
|
chunks.push(value);
|
||||||
rangeReader.read().then(readChunk, reject);
|
rangeReader.read().then(readChunk, reject);
|
||||||
} catch (e) {
|
} catch (e) {
|
||||||
reject(e);
|
reject(e);
|
||||||
|
@ -15,8 +15,8 @@
|
|||||||
|
|
||||||
import {
|
import {
|
||||||
AbortException,
|
AbortException,
|
||||||
arrayByteLength,
|
|
||||||
arraysToBytes,
|
arraysToBytes,
|
||||||
|
assert,
|
||||||
createPromiseCapability,
|
createPromiseCapability,
|
||||||
getVerbosityLevel,
|
getVerbosityLevel,
|
||||||
info,
|
info,
|
||||||
@ -314,8 +314,17 @@ class WorkerMessageHandler {
|
|||||||
cancelXHRs = null;
|
cancelXHRs = null;
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
if (
|
||||||
|
typeof PDFJSDev === "undefined" ||
|
||||||
|
PDFJSDev.test("!PRODUCTION || TESTING")
|
||||||
|
) {
|
||||||
|
assert(
|
||||||
|
value instanceof ArrayBuffer,
|
||||||
|
"readChunk (getPdfManager) - expected an ArrayBuffer."
|
||||||
|
);
|
||||||
|
}
|
||||||
|
loaded += value.byteLength;
|
||||||
|
|
||||||
loaded += arrayByteLength(value);
|
|
||||||
if (!fullRequest.isStreamingSupported) {
|
if (!fullRequest.isStreamingSupported) {
|
||||||
handler.send("DocProgress", {
|
handler.send("DocProgress", {
|
||||||
loaded,
|
loaded,
|
||||||
@ -328,7 +337,6 @@ class WorkerMessageHandler {
|
|||||||
} else {
|
} else {
|
||||||
cachedChunks.push(value);
|
cachedChunks.push(value);
|
||||||
}
|
}
|
||||||
|
|
||||||
fullRequest.read().then(readChunk, reject);
|
fullRequest.read().then(readChunk, reject);
|
||||||
} catch (e) {
|
} catch (e) {
|
||||||
reject(e);
|
reject(e);
|
||||||
|
@ -1115,7 +1115,6 @@ export {
|
|||||||
AnnotationReviewState,
|
AnnotationReviewState,
|
||||||
AnnotationStateModelType,
|
AnnotationStateModelType,
|
||||||
AnnotationType,
|
AnnotationType,
|
||||||
arrayByteLength,
|
|
||||||
arraysToBytes,
|
arraysToBytes,
|
||||||
assert,
|
assert,
|
||||||
BaseException,
|
BaseException,
|
||||||
|
Loading…
x
Reference in New Issue
Block a user