Skip to content

Conversation

@beru
Copy link
Contributor

@beru beru commented Sep 15, 2019

PR の目的

目的はリファクタリングを行ってコードの読み易さを向上する事です。

カテゴリ

  • リファクタリング

PR の背景

sakura_core/util/string_ex.h にある、接頭辞が auto_ のオーバーロード関数を使う必要が無い箇所では使わないように変更しました。以前は TCHAR を使用していたので ACHAR と WCHAR てオーバーロードされた関数を使う意味が有りましたが TCHAR を使わなくなったので WCHAR 用の関数を直接呼ぶようにしました。

なお auto_ 系の関数はインライン関数なので、経由しなくなったとしてもパフォーマンスの改善にはならないと思います。

PR のメリット

不要になった間接コードを経由しなくなる事で記述が明確になると思います。

PR のデメリット (トレードオフとかあれば)

ワイド文字列を処理する関数名になじみが無い人にとっては関数名から処理の内容を読み取るのが難しく感じるかもしれません。

PR の影響範囲

動作に影響はないはずです。

関連チケット

#1034 #1038

beru added 19 commits September 15, 2019 16:55
_tcsncmp_literal
_tcsistr_j
_tcs_toupper
@beru beru added the refactoring リファクタリング 【ChangeLog除外】 label Sep 15, 2019
@AppVeyorBot
Copy link

Build sakura 1.0.2234 completed (commit 106f9d046d by @)

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 );
Copy link
Contributor

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);
Copy link
Contributor

Choose a reason for hiding this comment

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

この10ってなんでしたっけ?
というのをどっかで確認したいです。

Copy link
Contributor Author

Choose a reason for hiding this comment

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

使われている書式文字列的にはそこまで要らないとは思いますが余裕を持って + 10 してるんでしょうね。

size_t nLen = wcslen(pRecent->GetItemText(i));
std::vector<WCHAR> vecPath(nLen + 2);
WCHAR* szPath = &vecPath[0];
auto_strcpy( szPath, pRecent->GetItemText(i) );
Copy link
Contributor

Choose a reason for hiding this comment

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

ここも std::wstring 使ったほうが直感的に書ける気がします。

Copy link
Contributor Author

Choose a reason for hiding this comment

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

auto_strcpy が生き残ってますね…

Copy link
Contributor Author

Choose a reason for hiding this comment

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

それよりループの内側でローカル変数でSTLコンテナを使ってるのが効率が悪そうで気になります…。

Copy link
Contributor

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() ) );
Copy link
Contributor

Choose a reason for hiding this comment

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

ここ wstring::compare にしても良さそうですね。

Copy link
Contributor Author

@beru beru Sep 15, 2019

Choose a reason for hiding this comment

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

basic_string アレルギーなので使わないでおきます。:mask:

Copy link
Contributor

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 する意義は?とかも気になるんですけどね。

完全に別件だと思ってますので対応は不要です。

Copy link
Contributor Author

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) {
Copy link
Contributor

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] ) としても同じですね。

Copy link
Contributor Author

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 ){
Copy link
Contributor

Choose a reason for hiding this comment

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

9ってなんでしたっけ?
というのはあとにします。

Copy link
Contributor Author

Choose a reason for hiding this comment

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

_countof(L"operator ") だと思います。

Copy link
Contributor Author

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 ){
Copy link
Contributor

Choose a reason for hiding this comment

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

9ってなんでしたっけ?
というのはあとにします。

Copy link
Contributor Author

Choose a reason for hiding this comment

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

_countof(L"operator ") だと思います。

Copy link
Contributor Author

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) {
Copy link
Contributor

Choose a reason for hiding this comment

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

何度か書いた独自マクロってのはこれのことです。
この変更に関してはなんも問題なしと思います。

@AppVeyorBot
Copy link

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)) ){
Copy link
Contributor

Choose a reason for hiding this comment

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

修正を確認しました。

Copy link
Contributor

@berryzplus berryzplus left a comment

Choose a reason for hiding this comment

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

問題ないと思います。
一応ローカルビルドと簡単な動作確認は行いましたが、問題なく動いていそうです。

@beru
Copy link
Contributor Author

beru commented Sep 15, 2019

@berryzplus さん
確認ありがとうございました。Merge します。
もし問題があったら別のPRで対処します。

@m-tmatma m-tmatma added this to the v2.4.0 milestone Dec 29, 2019
HoppingTappy pushed a commit to HoppingTappy/sakura that referenced this pull request Jun 16, 2020
auto_ 系の関数を使う必要が無いところで使わないように変更
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

refactoring リファクタリング 【ChangeLog除外】

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants