mirror of
https://github.com/mozilla/pdf.js.git
synced 2025-04-22 16:18:08 +02:00
Add a getRawValues
method, to Dict
instances, to provide an easier way of getting all *raw* values
When the old `Dict.getAll()` method was removed, it was replaced with a `Dict.getKeys()` call and `Dict.get(...)` calls (in a loop). While this pattern obviously makes a lot of sense in many cases, there's some instances where we actually want the *raw* `Dict` values (i.e. `Ref`s where applicable). In those cases, `Dict.getRaw(...)` calls are instead used within the loop. However, by introducing a new `Dict.getRawValues()` method we can reduce the number of (strictly unnecessary) function calls by simply getting the *raw* `Dict` values directly.
This commit is contained in:
parent
6381b5b08f
commit
ea8e432c45
4 changed files with 39 additions and 12 deletions
|
@ -254,8 +254,7 @@ class PartialEvaluator {
|
|||
// First check the current resources for blend modes.
|
||||
var graphicStates = node.get("ExtGState");
|
||||
if (graphicStates instanceof Dict) {
|
||||
for (const key of graphicStates.getKeys()) {
|
||||
let graphicState = graphicStates.getRaw(key);
|
||||
for (let graphicState of graphicStates.getRawValues()) {
|
||||
if (graphicState instanceof Ref) {
|
||||
if (processed.has(graphicState)) {
|
||||
continue; // The ExtGState has already been processed.
|
||||
|
@ -301,8 +300,7 @@ class PartialEvaluator {
|
|||
if (!(xObjects instanceof Dict)) {
|
||||
continue;
|
||||
}
|
||||
for (const key of xObjects.getKeys()) {
|
||||
var xObject = xObjects.getRaw(key);
|
||||
for (let xObject of xObjects.getRawValues()) {
|
||||
if (xObject instanceof Ref) {
|
||||
if (processed.has(xObject)) {
|
||||
// The XObject has already been processed, and by avoiding a
|
||||
|
@ -3078,9 +3076,7 @@ class PartialEvaluator {
|
|||
} else if (isRef(encoding)) {
|
||||
hash.update(encoding.toString());
|
||||
} else if (isDict(encoding)) {
|
||||
var keys = encoding.getKeys();
|
||||
for (var i = 0, ii = keys.length; i < ii; i++) {
|
||||
var entry = encoding.getRaw(keys[i]);
|
||||
for (const entry of encoding.getRawValues()) {
|
||||
if (isName(entry)) {
|
||||
hash.update(entry.name);
|
||||
} else if (isRef(entry)) {
|
||||
|
|
|
@ -2207,16 +2207,13 @@ const ObjectLoader = (function () {
|
|||
function addChildren(node, nodesToVisit) {
|
||||
if (node instanceof Dict || isStream(node)) {
|
||||
const dict = node instanceof Dict ? node : node.dict;
|
||||
const dictKeys = dict.getKeys();
|
||||
for (let i = 0, ii = dictKeys.length; i < ii; i++) {
|
||||
const rawValue = dict.getRaw(dictKeys[i]);
|
||||
for (const rawValue of dict.getRawValues()) {
|
||||
if (mayHaveChildren(rawValue)) {
|
||||
nodesToVisit.push(rawValue);
|
||||
}
|
||||
}
|
||||
} else if (Array.isArray(node)) {
|
||||
for (let i = 0, ii = node.length; i < ii; i++) {
|
||||
const value = node[i];
|
||||
for (const value of node) {
|
||||
if (mayHaveChildren(value)) {
|
||||
nodesToVisit.push(value);
|
||||
}
|
||||
|
|
|
@ -144,6 +144,11 @@ var Dict = (function DictClosure() {
|
|||
return Object.keys(this._map);
|
||||
},
|
||||
|
||||
// no dereferencing
|
||||
getRawValues: function Dict_getRawValues() {
|
||||
return Object.values(this._map);
|
||||
},
|
||||
|
||||
set: function Dict_set(key, value) {
|
||||
if (
|
||||
(typeof PDFJSDev === "undefined" ||
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue