Skip to content

Commit

Permalink
refactor: improve (de)serialization code, change fields order
Browse files Browse the repository at this point in the history
  • Loading branch information
polydez committed Mar 28, 2024
1 parent 6f16077 commit becafe3
Showing 1 changed file with 3 additions and 6 deletions.
9 changes: 3 additions & 6 deletions assembly/src/ast/imports.rs
Original file line number Diff line number Diff line change
Expand Up @@ -175,12 +175,9 @@ impl Serializable for ModuleImports {
// We don't need to serialize the library names if the library paths already contain the library names,
// which is true in the most cases
self.imports.iter().for_each(|(name, path)| {
path.write_into(target);
let name = match name == path.last() {
true => None,
false => Some(name),
};
let name = (name != path.last()).then_some(name);
name.write_into(target);
path.write_into(target);
});
target.write_u16(self.invoked_procs.len() as u16);
for (proc_id, (proc_name, lib_path)) in self.invoked_procs.iter() {
Expand All @@ -196,8 +193,8 @@ impl Deserializable for ModuleImports {
let mut imports = BTreeMap::<String, LibraryPath>::new();
let num_imports = source.read_u16()?;
for _ in 0..num_imports {
let path = LibraryPath::read_from(source)?;
let name = <Option<String>>::read_from(source)?;
let path = LibraryPath::read_from(source)?;
imports.insert(name.unwrap_or_else(|| path.last().to_string()), path);
}

Expand Down

0 comments on commit becafe3

Please sign in to comment.