Skip to content

Commit

Permalink
refactor: using &str directly instead of S: Borrow<str>.
Browse files Browse the repository at this point in the history
  • Loading branch information
filippodebortoli committed Jun 20, 2024
1 parent cbaeed6 commit e987107
Show file tree
Hide file tree
Showing 11 changed files with 75 additions and 97 deletions.
20 changes: 10 additions & 10 deletions benches/horned.rs
Original file line number Diff line number Diff line change
Expand Up @@ -12,8 +12,8 @@ fn a_thousand_classes(bench: &mut Bencher) {
let b = Build::new_rc();
let mut o = SetOntology::new();
for m in 1..1000 {
let i = b.iri(format!("http://example.com/b{}", m));
let _c = o.declare(b.class(i));
let i = b.iri(&format!("http://example.com/b{}", m));
let _c = o.declare(b.class(&i));
}
})
}
Expand All @@ -28,8 +28,8 @@ fn big_tree(bench: &mut Bencher) {
}

fn create_tree<A: ForIRI, O: MutableOntology<A>>(b: &Build<A>, o: &mut O, n: &mut i32) {
let i = b.iri(format!("http://example.com/a{}", n));
let c = b.class(i);
let i = b.iri(&format!("http://example.com/a{}", n));
let c = b.class(&i);
create_tree_0(b, o, vec![c], n);
}

