Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Further const correctness / String by reference passing cleanups#6571

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 ourterms of service andprivacy statement. We’ll occasionally send you account related emails.

Already on GitHub?Sign in to your account

Merged
d-a-v merged 4 commits intoesp8266:masterfromdirkmueller:string_cleanups
Oct 31, 2019

Conversation

@dirkmueller
Copy link
Contributor

There are actually several instances where we pass in read-only
parameters as pass-by-value, where in the case of String() that
is inefficient as it involves copy-constructor/temp string creations.

We can avoid that, similarly to single character string concatenations
done via string literals instead of char literals.

This is a continuation of#6569.

earlephilhower and d-a-v reacted with thumbs up emoji
@earlephilhower
Copy link
Collaborator

Most CI fails are due to arduino-builder crapping out, but the PlatformIO tests do show problems that need fixing in the examples to make this patch work.

https://travis-ci.org/esp8266/Arduino/jobs/591524978

https://travis-ci.org/esp8266/Arduino/jobs/591524979

@dirkmueller
Copy link
ContributorAuthor

yep, I am still trying to learn how to replicate what travis is testing locally so that I can fix all of them in one go. for now this is an iterative approach :)

@d-a-v
Copy link
Collaborator

d-a-v commentedSep 30, 2019
edited
Loading

cd tests./run_CI_locally.sh

(edit: submodules are now automatically updated)

@earlephilhowerearlephilhower added this to the2.6.0 milestoneSep 30, 2019
Copy link
Collaborator

@earlephilhowerearlephilhower left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others.Learn more.

Looks good and makes the interfaces more rational for a lot of things involvingString parameters.

Copy link
Collaborator

@devytedevyte left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others.Learn more.

Careful here. I'm all for constness, but we've been bitten before due to differences vs. the Arduino reference, where constness isn't always the best. Specifically, differences in constness vs. the Arduino reference can cause grief for 3rd party lib maintainers.
Please check whether any of the interfaces here are part of the Arduino reference (I didn't look through this whole PR), and if so whether the constness is different. In such cases, if any, I suggest reverting. If there are no such cases, please confirm that and I'll approve.

@dirkmueller
Copy link
ContributorAuthor

@devyte all API changes are in classes where their name starts with ESP8266. I would assume there is no 3rd party incompatibility here. There might be corner cases where ESP8266 code is affected, but I can't imagine this to be a very frequent case (to be honest I don't even know how you would notice String vs const String& other than reduced code footprint and better performance).

@dirkmuellerdirkmuellerforce-pushed thestring_cleanups branch 2 times, most recently from0634f52 to48e9b42CompareOctober 1, 2019 06:39
@d-a-v
Copy link
Collaborator

About CI, you can run mock trivial test locally with

cd tests/hostmake cleanmake  ../../libraries/ESP8266WebServer/examples/FSBrowser/FSBrowser

(fromtests/buildm.sh)

@earlephilhower
Copy link
Collaborator

@devyte, the only changes I see in the externally visible*.h files are:

  • type varname -> const type varname
  • String x -> const String &x

Adding a const to the param seems absolutely safe, as the const flows down into the function but not upwards to the caller, right? A char* can be passed into a fcn requiring a const char * without any concern.

The & operator is a compiler structure hint, and other than passing by ref and not value user code should need no change, either. The compiler will simply emit apush addr instead ofmemcpy onto stack.

Granted, if you have a blob using these libs the 2nd change will cause trouble, but the ESPRESSIF ones do not use our libs, obviously and we've never guaranteed binary ABI compatibility.

@devyte
Copy link
Collaborator

The constness trouble was encountered by@d-a-v and was related to 3rd party libs that are meant to work across cores for diffrent uCs. In the end, he had to roll back.
Example: derive a class from one of these and override a method. In our core it's const, in some other core it's not const => 3rd party lib no longer compiles for both cores and requires extensive (additional) #ifdefing.

Like@dirkmueller said, these have the esp8266 prefix and I suspect the signature changes might be ok, but I don't see any assurance, which means this could be a breaking change.
I'm ok with moving forward, as long as the risk is understood: if a breakage report comes in this will need to be rolled back, and if there is a release in the middle, we'll have to make a new release with the rollback fix.

@earlephilhower
Copy link
Collaborator

Ah, I see. The code as-is is safe, but there might be libs which might subclass them. IIRC,@d-a-v's issue was when he adjusted Arduino Client(?) and other libs which were subclasses of it crapped out.

@devyte
Copy link
Collaborator

On further thought, this is a breaking change any way you look at it, because any user with derived classes that override methods will need updating to add constness. I say target for v3.

@dirkmueller
Copy link
ContributorAuthor

dirkmueller commentedOct 1, 2019
edited
Loading

@d-a-v overrides are only for virtual methods, which most of them are not. are you okay when we remove that change for public/protected virtual methods?

I think the only part that is a change in a virtual function signature is in RequestHandler.h which I think is actually unreleased. I'll double check this part.

@d-a-v
Copy link
Collaborator

My issues were mostly because of inheritance.
I don't think String is inherited by other projects.
That kind of changes is IMHO harmless when the class is used (vs inherited). And useful :)

@dirkmueller
Copy link
ContributorAuthor

sorry, wrong completion, I wanted to talk to@devyte

@d-a-v
Copy link
Collaborator

No harm, I was answering to@earlephilhower two posts earlier 😆
Anyway I don't see any "official" arduino classes in this PR

@devyte
Copy link
Collaborator

@dirkmueller I think so, but I don't want to just drop the rest either. Please split the virtual ones into a separate pr, and I'll target for v3.

@dirkmueller
Copy link
ContributorAuthor

@devyte splitted into#6583

There are actually several instances where we pass in read-onlyparameters as pass-by-value, where in the case of String() thatis inefficient as it involves copy-constructor/temp string creations.We can avoid that, similarly to single character string concatenationsdone via string literals instead of char literals.
@d-a-vd-a-v merged commit8bc5a10 intoesp8266:masterOct 31, 2019
aerlon added a commit to aerlon/Arduino that referenced this pull requestNov 1, 2019
- Avoid single character String concatenations done via String literals instead of char literals, as this is inefficient because of temporary String creations (esp8266#6571).
TD-er pushed a commit to TD-er/Arduino that referenced this pull requestDec 4, 2019
- Avoid single character String concatenations done via String literals instead of char literals, as this is inefficient because of temporary String creations (esp8266#6571).
Sign up for freeto join this conversation on GitHub. Already have an account?Sign in to comment

Reviewers

@earlephilhowerearlephilhowerearlephilhower approved these changes

@devytedevytedevyte approved these changes

Assignees

No one assigned

Projects

None yet

Milestone

2.6.0

Development

Successfully merging this pull request may close these issues.

4 participants

@dirkmueller@earlephilhower@d-a-v@devyte

[8]ページ先頭

©2009-2025 Movatter.jp