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

C++20: use view() instead of str() to avoid a copy, use starts_with #13218

Merged
merged 8 commits into from
May 14, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
{
"type": "prerelease",
"comment": "Use view() instead of str(), starts_with() instead of _Starts_with()",
"packageName": "react-native-windows",
"email": "nate@bracy.dev",
"dependentChangeType": "patch"
}
5 changes: 2 additions & 3 deletions vnext/Microsoft.ReactNative/Utils/LocalBundleReader.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -59,11 +59,10 @@ std::future<std::string> LocalBundleReader::LoadBundleAsync(const std::wstring b
winrt::Windows::Storage::StorageFile file{nullptr};

// Supports "ms-appx://" or "ms-appdata://"
// TODO: Replace call to private string function with C++ 20 `starts_with`
if (bundleUri._Starts_with(L"ms-app")) {
if (bundleUri.starts_with(L"ms-app")) {
winrt::Windows::Foundation::Uri uri(bundleUri);
file = co_await winrt::Windows::Storage::StorageFile::GetFileFromApplicationUriAsync(uri);
} else if (bundleUri._Starts_with(L"resource://")) {
} else if (bundleUri.starts_with(L"resource://")) {
winrt::Windows::Foundation::Uri uri(bundleUri);
co_return GetBundleFromEmbeddedResource(uri);
} else {
Expand Down
3 changes: 1 addition & 2 deletions vnext/Shared/HermesSamplingProfiler.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -54,8 +54,7 @@ IAsyncOperation<winrt::hstring> getTraceFilePath() noexcept {
.count();

os << hermesDataPath.c_str() << L"\\cpu_" << now << L".cpuprofile";
// TODO: Use C++ 20 `os.view()` to avoid a copy
co_return winrt::hstring(os.str());
co_return winrt::hstring(os.view());
}

} // namespace
Expand Down
3 changes: 1 addition & 2 deletions vnext/Shared/OInstance.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -196,8 +196,7 @@ std::unique_ptr<const facebook::react::JSBigString> JsBigStringFromPath(
return facebook::react::FileMappingBigString::fromPath(bundlePath);
#else
std::wstring bundlePath;
// TODO: Replace call to private string function with C++ 20 `starts_with`
if (devSettings->bundleRootPath._Starts_with("resource://")) {
if (devSettings->bundleRootPath.starts_with("resource://")) {
auto uri = winrt::Windows::Foundation::Uri(
winrt::to_hstring(devSettings->bundleRootPath), winrt::to_hstring(jsBundleRelativePath));
bundlePath = uri.ToString();
Expand Down