Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Inline Sculpting to make transforming zero-cost, always #51

Merged
merged 2 commits into from Apr 23, 2017
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
2 changes: 1 addition & 1 deletion .travis.yml
Expand Up @@ -4,7 +4,7 @@ sudo: false

rust:
- stable
- nightly
- nightly-2017-04-21

cache: cargo

Expand Down
30 changes: 15 additions & 15 deletions benches/labelled.rs
Expand Up @@ -309,21 +309,21 @@ fn big_from_24fields(b: &mut Bencher) {

// Hilariously, uncommenting this out will kill the performance in the above 2 benchmarks

//#[bench]
//fn big_transform_from_25fields(b: &mut Bencher) {
// b.iter(|| {
// let j = BigStruct25FieldsReverse::transform_from(build_big_struct_25fields());
// j
// })
//}
//
//#[bench]
//fn big_from_25fields(b: &mut Bencher) {
// b.iter(|| {
// let j = <BigStruct25FieldsReverse as From<BigStruct25Fields>>::from(build_big_struct_25fields());
// j
// })
//}
#[bench]
fn big_transform_from_25fields(b: &mut Bencher) {
b.iter(|| {
let j = BigStruct25FieldsReverse::transform_from(build_big_struct_25fields());
j
})
}

#[bench]
fn big_from_25fields(b: &mut Bencher) {
b.iter(|| {
let j = <BigStruct25FieldsReverse as From<BigStruct25Fields>>::from(build_big_struct_25fields());
j
})
}



Expand Down
2 changes: 2 additions & 0 deletions core/src/hlist.rs
Expand Up @@ -435,6 +435,7 @@ pub trait Sculptor<Target, Indices> {
impl<Source> Sculptor<HNil, HNil> for Source {
type Remainder = Source;

#[inline(always)]
fn sculpt(self) -> (HNil, Self::Remainder) {
(HNil, self)
}
Expand All @@ -453,6 +454,7 @@ for HCons<SHead, STail>
{
type Remainder = <<HCons<SHead, STail> as Plucker<THead, IndexHead>>::Remainder as Sculptor<TTail, IndexTail>>::Remainder;

#[inline(always)]
fn sculpt(self) -> (HCons<THead, TTail>, Self::Remainder) {
let (p, r): (THead, <HCons<SHead, STail> as Plucker<THead, IndexHead>>::Remainder) =
self.pluck();
Expand Down