-
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
Changes from all commits
e789c60
4b7d343
46f40e2
3b20a54
61d300a
6ee34cb
c0d6521
47ea505
4e364f4
9755786
b405ea4
d7dd86e
876faf1
46fa080
96868a1
cdcca90
c1bd913
e6b8c2a
239918f
2bcc3da
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -64,14 +64,14 @@ void CGrepAgent::OnAfterSave(const SSaveInfo& sSaveInfo) | |
| */ | ||
| void CGrepAgent::CreateFolders( const WCHAR* pszPath, std::vector<std::wstring>& vPaths ) | ||
| { | ||
| const int nPathLen = auto_strlen( pszPath ); | ||
| 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 ); | ||
| wcscpy( &szPath[0], pszPath ); | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. wcslenのとこで書きましたが、std::wstring使ったらいいんじゃないかと。
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. my_strtok の呼び出しに使うバッファなので std::wstring にはしない方が良いかなと思います。 |
||
| WCHAR* token; | ||
| int nPathPos = 0; | ||
| while( NULL != (token = my_strtok<WCHAR>( &szPath[0], nPathLen, &nPathPos, L";")) ){ | ||
| auto_strcpy( &szTmp[0], token ); | ||
| wcscpy( &szTmp[0], token ); | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. szTmpもstd::wstringでいいんじゃないかと。
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 後続の while ループで
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 効率を最優先に考えるのは、必要な場面だけにしたいです。
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. in-place な指定文字を削る処理が複数個所で使われていたら関数化するのが良さそうですね。 |
||
| WCHAR* p; | ||
| WCHAR* q; | ||
| p = q = &szTmp[0]; | ||
|
|
@@ -711,7 +711,7 @@ int CGrepAgent::DoGrepTree( | |
| int nWork = 0; | ||
| int nHitCountOld = -100; | ||
| bool bOutputFolderName = false; | ||
| int nBasePathLen = auto_strlen(pszBasePath); | ||
| int nBasePathLen = wcslen(pszBasePath); | ||
| CGrepEnumOptions cGrepEnumOptions; | ||
| CGrepEnumFilterFiles cGrepEnumFilterFiles; | ||
| cGrepEnumFilterFiles.Enumerates( pszPath, cGrepEnumKeys, cGrepEnumOptions, cGrepExceptAbsFiles ); | ||
|
|
@@ -751,7 +751,7 @@ int CGrepAgent::DoGrepTree( | |
| currentFile += L"\\"; | ||
| currentFile += lpFileName; | ||
| int nBasePathLen2 = nBasePathLen + 1; | ||
| if( (int)auto_strlen(pszPath) < nBasePathLen2 ){ | ||
| if( (int)wcslen(pszPath) < nBasePathLen2 ){ | ||
| nBasePathLen2 = nBasePathLen; | ||
| } | ||
|
|
||
|
|
@@ -1196,7 +1196,7 @@ int CGrepAgent::DoGrepFile( | |
| X / O : (D)Folder(Abs) -> (G)RelPath(File) | ||
| 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); | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. この10ってなんでしたっけ?
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 使われている書式文字列的にはそこまで要らないとは思いますが余裕を持って + 10 してるんでしょうね。 |
||
| wchar_t* szWork0 = &pszWork[0]; | ||
| if( sGrepOption.bGrepOutputBaseFolder || sGrepOption.bGrepSeparateFolder ){ | ||
| if( !bOutputBaseFolder && sGrepOption.bGrepOutputBaseFolder ){ | ||
|
|
@@ -1214,7 +1214,7 @@ int CGrepAgent::DoGrepFile( | |
| if( pszFolder[0] ){ | ||
| auto_sprintf( szWork0, L"■\"%s\"\r\n", pszFolder ); // (C), (D) | ||
| }else{ | ||
| auto_strcpy( szWork0, L"■\r\n" ); | ||
| wcscpy( szWork0, L"■\r\n" ); | ||
| } | ||
| cmemMessage.AppendString( szWork0 ); | ||
| bOutputFolderName = true; | ||
|
|
@@ -1243,7 +1243,7 @@ int CGrepAgent::DoGrepFile( | |
| { | ||
| if( CODE_AUTODETECT == sGrepOption.nGrepCharSet ){ | ||
| if( IsValidCodeType(nCharCode) ){ | ||
| auto_strcpy( szCpName, CCodeTypeName(nCharCode).Bracket() ); | ||
| wcscpy( szCpName, CCodeTypeName(nCharCode).Bracket() ); | ||
| pszCodeName = szCpName; | ||
| }else{ | ||
| CCodePage::GetNameBracket(szCpName, nCharCode); | ||
|
|
@@ -1694,7 +1694,7 @@ int CGrepAgent::DoGrepReplaceFile( | |
| { | ||
| if( CODE_AUTODETECT == sGrepOption.nGrepCharSet ){ | ||
| if( IsValidCodeType(nCharCode) ){ | ||
| auto_strcpy( szCpName, CCodeTypeName(nCharCode).Bracket() ); | ||
| wcscpy( szCpName, CCodeTypeName(nCharCode).Bracket() ); | ||
| pszCodeName = szCpName; | ||
| }else{ | ||
| CCodePage::GetNameBracket(szCpName, nCharCode); | ||
|
|
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -112,9 +112,9 @@ class CGrepEnumFileBase { | |
| int baseLen = wcslen( lpBaseFolder ); | ||
| LPWSTR lpPath = new WCHAR[ baseLen + wcslen( vecKeys[ i ] ) + 2 ]; | ||
| if( NULL == lpPath ) break; | ||
| auto_strcpy( lpPath, lpBaseFolder ); | ||
| auto_strcpy( lpPath + baseLen, L"\\" ); | ||
| auto_strcpy( lpPath + baseLen + 1, vecKeys[ i ] ); | ||
| wcscpy( lpPath, lpBaseFolder ); | ||
| wcscpy( lpPath + baseLen, L"\\" ); | ||
| wcscpy( lpPath + baseLen + 1, vecKeys[ i ] ); | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. wstring使ったら
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. そうですね。それかスマポ使ってメモリ解放の記述を自動化してあげても良いかも。。 まぁこのPRでは wstring への置き換えまでやると考える事が増えるのでやらないようにしたいです。
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. サクラエディタには、文字列的なモノを扱うクラスがいっぱいありますが、そいつらを整備してやれば、ソコソコの可読性をキープしつつ効率を維持することができるような気がします。 ここのコンテキストだと StringBuffer に このPRでまとめて対処する気はありませんけども。
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 将来のC++で文字列の組み込み型が登場するまではコテコテのC言語の記述を保ちたいと思いますん。 |
||
| // vecKeys[ i ] ==> "subdir\*.h" 等の場合に後で(ファイル|フォルダ)名に "subdir\" を連結する | ||
| const WCHAR* keyDirYen = wcsrchr( vecKeys[ i ], L'\\' ); | ||
| const WCHAR* keyDirSlash = wcsrchr( vecKeys[ i ], L'/' ); | ||
|
|
@@ -150,9 +150,9 @@ class CGrepEnumFileBase { | |
| wcsncpy( lpName, vecKeys[ i ], nKeyDirLen ); | ||
| wcscpy( lpName + nKeyDirLen, w32fd.cFileName ); | ||
| LPWSTR lpFullPath = new WCHAR[ baseLen + wcslen(lpName) + 2 ]; | ||
| auto_strcpy( lpFullPath, lpBaseFolder ); | ||
| auto_strcpy( lpFullPath + baseLen, L"\\" ); | ||
| auto_strcpy( lpFullPath + baseLen + 1, lpName ); | ||
| wcscpy( lpFullPath, lpBaseFolder ); | ||
| wcscpy( lpFullPath + baseLen, L"\\" ); | ||
| wcscpy( lpFullPath + baseLen + 1, lpName ); | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. wstring使ったら
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. あとループの内側で毎回メモリ確保と解放をせずに、サイズが足りてるなら領域を使いまわしたりもできそうですね。 |
||
| if( IsValid( w32fd, lpName ) ){ | ||
| if( pExceptItems && pExceptItems->IsExist( lpFullPath ) ){ | ||
| }else{ | ||
|
|
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -327,9 +327,9 @@ void CHokanMgr::HokanSearchByKeyword( | |
| const wchar_t* word = keywordMgr.GetKeyWord(kwdset,i); | ||
| int nRet; | ||
| if( bHokanLoHiCase ){ | ||
| nRet = auto_memicmp(pszCurWord, word, nKeyLen ); | ||
| nRet = wmemicmp(pszCurWord, word, nKeyLen ); | ||
| }else{ | ||
| nRet = auto_memcmp(pszCurWord, word, nKeyLen ); | ||
| nRet = wmemcmp(pszCurWord, word, nKeyLen ); | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. PRの趣旨とは関係ないですが、利用する関数が誤ってる気がします。 wmemcmp ← メモリ領域を wchar_t のバイナリ配列として比較。 つまり、SUPERニッチな関数以外では wmemcmp を使う必要はないはず・・・。
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. そうなんでしょうか?処理結果が問題無いなら誤っているとまではいえない気もします。 wcscmp だと文字列長渡さないのが気になりますね。まぁ本当はC文字列ではなくて比較する両方の文字列の長さが事前に分かっている型を使いたいです。まず文字列長が一致しているかの比較が出来るので文字列一致判定の効率が良くなる場合が有ると思います。
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 関数の特性を見て分かる通り、領域内にNUL文字 wcscmpだと -1, 0, 1 の3つの可能性があるので微妙ですが、operator == だと文字列長を考慮せずには語れませんね・・・。
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
具体的に問題が生じるケースがあるのか自分は掴めていません。
ここでの使われ方は同一かどうかの比較なので、その要件を満たすならまぁ良いんじゃないかなと思います。 |
||
| } | ||
| if( nRet != 0 ){ | ||
| continue; | ||
|
|
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -141,7 +141,7 @@ int CCommandLine::CheckCommandLine( | |
| { | ||
| if( len >= ptr->len && // 長さが足りているか | ||
| ( str[ptr->len] == '=' || str[ptr->len] == ':' ) && // オプション部分の長さチェック | ||
| auto_memicmp( str, ptr->opt, ptr->len ) == 0 ) // 文字列の比較 // 2006.10.25 ryoji memcmp() -> _memicmp() | ||
| wmemicmp( str, ptr->opt, ptr->len ) == 0 ) // 文字列の比較 // 2006.10.25 ryoji memcmp() -> _memicmp() | ||
| { | ||
| *arg = str + ptr->len + 1; // 引数開始位置 | ||
| *arglen = len - ptr->len - 1; | ||
|
|
@@ -164,7 +164,7 @@ int CCommandLine::CheckCommandLine( | |
| for( ptr = _COptWoA; ptr->opt != NULL; ptr++ ) | ||
| { | ||
| if( len == ptr->len && // 長さチェック | ||
| auto_memicmp( str, ptr->opt, ptr->len ) == 0 ) // 文字列の比較 | ||
| wmemicmp( str, ptr->opt, ptr->len ) == 0 ) // 文字列の比較 | ||
| { | ||
| *arglen = 0; | ||
| return ptr->value; | ||
|
|
@@ -288,7 +288,7 @@ void CCommandLine::ParseCommandLine( LPCWSTR pszCmdLineSrc, bool bResponse ) | |
| // Nov. 11, 2005 susu | ||
| // 不正なファイル名のままだとファイル保存時ダイアログが出なくなるので | ||
| // 簡単なファイルチェックを行うように修正 | ||
| if (_tcsncmp_literal(szPath, L"file:///")==0) { | ||
| if (wcsncmp_literal(szPath, L"file:///")==0) { | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 何度か書いた独自マクロってのはこれのことです。 |
||
| wcscpy(szPath, &(szPath[8])); | ||
| } | ||
| int len = wcslen(szPath); | ||
|
|
@@ -384,7 +384,7 @@ void CCommandLine::ParseCommandLine( LPCWSTR pszCmdLineSrc, bool bResponse ) | |
| case CMDLINEOPT_GREPMODE: // GREPMODE | ||
| m_bGrepMode = true; | ||
| if( L'\0' == m_fi.m_szDocType[0] ){ | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. ちょっと関係ありませんが、 |
||
| auto_strcpy( m_fi.m_szDocType , L"grepout" ); | ||
| wcscpy( m_fi.m_szDocType , L"grepout" ); | ||
| } | ||
| break; | ||
| case CMDLINEOPT_GREPDLG: // GREPDLG | ||
|
|
@@ -473,7 +473,7 @@ void CCommandLine::ParseCommandLine( LPCWSTR pszCmdLineSrc, bool bResponse ) | |
| m_bDebugMode = true; | ||
| // 2010.06.16 Moca -TYPE=output 扱いとする | ||
| if( L'\0' == m_fi.m_szDocType[0] ){ | ||
| auto_strcpy( m_fi.m_szDocType , L"output" ); | ||
| wcscpy( m_fi.m_szDocType , L"output" ); | ||
| } | ||
| break; | ||
| case CMDLINEOPT_NOMOREOPT: // 2007.09.09 genta これ以降引数無効 | ||
|
|
||
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.
amemcmpってなんでしたっけ?
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.
実質 memcmp ですね。
sakura/sakura_core/util/string_ex.h
Line 55 in 239918f
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.
memcmpと書けばよいものをamemcmpと書いて分かりづらくしている、ととるか
memcmpと書いたらansi想定かどうか分かりづらいからamemcmpと書いて分かりやすくしてる、ととるか。
ぼく個人は、付加価値を与えない独自定義は、コードを分かりづらくしてるだけだと考えています。(これまたPRの趣旨とずれている・・・)
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.
きっと amemcmp 関数を書いた中の人にとっては priceless だったんでしょう。