CNativeW クラスの SetString メソッドに std::wstring_view 型を受け取るものを追加 #1734
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
PR の目的
SetString
メソッドを呼ぶ際に、std::wstring
型のインスタンスのc_str()
メソッドでポインタを引数にして呼びだすと、CNativeW::SetString( const wchar_t* pszData )
の実装でstd::wstring_view
のコンストラクタで文字列の要素数を調べる処理が走ります。文字列の要素数の情報はstd::wstring
型の size や length メソッドで定数時間で取得できるので、それを使う方が効率が良いと思い変更しました。カテゴリ
PR の背景
PR のメリット
.c_str()
の記述が無くせるので記述が短くなります。PR のデメリット (トレードオフとかあれば)
特にないと思います。
仕様・動作説明
PR の影響範囲
テスト内容
テスト1
手順
関連 issue, PR
参考資料
https://cpprefjp.github.io/reference/string/basic_string/length.html
https://cpprefjp.github.io/reference/string_view/basic_string_view.html