Commit bf7c6a80705c2b913b63a84349e030f1d9dc8233
1 parent
e5f504b6
Use SparseOHArray in parsing
Showing
1 changed file
with
17 additions
and
14 deletions
libqpdf/QPDFObjectHandle.cc
| ... | ... | @@ -19,6 +19,7 @@ |
| 19 | 19 | #include <qpdf/BufferInputSource.hh> |
| 20 | 20 | #include <qpdf/QPDFExc.hh> |
| 21 | 21 | #include <qpdf/QPDFPageObjectHelper.hh> |
| 22 | +#include <qpdf/SparseOHArray.hh> | |
| 22 | 23 | |
| 23 | 24 | #include <qpdf/QTC.hh> |
| 24 | 25 | #include <qpdf/QUtil.hh> |
| ... | ... | @@ -1715,8 +1716,8 @@ QPDFObjectHandle::parseInternal(PointerHolder<InputSource> input, |
| 1715 | 1716 | |
| 1716 | 1717 | QPDFObjectHandle object; |
| 1717 | 1718 | |
| 1718 | - std::vector<std::vector<QPDFObjectHandle> > olist_stack; | |
| 1719 | - olist_stack.push_back(std::vector<QPDFObjectHandle>()); | |
| 1719 | + std::vector<SparseOHArray> olist_stack; | |
| 1720 | + olist_stack.push_back(SparseOHArray()); | |
| 1720 | 1721 | std::vector<parser_state_e> state_stack; |
| 1721 | 1722 | state_stack.push_back(st_top); |
| 1722 | 1723 | std::vector<qpdf_offset_t> offset_stack; |
| ... | ... | @@ -1728,7 +1729,7 @@ QPDFObjectHandle::parseInternal(PointerHolder<InputSource> input, |
| 1728 | 1729 | while (! done) |
| 1729 | 1730 | { |
| 1730 | 1731 | bool bad = false; |
| 1731 | - std::vector<QPDFObjectHandle>& olist = olist_stack.back(); | |
| 1732 | + SparseOHArray& olist = olist_stack.back(); | |
| 1732 | 1733 | parser_state_e state = state_stack.back(); |
| 1733 | 1734 | offset = offset_stack.back(); |
| 1734 | 1735 | |
| ... | ... | @@ -1828,7 +1829,7 @@ QPDFObjectHandle::parseInternal(PointerHolder<InputSource> input, |
| 1828 | 1829 | } |
| 1829 | 1830 | else |
| 1830 | 1831 | { |
| 1831 | - olist_stack.push_back(std::vector<QPDFObjectHandle>()); | |
| 1832 | + olist_stack.push_back(SparseOHArray()); | |
| 1832 | 1833 | state = st_start; |
| 1833 | 1834 | offset_stack.push_back(input->tell()); |
| 1834 | 1835 | state_stack.push_back( |
| ... | ... | @@ -1883,8 +1884,8 @@ QPDFObjectHandle::parseInternal(PointerHolder<InputSource> input, |
| 1883 | 1884 | context, |
| 1884 | 1885 | olist.at(olist.size() - 2).getIntValueAsInt(), |
| 1885 | 1886 | olist.at(olist.size() - 1).getIntValueAsInt()); |
| 1886 | - olist.pop_back(); | |
| 1887 | - olist.pop_back(); | |
| 1887 | + olist.remove_last(); | |
| 1888 | + olist.remove_last(); | |
| 1888 | 1889 | } |
| 1889 | 1890 | else if ((value == "endobj") && (state == st_top)) |
| 1890 | 1891 | { |
| ... | ... | @@ -1996,7 +1997,7 @@ QPDFObjectHandle::parseInternal(PointerHolder<InputSource> input, |
| 1996 | 1997 | setObjectDescriptionFromInput( |
| 1997 | 1998 | object, context, object_description, input, |
| 1998 | 1999 | input->getLastOffset()); |
| 1999 | - olist.push_back(object); | |
| 2000 | + olist.append(object); | |
| 2000 | 2001 | break; |
| 2001 | 2002 | |
| 2002 | 2003 | case st_top: |
| ... | ... | @@ -2017,7 +2018,9 @@ QPDFObjectHandle::parseInternal(PointerHolder<InputSource> input, |
| 2017 | 2018 | state_stack.pop_back(); |
| 2018 | 2019 | if (old_state == st_array) |
| 2019 | 2020 | { |
| 2020 | - object = newArray(olist); | |
| 2021 | + // There's no newArray(SparseOHArray) since | |
| 2022 | + // SparseOHArray is not part of the public API. | |
| 2023 | + object = QPDFObjectHandle(new QPDF_Array(olist)); | |
| 2021 | 2024 | setObjectDescriptionFromInput( |
| 2022 | 2025 | object, context, object_description, input, offset); |
| 2023 | 2026 | } |
| ... | ... | @@ -2027,13 +2030,13 @@ QPDFObjectHandle::parseInternal(PointerHolder<InputSource> input, |
| 2027 | 2030 | // Attempt to recover more or less gracefully from |
| 2028 | 2031 | // invalid dictionaries. |
| 2029 | 2032 | std::set<std::string> names; |
| 2030 | - for (std::vector<QPDFObjectHandle>::iterator iter = | |
| 2031 | - olist.begin(); | |
| 2032 | - iter != olist.end(); ++iter) | |
| 2033 | + size_t n_elements = olist.size(); | |
| 2034 | + for (size_t i = 0; i < n_elements; ++i) | |
| 2033 | 2035 | { |
| 2034 | - if ((! (*iter).isIndirect()) && (*iter).isName()) | |
| 2036 | + QPDFObjectHandle oh = olist.at(i); | |
| 2037 | + if ((! oh.isIndirect()) && oh.isName()) | |
| 2035 | 2038 | { |
| 2036 | - names.insert((*iter).getName()); | |
| 2039 | + names.insert(oh.getName()); | |
| 2037 | 2040 | } |
| 2038 | 2041 | } |
| 2039 | 2042 | |
| ... | ... | @@ -2097,7 +2100,7 @@ QPDFObjectHandle::parseInternal(PointerHolder<InputSource> input, |
| 2097 | 2100 | } |
| 2098 | 2101 | else |
| 2099 | 2102 | { |
| 2100 | - olist_stack.back().push_back(object); | |
| 2103 | + olist_stack.back().append(object); | |
| 2101 | 2104 | } |
| 2102 | 2105 | } |
| 2103 | 2106 | } | ... | ... |