Skip to content
This repository has been archived by the owner on Aug 30, 2023. It is now read-only.

Commit

Permalink
Do not write uuid duplicates into the file
Browse files Browse the repository at this point in the history
  • Loading branch information
mitsuhiko committed Mar 21, 2017
1 parent 029884d commit 110a544
Showing 1 changed file with 19 additions and 11 deletions.
30 changes: 19 additions & 11 deletions src/memdb/write.rs
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ use std::mem;
use std::slice;
use std::path::Path;
use std::cell::RefCell;
use std::collections::HashMap;
use std::collections::{HashSet, HashMap};

use uuid::Uuid;
use xz2::write::XzEncoder;
Expand All @@ -32,6 +32,7 @@ struct MemDbBuilder<W> {
object_names_map: HashMap<String, u16>,
object_uuid_mapping: Vec<(String, Uuid)>,
variant_uuids: Vec<IndexedUuid>,
variant_uuids_seen: HashSet<Uuid>,
variants: Vec<Vec<IndexItem>>,
symbol_count: usize,
progress: ProgressIndicator,
Expand Down Expand Up @@ -60,6 +61,7 @@ impl<W: Write + Seek> MemDbBuilder<W> {
object_names_map: HashMap::new(),
object_uuid_mapping: vec![],
variant_uuids: vec![],
variant_uuids_seen: HashSet::new(),
variants: vec![],
symbol_count: 0,
progress: if opts.show_progress_bar {
Expand Down Expand Up @@ -142,15 +144,25 @@ impl<W: Write + Seek> MemDbBuilder<W> {
if let Some(fname) = Path::new(src).file_name().and_then(|x| x.to_str()) {
self.progress.set_message(fname);
}
if variant.uuid().is_some() {
self.write_object_variant(&obj, &variant, src)?;
if let Some(uuid) = variant.uuid() {
self.write_object_variant(&obj, &variant, &uuid, src)?;
}
}
Ok(())
}

pub fn write_object_variant(&mut self, obj: &Object, var: &Variant,
src: &str) -> Result<()> {
fn write_object_variant(&mut self, obj: &Object, var: &Variant,
uuid: &Uuid, src: &str) -> Result<bool> {
self.object_uuid_mapping.push((
format!("{}:{}", src, var.arch()),
*uuid
));

if self.variant_uuids_seen.contains(uuid) {
return Ok(false);
}
self.variant_uuids_seen.insert(*uuid);

let mut symbols = obj.symbols(var.arch())?;
let src_id = self.add_object_name(src);

Expand All @@ -174,14 +186,10 @@ impl<W: Write + Seek> MemDbBuilder<W> {
index.sort_by_key(|item| item.addr());

// register variant and uuid
self.variant_uuids.push(IndexedUuid::new(&var.uuid().unwrap(), self.variants.len()));
self.object_uuid_mapping.push((
format!("{}:{}", src, var.arch()),
var.uuid().unwrap()
));
self.variant_uuids.push(IndexedUuid::new(uuid, self.variants.len()));
self.variants.push(index);

Ok(())
Ok(true)
}

fn make_string_slices(&self, strings: &[String], _try_compress: bool) -> Result<Vec<StoredSlice>> {
Expand Down

0 comments on commit 110a544

Please sign in to comment.