-
Notifications
You must be signed in to change notification settings - Fork 179
auto_ 系の関数を使う必要が無いところで使わないように変更 #1040
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
Conversation
|
✅ Build sakura 1.0.2234 completed (commit 106f9d046d by @) |
sakura_core/CGrepAgent.cpp
Outdated
| const int nPathLen = wcslen( pszPath ); | ||
| auto szPath = std::make_unique<WCHAR[]>(nPathLen + 1); | ||
| auto szTmp = std::make_unique<WCHAR[]>(nPathLen + 1); | ||
| auto_strcpy( &szPath[0], pszPath ); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
文字列長を取得して、メモリ確保して、メモリコピーしてますね。
std::wstring使ったらいいような気がしないでもないです。
| X / X : (H)FullPath | ||
| */ | ||
| auto pszWork = std::make_unique<wchar_t[]>(auto_strlen(pszFullPath) + auto_strlen(pszCodeName) + 10); | ||
| auto pszWork = std::make_unique<wchar_t[]>(wcslen(pszFullPath) + wcslen(pszCodeName) + 10); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
この10ってなんでしたっけ?
というのをどっかで確認したいです。
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
使われている書式文字列的にはそこまで要らないとは思いますが余裕を持って + 10 してるんでしょうね。
sakura_core/dlg/CDlgFavorite.cpp
Outdated
| size_t nLen = wcslen(pRecent->GetItemText(i)); | ||
| std::vector<WCHAR> vecPath(nLen + 2); | ||
| WCHAR* szPath = &vecPath[0]; | ||
| auto_strcpy( szPath, pRecent->GetItemText(i) ); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
ここも std::wstring 使ったほうが直感的に書ける気がします。
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
auto_strcpy が生き残ってますね…
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
それよりループの内側でローカル変数でSTLコンテナを使ってるのが効率が悪そうで気になります…。
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
それはそれで対策がいりそうですが別件でよいと思っています。
どっかで対応いれたいな、というのを書いてみただけです。
| if( plugin ){ | ||
| // 要検討:plugin.defのidとsakuraw.iniのidの不一致処理 | ||
| assert_warning( 0 == auto_strcmp( plugin_table[iNo].m_szId, plugin->m_sId.c_str() ) ); | ||
| assert_warning( 0 == wcscmp( plugin_table[iNo].m_szId, plugin->m_sId.c_str() ) ); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
ここ wstring::compare にしても良さそうですね。
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
basic_string アレルギーなので使わないでおきます。:mask:
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
では std::char_traits<WCHAR>::compare で、と言ってみたりして 😄
というか、ここに関していうと assert_warning ってなんでしたっけ?とか assert_warning する意義は?とかも気になるんですけどね。
完全に別件だと思ってますので対応は不要です。
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
assert_warning はデバッグ時に軽微な問題を拾いやすくするための仕組みのようです。
| // 何も設定しない(元のまま) | ||
| } | ||
| else if (auto_strcmp(ptdi->item.pszText, L"") == 0) { | ||
| else if (wcscmp(ptdi->item.pszText, L"") == 0) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
ここ、else if ( !ptdi->item.pszText[0] ) としても同じですね。
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
おそらくいっしょですね。
| /* クラス名::メソッドの場合 */ | ||
| if( NULL != ( pPos = wcsstr( pWork, L"::" ) ) | ||
| && auto_strncmp( L"operator ", pWork, 9) != 0 ){ | ||
| && wcsncmp( L"operator ", pWork, 9) != 0 ){ |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
9ってなんでしたっけ?
というのはあとにします。
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
_countof(L"operator ") だと思います。
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
-1 が必要かも…。
| ++k; | ||
| // Klass::operator std::string | ||
| if( auto_strncmp( L"operator ", pWork + m, 9) == 0 ){ | ||
| if( wcsncmp( L"operator ", pWork + m, 9) == 0 ){ |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
9ってなんでしたっけ?
というのはあとにします。
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
_countof(L"operator ") だと思います。
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
-1 が必要かも…。
| // 不正なファイル名のままだとファイル保存時ダイアログが出なくなるので | ||
| // 簡単なファイルチェックを行うように修正 | ||
| if (_tcsncmp_literal(szPath, L"file:///")==0) { | ||
| if (wcsncmp_literal(szPath, L"file:///")==0) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
何度か書いた独自マクロってのはこれのことです。
この変更に関してはなんも問題なしと思います。
|
✅ Build sakura 1.0.2236 completed (commit 25bc4a8c92 by @beru) |
| else { | ||
| if( !GetDllShareData().m_Common.m_sMainMenu.m_bMainMenuKeyParentheses | ||
| && (((p = wcschr( sName, sKey[0])) != NULL) || ((p = auto_strchr( sName, _totlower(sKey[0]))) != NULL)) ){ | ||
| && (((p = wcschr( sName, sKey[0])) != NULL) || ((p = wcschr( sName, _totlower(sKey[0]))) != NULL)) ){ |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
修正を確認しました。
berryzplus
left a comment
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
問題ないと思います。
一応ローカルビルドと簡単な動作確認は行いましたが、問題なく動いていそうです。
|
@berryzplus さん |
auto_ 系の関数を使う必要が無いところで使わないように変更
PR の目的
目的はリファクタリングを行ってコードの読み易さを向上する事です。
カテゴリ
PR の背景
sakura_core/util/string_ex.hにある、接頭辞がauto_のオーバーロード関数を使う必要が無い箇所では使わないように変更しました。以前は TCHAR を使用していたので ACHAR と WCHAR てオーバーロードされた関数を使う意味が有りましたが TCHAR を使わなくなったので WCHAR 用の関数を直接呼ぶようにしました。なお
auto_系の関数はインライン関数なので、経由しなくなったとしてもパフォーマンスの改善にはならないと思います。PR のメリット
不要になった間接コードを経由しなくなる事で記述が明確になると思います。
PR のデメリット (トレードオフとかあれば)
ワイド文字列を処理する関数名になじみが無い人にとっては関数名から処理の内容を読み取るのが難しく感じるかもしれません。
PR の影響範囲
動作に影響はないはずです。
関連チケット
#1034 #1038