Mike Gerwitz

Activist for User Freedom

aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorMike Gerwitz <mike.gerwitz@ryansg.com>2020-03-13 01:19:43 -0400
committerMike Gerwitz <mike.gerwitz@ryansg.com>2020-03-19 15:42:06 -0400
commit3fe3fc4b84608045cc55fc350ede38c9b760ca04 (patch)
tree3c91083d6bff11265551047bc47ff38cd81b26a1 /tamer/src/ld/poc.rs
parent400d5b25a1a0912790f65ceb0fff9f92059e61b9 (diff)
downloadtame-3fe3fc4b84608045cc55fc350ede38c9b760ca04.tar.gz
tame-3fe3fc4b84608045cc55fc350ede38c9b760ca04.tar.bz2
tame-3fe3fc4b84608045cc55fc350ede38c9b760ca04.zip
TAMER: ld/poc: Simplify {get_interner_value=>get_ident}
Diffstat (limited to 'tamer/src/ld/poc.rs')
-rw-r--r--tamer/src/ld/poc.rs44
1 files changed, 17 insertions, 27 deletions
diff --git a/tamer/src/ld/poc.rs b/tamer/src/ld/poc.rs
index 829176a..def7730 100644
--- a/tamer/src/ld/poc.rs
+++ b/tamer/src/ld/poc.rs
@@ -238,18 +238,14 @@ fn load_xmlo<'a, 'i, I: Interner<'i>>(
}
}
-fn get_interner_value<'a, 'i, I: Interner<'i>>(
+fn get_ident<'a, 'i>(
depgraph: &'a LinkerAsg<'i>,
- interner: &'i I,
- name: &str,
-) -> Result<&'a Object<'i>, Box<dyn Error>> {
- match depgraph.lookup(interner.intern(name)) {
- Some(frag) => match depgraph.get(frag) {
- Some(result) => Ok(result),
- None => Err(XmloError::MissingFragment(String::from(name)).into()),
- },
- None => Err(XmloError::MissingFragment(String::from(name)).into()),
- }
+ name: &'i Symbol<'i>,
+) -> Result<&'a Object<'i>, XmloError> {
+ depgraph
+ .lookup(name)
+ .and_then(|id| depgraph.get(id))
+ .ok_or(XmloError::MissingFragment(String::from(name as &str)))
}
fn output_xmle<'a, 'i, I: Interner<'i>>(
@@ -261,28 +257,22 @@ fn output_xmle<'a, 'i, I: Interner<'i>>(
output: &str,
) -> Result<(), Box<dyn Error>> {
if !sorted.map.is_empty() {
- sorted.map.push_head(get_interner_value(
- depgraph,
- interner,
- &String::from(":map:___head"),
- )?);
- sorted.map.push_tail(get_interner_value(
- depgraph,
- interner,
- &String::from(":map:___tail"),
- )?);
+ sorted
+ .map
+ .push_head(get_ident(depgraph, interner.intern(":map:___head"))?);
+ sorted
+ .map
+ .push_tail(get_ident(depgraph, interner.intern(":map:___tail"))?);
}
if !sorted.retmap.is_empty() {
- sorted.retmap.push_head(get_interner_value(
+ sorted.retmap.push_head(get_ident(
depgraph,
- interner,
- &String::from(":retmap:___head"),
+ interner.intern(":retmap:___head"),
)?);
- sorted.retmap.push_tail(get_interner_value(
+ sorted.retmap.push_tail(get_ident(
depgraph,
- interner,
- &String::from(":retmap:___tail"),
+ interner.intern(":retmap:___tail"),
)?);
}