Skip to content

Commit

Permalink
C++20: use view() instead of str() to avoid a copy, use starts_with (m…
Browse files Browse the repository at this point in the history
…icrosoft#13218)

* Change files

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

Signed-off-by: Nathanael Bracy <nate@bracy.dev>

* fix

* Apply changefile modifications from code review

Co-authored-by: Jon Thysell <thysell@gmail.com>

* Revert package.json

Signed-off-by: Nathanael Bracy <nate@bracy.dev>

---------

Signed-off-by: Nathanael Bracy <nate@bracy.dev>
Co-authored-by: Andrew Coates <30809111+acoates-ms@users.noreply.github.com>
Co-authored-by: Jon Thysell <thysell@gmail.com>
  • Loading branch information
3 people committed May 14, 2024
1 parent 1110f54 commit 71335b5
Show file tree
Hide file tree
Showing 4 changed files with 11 additions and 7 deletions.
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

0 comments on commit 71335b5

Please sign in to comment.