Skip to content

[Basic] Ensure empty NullTerminatedStringRef have valid pointer #65263

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

Merged
merged 2 commits into from
Apr 19, 2023

Conversation

rintaro
Copy link
Member

@rintaro rintaro commented Apr 18, 2023

NullterminatedStringRef is meant to be safe for reading data() as a valid C-string.

rdar://108215490

@rintaro
Copy link
Member Author

rintaro commented Apr 18, 2023

@swift-ci Please smoke test

@xedin xedin removed their request for review April 18, 2023 19:18
@rintaro rintaro requested review from bnbarham and DougGregor and removed request for hborla and slavapestov April 18, 2023 19:59
@rintaro rintaro force-pushed the nullterminatedstringref-rdar108215490 branch 3 times, most recently from 538be7f to 21fda4e Compare April 18, 2023 20:16
NullterminatedStringRef is meant to be safe for reading 'data()' as a
valid C-string.

rdar://108215490
@rintaro rintaro force-pushed the nullterminatedstringref-rdar108215490 branch from 21fda4e to 43eabf1 Compare April 18, 2023 20:20
@rintaro
Copy link
Member Author

rintaro commented Apr 18, 2023

@swift-ci Please smoke test

@rintaro rintaro force-pushed the nullterminatedstringref-rdar108215490 branch from 93d4fe4 to 4252148 Compare April 18, 2023 20:56
@rintaro rintaro force-pushed the nullterminatedstringref-rdar108215490 branch from 4252148 to f8de332 Compare April 19, 2023 00:10
Comment on lines 690 to 694
std::string cachedDiscriminator;
auto getDiscriminator = [&]() -> StringRef {
if (!cachedDiscriminator.empty())
return cachedDiscriminator;

LazyValue<std::string> discriminator([&]() -> std::string {
Copy link
Member Author

Choose a reason for hiding this comment

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

Don't we have similar "lazy" value thing in llvm or swiftBasic? 🤔

@rintaro rintaro force-pushed the nullterminatedstringref-rdar108215490 branch from f8de332 to c4a4b58 Compare April 19, 2023 05:02
@rintaro
Copy link
Member Author

rintaro commented Apr 19, 2023

@swift-ci Please smoke test

Saves one memory copy. No need to create a temporary
NullTerminatedStringRef.
@rintaro rintaro force-pushed the nullterminatedstringref-rdar108215490 branch from c4a4b58 to a0eb32e Compare April 19, 2023 17:51
@rintaro
Copy link
Member Author

rintaro commented Apr 19, 2023

@swift-ci Please smoke test

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.

2 participants