Merge pull request #11118 from Snuffleupagus/FetchBuiltInCMap-sendWithStream
Transfer, rather than copy, CMap data to the worker-thread
This commit is contained in:
commit
37d5b80ba8
@ -78,8 +78,24 @@ var PartialEvaluator = (function PartialEvaluatorClosure() {
|
|||||||
if (this.builtInCMapCache.has(name)) {
|
if (this.builtInCMapCache.has(name)) {
|
||||||
return this.builtInCMapCache.get(name);
|
return this.builtInCMapCache.get(name);
|
||||||
}
|
}
|
||||||
const data = await this.handler.sendWithPromise('FetchBuiltInCMap',
|
const readableStream = this.handler.sendWithStream('FetchBuiltInCMap', {
|
||||||
{ name, });
|
name,
|
||||||
|
});
|
||||||
|
const reader = readableStream.getReader();
|
||||||
|
|
||||||
|
const data = await new Promise(function(resolve, reject) {
|
||||||
|
function pump() {
|
||||||
|
reader.read().then(function({ value, done, }) {
|
||||||
|
if (done) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
resolve(value);
|
||||||
|
pump();
|
||||||
|
}, reject);
|
||||||
|
}
|
||||||
|
pump();
|
||||||
|
});
|
||||||
|
|
||||||
if (data.compressionType !== CMapCompressionType.NONE) {
|
if (data.compressionType !== CMapCompressionType.NONE) {
|
||||||
// Given the size of uncompressed CMaps, only cache compressed ones.
|
// Given the size of uncompressed CMaps, only cache compressed ones.
|
||||||
this.builtInCMapCache.set(name, data);
|
this.builtInCMapCache.set(name, data);
|
||||||
|
@ -2225,11 +2225,26 @@ class WorkerTransport {
|
|||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|
||||||
messageHandler.on('FetchBuiltInCMap', (data) => {
|
messageHandler.on('FetchBuiltInCMap', (data, sink) => {
|
||||||
if (this.destroyed) {
|
if (this.destroyed) {
|
||||||
return Promise.reject(new Error('Worker was destroyed'));
|
sink.error(new Error('Worker was destroyed'));
|
||||||
|
return;
|
||||||
}
|
}
|
||||||
return this.CMapReaderFactory.fetch(data);
|
let fetched = false;
|
||||||
|
|
||||||
|
sink.onPull = () => {
|
||||||
|
if (fetched) {
|
||||||
|
sink.close();
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
fetched = true;
|
||||||
|
|
||||||
|
this.CMapReaderFactory.fetch(data).then(function(builtInCMap) {
|
||||||
|
sink.enqueue(builtInCMap, 1, [builtInCMap.cMapData.buffer]);
|
||||||
|
}).catch(function(reason) {
|
||||||
|
sink.error(reason);
|
||||||
|
});
|
||||||
|
};
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user