Commit 21612165c6c1b49b88786c0232215f2e894254ea

Authored by Jay Berkenbilt
Committed by GitHub
2 parents d3c444a7 d8e078fb

Merge pull request #981 from m-holger/writer

Remove redundant loop in QPDFWriter::prepareFileForWrite
Showing 1 changed file with 15 additions and 19 deletions
libqpdf/QPDFWriter.cc
@@ -2034,29 +2034,25 @@ QPDFWriter::getTrimmedTrailer() @@ -2034,29 +2034,25 @@ QPDFWriter::getTrimmedTrailer()
2034 return trailer; 2034 return trailer;
2035 } 2035 }
2036 2036
  2037 +// Make document extension level information direct as required by the spec.
2037 void 2038 void
2038 QPDFWriter::prepareFileForWrite() 2039 QPDFWriter::prepareFileForWrite()
2039 { 2040 {
2040 - // Make document extension level information direct as required by the spec.  
2041 -  
2042 m->pdf.fixDanglingReferences(); 2041 m->pdf.fixDanglingReferences();
2043 - QPDFObjectHandle root = m->pdf.getRoot();  
2044 - for (auto const& key: root.getKeys()) {  
2045 - QPDFObjectHandle oh = root.getKey(key);  
2046 - if ((key == "/Extensions") && (oh.isDictionary())) {  
2047 - bool extensions_indirect = false;  
2048 - if (oh.isIndirect()) {  
2049 - QTC::TC("qpdf", "QPDFWriter make Extensions direct");  
2050 - extensions_indirect = true;  
2051 - oh = root.replaceKeyAndGetNew(key, oh.shallowCopy());  
2052 - }  
2053 - if (oh.hasKey("/ADBE")) {  
2054 - QPDFObjectHandle adbe = oh.getKey("/ADBE");  
2055 - if (adbe.isIndirect()) {  
2056 - QTC::TC("qpdf", "QPDFWriter make ADBE direct", extensions_indirect ? 0 : 1);  
2057 - adbe.makeDirect();  
2058 - oh.replaceKey("/ADBE", adbe);  
2059 - } 2042 + auto root = m->pdf.getRoot();
  2043 + auto oh = root.getKey("/Extensions");
  2044 + if (oh.isDictionary()) {
  2045 + const bool extensions_indirect = oh.isIndirect();
  2046 + if (extensions_indirect) {
  2047 + QTC::TC("qpdf", "QPDFWriter make Extensions direct");
  2048 + oh = root.replaceKeyAndGetNew("/Extensions", oh.shallowCopy());
  2049 + }
  2050 + if (oh.hasKey("/ADBE")) {
  2051 + auto adbe = oh.getKey("/ADBE");
  2052 + if (adbe.isIndirect()) {
  2053 + QTC::TC("qpdf", "QPDFWriter make ADBE direct", extensions_indirect ? 0 : 1);
  2054 + adbe.makeDirect();
  2055 + oh.replaceKey("/ADBE", adbe);
2060 } 2056 }
2061 } 2057 }
2062 } 2058 }