Skip to content

use default copy constructor and copy assignments for CRGB and CHSV - #990

Merged
kriegsman merged 2 commits into
FastLED:masterfrom
5chmidti:master
Jul 29, 2020
Merged

kriegsman merged 2 commits into
FastLED:masterfrom
5chmidti:master

Conversation

@5chmidti

@5chmidti 5chmidti commented Mar 28, 2020 •

Copy link
Copy Markdown
Contributor

fix for class-memaccess warnings for the CRGB and CHSV structs.
fixes the same warnings as #986 (discussion #985) and #977 (discussion #971)(which are duplicates), except that this removes the warning from all uses that require CRGB and CHSV to be trivially copyable.

As littlebalckfish said

Quote

memmove signature from stdlib is

void * memmove ( void * destination, const void * source, size_t num );

So, casting all the pointers to (void*), I believe, is an appropriate, if not optimal solution to the problem, i.e.

memmove8( &(entries[0]), &(rhs.entries[0]), sizeof( entries));

to

memmove8( (void *) &(entries[0]), (void *) &(rhs.entries[0]), sizeof( entries));

etc.

This builds without complaints. I'd love to do a pull request but I have no way to test this with all the platforms, is there a recommended way to proceed?

the memmove signature takes void * as arguments and the warnings could be avoided by casting to void *, but the warnings could be completely removed for CRGB and CHSV by making both have a trivial copy assignment and a trivial copy constructor. Thus removing warnings when using for example memmove in user code and in the future.

Performance wise this shouldn't make a difference, but please test it. I've done a bit of testing myself and haven't found any real performance difference although I'm not sure how good my tests are.

@5chmidti

5chmidti commented Jul 16, 2020 •

Copy link
Copy Markdown
Contributor Author

I've noticed that I could've made the default constructor trivial.
Also this as a representation of avr assembly. This might have performance improvements after all (looking at avr asm, esp32 asm reordered three instructions but with no difference in used instructions)

@kriegsman
kriegsman merged commit 3a1d880 into FastLED:master Jul 29, 2020
@kriegsman

Copy link
Copy Markdown
Member

Thanks for the help with this, and the code fixes.

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

Successfully merging this pull request may close these issues.

3 participants