Timeline for How can I make code that is both DRY and fast where intermediate values in a calculation may or may not be needed?
Current License: CC BY-SA 4.0
9 events
when toggle format | what | by | license | comment | |
---|---|---|---|---|---|
Sep 15, 2023 at 16:08 | vote | accept | CPlus | ||
Sep 14, 2023 at 3:41 | comment | added | Simon Richter | A compiler that supports constant propagation will very likely generate two copies of that function, making #2 the best option. | |
Sep 13, 2023 at 19:40 | history | edited | Glorfindel | CC BY-SA 4.0 |
edited body
|
Sep 13, 2023 at 17:29 | comment | added | Doc Brown | @user253751: that's why its best to try #1 before #2 and profile in each step. | |
Sep 13, 2023 at 15:46 | history | edited | Doc Brown | CC BY-SA 4.0 |
more careful wording
|
Sep 13, 2023 at 14:48 | comment | added | supercat |
Similar situations where one needs a function that can operate on either of two data structures, but the target platform is horribly inefficient at processing pointer indirection. If a construct like foo.bar takes less than half as much code space as fooPtr->bar , using macros with #include to generate a function which acts on foo and one that acts as bar may yield code which is smaller as well as faster than a single function which accepts a fooPtr argument. While #4 is generally less desirable than the others, there are times where it's the only good approach.
|
|
Sep 13, 2023 at 8:54 | history | edited | Doc Brown | CC BY-SA 4.0 |
added 668 characters in body
|
Sep 13, 2023 at 8:19 | history | edited | Doc Brown | CC BY-SA 4.0 |
added 36 characters in body
|
Sep 13, 2023 at 8:14 | history | answered | Doc Brown | CC BY-SA 4.0 |