Skip to content

配列クラスを整備する - #2635

Closed
berryzplus wants to merge 23 commits into
sakura-editor:masterfrom
berryzplus:feature/make_statictype_useful
Closed

配列クラスを整備する#2635
berryzplus wants to merge 23 commits into
sakura-editor:masterfrom
berryzplus:feature/make_statictype_useful

Conversation

@berryzplus

Copy link
Copy Markdown
Contributor

PR対象

  • アプリ(サクラエディタ本体)
  • テストコード

カテゴリ

  • 改善

PR の背景

  • 先行 issue はとくに作成していません。

仕様・動作説明

  • 独自の可変長配列クラス StaticVector を整備します。
  • 独自の固定長文字列バッファクラス StaticString を整備します。
  • 独自の可変長文字列バッファクラス CNativeW を整備します。

「生配列の代わりに使えるクラスを整備する」の目的で始めた整備でしたが、
CNativeWも合わせて整備するのが妥当と思われたため一緒に含めることにしました。

最大の変更点はNULLの扱いです。

変更前) 文字列は LPCWSTR で受け取る。
変更後) 文字列は std::wstring_view で受け取る。

LPCWSTR はwchar_tポインタなので、NULL値になり得ます。
std::wstring_view は文字列参照なので、NULL値になりません。

旧来の実装では NULL を有効な無効値として扱うために色々苦労していました。
思い切って 「NULL値は無効」 に倒してしまうことで整理しやすくします。

LPCWSTR pszText = nullptr;
SFilePath szFile{};
szFile = pszText; // ←従来なら有効だったコード。

今後は無効で、やったらクラッシュします。

「いい悪い」の判断は不可能と思うので、
本件も勝手にやります。

PR の影響範囲

テスト内容

関連 issue, PR

参考資料

- static max_size() → static size() 配列サイズ(上限値)を返す。
- size() → count() 有効要素数(現在値)を返す。
- 新規 empty() 有効要素数が0かどうかを返す。
size() → count() の影響箇所を修正。
(empty()への移行分は除外。)
empty()への移行分を修正。
WCHAR[N]の代わりとして使い倒すべく改善する。
型の入出力をテンプレート特殊化で調整できるようにする。
不要になったstd::wstring::c_str()を外すだけのもの。
不要になったCNativeW::GetStringPtr()を外すだけのもの。
代入値の算出部分を関数化する特殊な変更を行ったもの。
NULLチェック漏れが起きうる変更。
@berryzplus

Copy link
Copy Markdown
Contributor Author

上げてから思い出す。GitHub Actionsの英語版だと何故かこうなるのよね。

image

組み込み演算子 operator [](size_t)
独自定義演算子 operator [](int)
どちらを使えばよいか分からんのでエラー、というやつ。

@berryzplus

Copy link
Copy Markdown
Contributor Author

全然違う話だった。

理由:
x86ビルドをまったく考慮していなかったため。

前提がひっくり返るので取り下げます。

@berryzplus berryzplus closed this Sep 2, 2026
x86ビルドができないため。
トップレベルのテンプレートをTに変えた影響でコンストラクタと衝突していた。
MinGWビルドのみでビルドエラー発生。
@berryzplus berryzplus reopened this Sep 3, 2026
@berryzplus

Copy link
Copy Markdown
Contributor Author

あとでコミットの再編をするとして、対策済み修正をあげておくことに。

@github-actions

github-actions Bot commented Sep 3, 2026

Copy link
Copy Markdown

Test Results

1 358 tests  +1   1 358 ✅ +1   7m 3s ⏱️ -25s
  122 suites ±0       0 💤 ±0 
    1 files   ±0       0 ❌ ±0 

Results for commit 49ec2dc. ± Comparison against base commit 80132bc.

This pull request removes 5 and adds 6 tests. Note that renamed tests count towards both.
CNativeW ‑ AppendStringNullPointer
CNativeW ‑ AssignStringNullLiteral
CNativeW ‑ AssignStringNullPointer
CNativeW ‑ CompareWithStringPtr
CNativeW ‑ ConstructWithStringNull
CNativeW ‑ CompareWithString
CNativeW ‑ length001
CNativeW ‑ length101
StaticVector ‑ test101
StaticVector ‑ test102
StaticVector ‑ test103

@berryzplus

Copy link
Copy Markdown
Contributor Author

ひっくり返った前提

前提: StaticVectorを生配列の代わりとして使いたい。
発覚: 生配列の代わりとして使おうとすると x86 がビルドできない。

StaticVectorを生配列として扱ってたのはCRecentで、
もともと暗黙変換ではなく取得メソッドを利用していた。
しかも、CRecent自体に整理したほうがよさげな気配がある。

どうまとめるかは考え中。

@sonarqubecloud

sonarqubecloud Bot commented Sep 3, 2026

Copy link
Copy Markdown

@berryzplus berryzplus closed this Sep 4, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant