Skip to content

Conversation

@beru
Copy link
Contributor

@beru beru commented Nov 9, 2025

PR対象

  • アプリ(サクラエディタ本体)

カテゴリ

  • 改善

PR の背景

#2153 (comment) に記載

タイトルが更新されない場合にも CEditWnd::ChangeFileNameNotify の最後でファイル名変更通知をブロードキャストして CEditWnd::DispatchEventcase MYWM_TAB_WINDOW_NOTIFY で処理するのが定期的に実行されているのでもったいないなと思いました。

仕様・動作説明

タブの見出しやファイル名の内容が変わっていない場合はファイル名変更通知をブロードキャストしないようにしました。

PR の影響範囲

テスト内容

タブ名が今まで通りと変わらず変更される事を確認

関連 issue, PR

参考資料

@beru beru added refactoring リファクタリング 【ChangeLog除外】 🚅 speed up 🚀 高速化 and removed refactoring リファクタリング 【ChangeLog除外】 labels Nov 9, 2025
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.

対応ありがとうございます。

wcsncpy_s(filePath, _countof2(filePath), pszFilePath, _TRUNCATE );
if (wcscmp(filePath, p->m_szFilePath) != 0) {
p->m_szFilePath = filePath;
changed = true;
Copy link
Contributor

Choose a reason for hiding this comment

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

指摘じゃないです。

ここのコードは結合テストでないとテストしづらいので、if文の追加は極力避けるべきと思います。

changed = 0 != wcscmp(変更前文字列, 変更後文字列);
ストア先変数 = 変更後文字列;

のように書けば、事前コピーとif文が要らないんじゃないかと思いました。

Copy link
Contributor Author

Choose a reason for hiding this comment

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

コピー元の文字列 (pszFilePath) が極端に長い時にコピー先に切り詰めて記録されるので、コピー元の文字列が以前と変わってたとしてもコピー先の文字列の内容が以前と変わらない場合があるのではないかと思います。

ただコピー元の文字列が極端に長い場合があり得るのかの検証はしていません。

Copy link
Contributor

@berryzplus berryzplus Nov 11, 2025

Choose a reason for hiding this comment

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

もう少し詰めるとこういうことです。

changed |= 0 != _wcsncmp(変更後文字列, ストア先変数, std::size(ストア先変数) - 1);
wcsncpy_s(ストア先変数, std::size(ストア先変数), 変更後文字列, _TRUNCATE);

C++20以降なら「変更後文字列.starts_with(ストア先変数)」と書けます。

ストア先変数のサイズはかなり大きくてMAXはタイトルバーに入りきらない気がするので、あまり気にしなくてよいかも知れません。(要検証。)

Copy link
Contributor Author

Choose a reason for hiding this comment

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

バッファサイズについて少し見てみました。なんか統一されてないですね。

CEditWnd::ChangeFileNameNotify 呼び出し元の CEditWnd::UpdateCaption でローカル変数で用意しているキャプションのバッファサイズは1024文字分 link

CEditWnd::ChangeFileNameNotify で設定するタブのキャプション書き込み先(EditNode::m_szTabCaption)のバッファサイズは260文字分 link

CEditWnd::DispatchEventMYWM_TAB_WINDOW_NOTIFY メッセージの処理で CTabWnd::TabWindowNotify を呼び出して case TWNT_FILE の処理で用意される文字列バッファのサイズは1024文字分 link

ストア先変数のサイズはかなり大きくてMAXはタイトルバーに入りきらない気がするので、あまり気にしなくてよいかも知れません。(要検証。)

いやしかしberryzplusさんが将来的にLas Vegas Sphereを買い取ってサクラエディタの画面を映したとしたらタブの見出しに長い文字列を表示できる可能性も?

if (changed) {
//ファイル名変更通知をブロードキャストする。
int nGroup = CAppNodeManager::getInstance()->GetEditNode( GetHwnd() )->GetGroup();
CAppNodeGroupHandle(nGroup).PostMessageToAllEditors(
Copy link
Contributor

Choose a reason for hiding this comment

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

指摘じゃないんですが。

これ

int nGroup = CAppNodeManager::getInstance()->GetEditNode( GetHwnd() )->GetGroup();
CAppNodeGroupHandle(nGroup).PostMessageToAllEditors(

CAppNodeManager::getInstance()->GetEditNode( GetHwnd() )->GetGroup().PostMessageToAllEditors(

と等価なので、冗長な書き方だと思います。

Copy link
Contributor Author

Choose a reason for hiding this comment

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

確かにそうですね。ただこのPRでは変更しないようにします。

Copy link
Contributor

Choose a reason for hiding this comment

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

「他にもたくさんある」というのと、こういうのとどちらがよいか、みたいな話もあります。

auto& cGroup = CAppNodeManager::getInstance()->GetEditNode( GetHwnd() )->GetGroup();
cGroup.PostMessageToAllEditors(

@beru beru merged commit 4b096cd into sakura-editor:master Nov 15, 2025
11 of 12 checks passed
@beru beru deleted the suppress_broadcast_WM_TAB_WINDOW_NOTIFY branch November 15, 2025 14:23
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

🚅 speed up 🚀 高速化 refactoring リファクタリング 【ChangeLog除外】

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants