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

"Outline" generic methods #193

Open
Ogeon opened this issue Dec 13, 2020 · 0 comments
Open

"Outline" generic methods #193

Ogeon opened this issue Dec 13, 2020 · 0 comments

Comments

@Ogeon
Copy link
Owner

Ogeon commented Dec 13, 2020

This is mostly relevant for conversion methods that are larger than a handful of lines. It should be possible to help the compiler de-duplicate a lot of code where the same methods are used with different type parameters. Parameters such as white point or RGB standard don't affect the code more than changing a few constants, so they should be possible to "outline" as a function that is only generic over the component type:

impl<Wp: WhitePoint, T: FloatComponent> SomeType<Wp, T> {
    fn made_up_function<Wp: WhitePoint>(&self) -> Self {
        fn inner<T: FloatComponent>(a: T, b: T, c: T, white_point: (T, T, T)) -> (T, T, T) {
            // Complicated stuff...
        }

        let white_point = Wp::get_xyz().into_components();
        inner(self.a, self.b, self.c, white_point)
    }
}

This avoids generating nearly identical copies for each white point that is used. The exact way of passing the data around is up to what works best for the situation.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant