mmp / pbrt-v4

Source code to pbrt, the ray tracer described in the forthcoming 4th edition of the "Physically Based Rendering: From Theory to Implementation" book.
https://pbrt.org
Apache License 2.0
2.8k stars 429 forks source link

Optimize operator[] of vectors by converting it from if-else series to array access #341

Closed MoamenAbdelsattar closed 1 year ago

mmp commented 1 year ago

In C++, it's actually not allowed to read a different union member than the one that was last written to; while this may work in practice, it's in fact disallowed. (And that's in part why the current implementation is the way it is.)

Some discussion here: https://stackoverflow.com/a/11996970.

MoamenAbdelsattar commented 1 year ago

Thank you for explanation!