Skip to content

Commit

Permalink
Try LinkedHashMap instead of IndexMap
Browse files Browse the repository at this point in the history
  • Loading branch information
cormacrelf committed Oct 29, 2019
1 parent 58c211e commit c324a6e
Show file tree
Hide file tree
Showing 3 changed files with 18 additions and 12 deletions.
8 changes: 7 additions & 1 deletion Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion dpx/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ md-5 = "0.8.0"
sha2 = "0.8.0"
rand = "0.7.2"
chrono = "0.4.9"
indexmap = "1.3.0"
linked-hash-map = "0.5.2"

[features]
default = ['libz-sys']
Expand Down
20 changes: 10 additions & 10 deletions dpx/src/dpx_pdfobj.rs
Original file line number Diff line number Diff line change
Expand Up @@ -222,12 +222,12 @@ pub struct xref_entry {
pub indirect: PdfObjRef,
}

use indexmap::IndexMap;
use linked_hash_map::LinkedHashMap;

#[derive(Clone)]
#[repr(C)]
pub struct PdfDict {
inner: IndexMap<PdfName, PdfObjRef>,
inner: LinkedHashMap<PdfName, PdfObjRef>,
}

impl PdfDict {
Expand Down Expand Up @@ -1186,15 +1186,15 @@ unsafe fn write_dict(dict: &PdfDict, handle: &mut OutputHandleWrapper) {
pub fn pdf_new_dict() -> PdfObjRef {
safe_new_obj(PdfObjType::DICT, |object| {
let boxed = Box::new(PdfDict {
inner: IndexMap::new(),
inner: LinkedHashMap::new(),
});
object.data = Box::into_raw(boxed) as *mut libc::c_void;
})
}

unsafe fn release_dict(mut data: *mut PdfDict) {
let mut boxed = Box::from_raw(data);
for (_k, v) in boxed.inner.drain(..) {
for (_k, &v) in boxed.inner.iter() {
unsafe {
pdf_release_obj(v);
}
Expand Down Expand Up @@ -1228,12 +1228,12 @@ pub unsafe extern "C" fn pdf_merge_dict(dict1: &mut pdf_obj, dict2: &pdf_obj) {
let dict2 = dict2.get_dict();
for (k, &v) in dict2.inner.iter() {
let linked = pdf_link_obj(v);
dict1.inner.entry(k.clone())
.and_modify(|existing| {
let existing = mem::replace(existing, linked);
pdf_release_obj(existing);
})
.or_insert(linked);
if let Some(existing) = dict1.inner.get_mut(k) {
let existing = mem::replace(existing, linked);
pdf_release_obj(existing);
} else {
dict1.inner.insert(k.clone(), linked);
}
}
}

Expand Down

0 comments on commit c324a6e

Please sign in to comment.