Skip to content
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 our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add a ValueOr method to Optional #3767

Merged
merged 1 commit into from
Nov 12, 2020

Conversation

bzbarsky-apple
Copy link
Contributor

This allows easier use of the "the value in the Optional or this
default value I have" pattern.

Problem

The pattern for "the value from the Optional or this default I have` is pretty ugly right now.

Summary of Changes

Add a ValueOr method that encapsulates the pattern.

Fixes #3766

This allows easier use of the "the value in the Optional or this
default value I have" pattern.
@github-actions
Copy link

Size increase report for "esp32-example-build" from eda6980

File Section File VM
chip-all-clusters-app.elf .flash.text -12 -12
Full report output
BLOAT REPORT

Files found only in the build output:
    report.csv

Comparing ./master_artifact/chip-all-clusters-app.elf and ./pull_artifact/chip-all-clusters-app.elf:

sections,vmsize,filesize
.debug_info,0,624
.debug_str,0,192
.xt.prop._ZN4chip8BufBound3PutEPKvj,0,40
.xt.prop._ZN4chip8Encoding12LittleEndian7Write32ERPhj,0,-1
.debug_aranges,0,-8
.debug_loc,0,-8
.debug_ranges,0,-8
.debug_abbrev,0,-12
.flash.text,-12,-12
.debug_frame,0,-24
.xt.lit._ZNK4chip8OptionalIyE5ValueEv,0,-40
.debug_line,0,-67


Copy link
Contributor

@andy31415 andy31415 left a comment

Choose a reason for hiding this comment

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

Code is soo much more readable now.

And somehow 12 bytes less flash. Cool!

@bzbarsky-apple
Copy link
Contributor Author

@saurabhst @BroderickCarlin @jelderton please take a look?

@bzbarsky-apple bzbarsky-apple merged commit 9fcb5d5 into project-chip:master Nov 12, 2020
@bzbarsky-apple bzbarsky-apple deleted the add-value-or branch November 12, 2020 22:38
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Consider adding a ValueOr method to Optional that allows supplying a default
4 participants