ArduinoCore-API icon indicating copy to clipboard operation
ArduinoCore-API copied to clipboard

Update math macros to avoid computing callable arguments more than once

Open Keating950 opened this issue 4 years ago • 4 comments

This PR updates various math macros to avoid computing callable arguments more than once using the same technique that the max macro currently does. It also replaces them with C++ template functions when __cplusplus is defined. I originally opened this as in the ArduinoCore-avr repo, but was directed here.

❯ ./test-ArduinoCore-API
===============================================================================
All tests passed (527 assertions in 226 test cases)

Keating950 avatar Feb 05 '21 15:02 Keating950

Minimized the diff (I believe) as requested.

Keating950 avatar Feb 17 '21 19:02 Keating950

Codecov Report

Merging #140 (585f67a) into master (2af4a9c) will not change coverage. The diff coverage is n/a.

Impacted file tree graph

@@           Coverage Diff           @@
##           master     #140   +/-   ##
=======================================
  Coverage   96.06%   96.06%           
=======================================
  Files          14       14           
  Lines         839      839           
=======================================
  Hits          806      806           
  Misses         33       33           
Impacted Files Coverage Δ
api/Common.h 100.00% <ø> (ø)

Continue to review full report at Codecov.

Legend - Click here to learn more Δ = absolute <relative> (impact), ø = not affected, ? = missing data Powered by Codecov. Last update 2af4a9c...585f67a. Read the comment docs.

codecov-io avatar Feb 17 '21 19:02 codecov-io

Thanks! It's not exactly as I suggested yet, because:

  • You added indentation to the min/max macros, so, there's still a (IMHO unneeded) diff there. I would remove the indent again so these macros are not changed at all.
  • I also suggested (at least tried to) to move the rest of the functions and macros (constrain until sq) down to where min and max are defined, so they can share a single ifdef __cplusplus block, and are also in a place where you do not need to interrupt the extern "C" block.
  • It seems one of the commits also removes some trailing whitespace in from the two template<class T, class L> lines for the min/max template functions, I'd also either revert that, or put it in a separate commit.

Ideally, you'd also squash all your commits together into a single commit (except maybe for whitespace-only changes, those would better be in separate commits), not sure if you're familiar with merging commits / rewriting history in git?

matthijskooijman avatar Feb 17 '21 21:02 matthijskooijman

CLA assistant check
Thank you for your submission! We really appreciate it. Like many open source projects, we ask that you sign our Contributor License Agreement before we can accept your contribution.
You have signed the CLA already but the status is still pending? Let us recheck it.

CLAassistant avatar Apr 09 '21 13:04 CLAassistant