Commit 6295da436f77ef0e1016dafbb4172452db65ac0b
1 parent
73023bcb
Remove SparseOHArray::insert
Showing
3 changed files
with
13 additions
and
25 deletions
libqpdf/QPDF_Array.cc
| @@ -246,7 +246,19 @@ QPDF_Array::insert(int at, QPDFObjectHandle const& item) | @@ -246,7 +246,19 @@ QPDF_Array::insert(int at, QPDFObjectHandle const& item) | ||
| 246 | } else { | 246 | } else { |
| 247 | checkOwnership(item); | 247 | checkOwnership(item); |
| 248 | if (sparse) { | 248 | if (sparse) { |
| 249 | - sp_elements.insert(at, item); | 249 | + auto iter = sp_elements.elements.crbegin(); |
| 250 | + while (iter != sp_elements.elements.crend()) { | ||
| 251 | + auto key = (iter++)->first; | ||
| 252 | + if (key >= at) { | ||
| 253 | + auto nh = sp_elements.elements.extract(key); | ||
| 254 | + ++nh.key(); | ||
| 255 | + sp_elements.elements.insert(std::move(nh)); | ||
| 256 | + } else { | ||
| 257 | + break; | ||
| 258 | + } | ||
| 259 | + } | ||
| 260 | + sp_elements.elements[at] = item.getObj(); | ||
| 261 | + ++sp_elements.n_elements; | ||
| 250 | } else { | 262 | } else { |
| 251 | elements.insert(elements.cbegin() + at, item.getObj()); | 263 | elements.insert(elements.cbegin() + at, item.getObj()); |
| 252 | } | 264 | } |
libqpdf/SparseOHArray.cc
| @@ -49,29 +49,6 @@ SparseOHArray::erase(int at) | @@ -49,29 +49,6 @@ SparseOHArray::erase(int at) | ||
| 49 | --n_elements; | 49 | --n_elements; |
| 50 | } | 50 | } |
| 51 | 51 | ||
| 52 | -void | ||
| 53 | -SparseOHArray::insert(int idx, QPDFObjectHandle oh) | ||
| 54 | -{ | ||
| 55 | - if (idx == n_elements) { | ||
| 56 | - // Allow inserting to the last position | ||
| 57 | - append(oh); | ||
| 58 | - } else { | ||
| 59 | - auto iter = elements.crbegin(); | ||
| 60 | - while (iter != elements.crend()) { | ||
| 61 | - auto key = (iter++)->first; | ||
| 62 | - if (key >= idx) { | ||
| 63 | - auto nh = elements.extract(key); | ||
| 64 | - ++nh.key(); | ||
| 65 | - elements.insert(std::move(nh)); | ||
| 66 | - } else { | ||
| 67 | - break; | ||
| 68 | - } | ||
| 69 | - } | ||
| 70 | - elements[idx] = oh.getObj(); | ||
| 71 | - ++n_elements; | ||
| 72 | - } | ||
| 73 | -} | ||
| 74 | - | ||
| 75 | SparseOHArray | 52 | SparseOHArray |
| 76 | SparseOHArray::copy() | 53 | SparseOHArray::copy() |
| 77 | { | 54 | { |
libqpdf/qpdf/SparseOHArray.hh
| @@ -34,7 +34,6 @@ class SparseOHArray | @@ -34,7 +34,6 @@ class SparseOHArray | ||
| 34 | elements[idx] = oh.getObj(); | 34 | elements[idx] = oh.getObj(); |
| 35 | } | 35 | } |
| 36 | void erase(int idx); | 36 | void erase(int idx); |
| 37 | - void insert(int idx, QPDFObjectHandle oh); | ||
| 38 | SparseOHArray copy(); | 37 | SparseOHArray copy(); |
| 39 | void disconnect(); | 38 | void disconnect(); |
| 40 | 39 |