Expand All @@ -42,11 +42,11 @@ fn create_tree_0<A: ForIRI, O: MutableOntology<A>>(
let mut next = vec![];

for curr in current.into_iter() {
let i = b.iri(format!("http://example.com/a{}", remaining));
let c = b.class(i);
let i = b.iri(&format!("http://example.com/a{}", remaining));
let c = b.class(&i);
*remaining -= 1;
let i = b.iri(format!("http://example.com/a{}", remaining));
let d = b.class(i);
let i = b.iri(&format!("http://example.com/a{}", remaining));
let d = b.class(&i);
*remaining -= 1;

next.push(c.clone());
Expand Down Expand Up @@ -191,8 +191,8 @@ fn food_to_vec() -> Vec<u8> {
std::fs::read("./benches/ont/food.owl").unwrap()
}

fn read_vec<A: ForIRI, AA: ForIndex<A>>(v: &Vec<u8>, b: Build<A>) -> RDFOntology<A, AA> {
let mut c = Cursor::new(v.clone());
fn read_vec<A: ForIRI, AA: ForIndex<A>>(v: &[u8], b: Build<A>) -> RDFOntology<A, AA> {
let mut c = Cursor::new(v);
horned_owl::io::rdf::reader::read_with_build(&mut c, &b, Default::default())
.unwrap()
.0
Expand Down
2 changes: 1 addition & 1 deletion horned-bin/src/bin/horned_big.rs
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,7 @@ pub(crate) fn matcher(matches: &ArgMatches) -> Result<(), HornedError> {
});

for i in 1..size + 1 {
o.declare(b.class(format!("https://www.example.com/o{}", i)));
o.declare(b.class(&format!("https://www.example.com/o{}", i)));
}

let amo: RcComponentMappedOntology = o.into();
Expand Down
6 changes: 3 additions & 3 deletions src/io/ofn/reader/from_pair.rs
Original file line number Diff line number Diff line change
Expand Up @@ -605,7 +605,7 @@ macro_rules! impl_ce_data_cardinality {
Some(pair) => DataRange::from_pair(pair, $ctx)?,
// No data range is equivalent to `rdfs:Literal` as a data range.
// see https://www.w3.org/TR/owl2-syntax/#Data_Property_Cardinality_Restrictions
None => Datatype($ctx.build.iri(OWL2Datatype::Literal)).into(),
None => Datatype($ctx.build.iri(&OWL2Datatype::Literal)).into(),
};
Ok(ClassExpression::$dt { n, dp, dr })
}};
Expand All @@ -620,7 +620,7 @@ macro_rules! impl_ce_obj_cardinality {
Some(x) => Self::from_pair(x, $ctx).map(Box::new)?,
// Missing class expression is equivalent to `owl:Thing` as class expression.
// see https://www.w3.org/TR/owl2-syntax/#Object_Property_Cardinality_Restrictions
None => Box::new(ClassExpression::Class(Class($ctx.build.iri(OWL::Thing)))),
None => Box::new(ClassExpression::Class(Class($ctx.build.iri(&OWL::Thing)))),
};
Ok(ClassExpression::$card { n, ope, bce })
}};
Expand Down Expand Up @@ -858,7 +858,7 @@ impl<A: ForIRI> FromPair<A> for IRI<A> {
local.as_str(),
);
match ctx.mapping.expand_curie(&curie) {
Ok(s) => Ok(ctx.build.iri(s)),
Ok(s) => Ok(ctx.build.iri(&s)),
Err(curie::ExpansionError::Invalid) => {
Err(HornedError::invalid_at("undefined prefix", span))
}
Expand Down
6 changes: 3 additions & 3 deletions src/io/owx/reader.rs
Original file line number Diff line number Diff line change
Expand Up @@ -218,7 +218,7 @@ fn get_iri_value_for<A: ForIRI, R: BufRead>(
// Into an iri
r.build.iri(
// or a curie
x,
&x,
)
}),
)
Expand Down Expand Up @@ -926,7 +926,7 @@ impl<A: ForIRI> FromStart<A> for AnonymousIndividual<A> {
e: &BytesStart,
) -> Result<AnonymousIndividual<A>, HornedError> {
let ai: AnonymousIndividual<_> = r.build.anon(
get_attr_value_str(&mut r.reader, e, b"nodeID")?
&get_attr_value_str(&mut r.reader, e, b"nodeID")?
.ok_or_else(|| error_missing_attribute("nodeID Expected", r))?,
);
Ok(ai)
Expand Down Expand Up @@ -1337,7 +1337,7 @@ from_xml! {IRI, r, end,
match e {
(ref _ns,Event::Text(ref e)) => {
iri = Some(r.build.iri
(decode_expand_curie_maybe(r, e)?));
(&decode_expand_curie_maybe(r, e)?));
},
(ref ns, Event::End(ref e))
if is_owl_name(ns, e, end) =>
Expand Down
2 changes: 1 addition & 1 deletion src/io/owx/writer.rs
Original file line number Diff line number Diff line change
Expand Up @@ -998,7 +998,7 @@ mod test {
let mut ont = ComponentMappedOntology::new_rc();
let build = Build::new();

let iri = build.iri("http://www.example.com/a".to_string());
let iri = build.iri("http://www.example.com/a");
ont.insert(OntologyID {
iri: Some(iri.clone()),
viri: None,
Expand Down
12 changes: 6 additions & 6 deletions src/io/rdf/reader.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1211,15 +1211,15 @@ impl<'a, A: ForIRI, AA: ForIndex<A>> OntologyParser<'a, A, AA> {
{
n:self.fetch_u32(literal)?,
ope,
bce: self.b.class(VOWL::Thing).into()
bce: self.b.class(&VOWL::Thing).into()
}
},
PropertyExpression::DataProperty(dp) => {
ClassExpression::DataExactCardinality
{
n:self.fetch_u32(literal)?,
dp,
dr: self.b.datatype(OWL2Datatype::Literal).into(),
dr: self.b.datatype(&OWL2Datatype::Literal).into(),
}
}
_ => {
Expand Down Expand Up @@ -1251,7 +1251,7 @@ impl<'a, A: ForIRI, AA: ForIndex<A>> OntologyParser<'a, A, AA> {
{
n:self.fetch_u32(literal)?,
ope: pr.into(),
bce: self.b.class(VOWL::Thing).into()
bce: self.b.class(&VOWL::Thing).into()
}
}
}
Expand All @@ -1278,7 +1278,7 @@ impl<'a, A: ForIRI, AA: ForIndex<A>> OntologyParser<'a, A, AA> {
{
n:self.fetch_u32(literal)?,
ope: pr.into(),
bce: self.b.class(VOWL::Thing).into()
bce: self.b.class(&VOWL::Thing).into()
}
}
}
Expand Down Expand Up @@ -1852,7 +1852,7 @@ impl<'a, A: ForIRI, AA: ForIndex<A>> OntologyParser<'a, A, AA> {
[Term::Iri(iri), Term::Iri(ap), _]
if parse_all
|| (self.o.0).j().is_annotation_property(ap)
|| is_annotation_builtin(ap.as_ref()) =>
|| is_annotation_builtin(ap) =>
{
firi(self, &triple.0, iri)
}
Expand All @@ -1864,7 +1864,7 @@ impl<'a, A: ForIRI, AA: ForIndex<A>> OntologyParser<'a, A, AA> {
for (k, v) in std::mem::take(&mut self.bnode) {
let fbnode = |s: &mut OntologyParser<_, _>, t, ind: &BNode<A>| {
let ann = s.ann_map.remove(t).unwrap_or_default();
let ind: AnonymousIndividual<A> = s.b.anon(ind.0.clone());
let ind: AnonymousIndividual<A> = s.b.anon(&ind.0);
s.merge(AnnotatedComponent {
component: AnnotationAssertion {
subject: ind.into(),
Expand Down
4 changes: 2 additions & 2 deletions src/io/rdf/writer.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1783,7 +1783,7 @@ mod test {
let mut ont = ComponentMappedOntology::new_rc();
let build = Build::new();

let iri = build.iri("http://www.example.com/a".to_string());
let iri = build.iri("http://www.example.com/a");
ont.insert(OntologyID {
iri: Some(iri),
viri: None,
Expand Down Expand Up @@ -1841,7 +1841,7 @@ mod test {
#[test_resources("src/ont/owl-rdf/ambiguous/*.owl")]
fn roundtrip_rdf(resource: &str) {
let resource = &slurp::read_all_to_string(resource).unwrap();
assert_round(&resource);
assert_round(resource);
}

#[test]
Expand Down
Loading

0 comments on commit e987107

Please sign in to comment.