Skip to content
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

ファイル読み込みの高速化 #1951

Merged
merged 3 commits into from
May 13, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
3 changes: 1 addition & 2 deletions sakura_core/charset/codechecker.h
Original file line number Diff line number Diff line change
Expand Up @@ -392,8 +392,7 @@ char32_t ConvertToUtf32(std::wstring_view text) {
* 文字列がIVSの異体字セレクタで始まっているか判定する
*/
inline bool IsVariationSelector(std::wstring_view text) {
Copy link
Member Author

Choose a reason for hiding this comment

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

今後、std::wstring_view 型で文字列を扱う処理からも使うことも考えて std::wstring_view 型を受け入れる版も引き続き利用できるようにします。

const auto cp = ConvertToUtf32(text);
return 0xe0100 <= cp && cp <= 0xe01ef;
return (2 <= text.size()) && (text[0] == 0xDB40) && (0xDD00 <= text[1]) && (text[1] <= 0xDDEF);
Copy link
Contributor

Choose a reason for hiding this comment

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

この変更は速度に影響ありますか?

「0xe0100~0xe01ef」が見えなくなることを気にしています。

Copy link
Member Author

Choose a reason for hiding this comment

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

あります。ファイル読み込み処理全体 (DocFileOperation::FileLoad) の約10%はこの ConvertToUtf32 が消費していました。

}

//! 上位バイトと下位バイトを交換 (主に UTF-16 LE/BE 向け)
Expand Down
2 changes: 1 addition & 1 deletion sakura_core/mem/CNativeW.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -397,7 +397,7 @@ CLogicInt CNativeW::GetSizeOfChar( const wchar_t* pData, int nDataLen, int nIdx
}

// IVSの異体字セレクタチェック
if (IsVariationSelector(pData + nIdx + 1)) {
if (IsVariationSelector(std::wstring_view(pData + nIdx + 1, nDataLen - (nIdx + 1)))) {
// 正字 + 異体字セレクタで3個分
return CLogicInt(3);
}
Expand Down
2 changes: 1 addition & 1 deletion sakura_core/parse/CWordParse.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -187,7 +187,7 @@ ECharKind CWordParse::WhatKindOfChar(
}
// IVS(正字 + 異体字セレクタ)
else if (nCharChars == 3 &&
IsVariationSelector(pData + nIdx + 1))
IsVariationSelector(std::wstring_view(pData + nIdx + 1, pDataLen - (nIdx + 1))))
{
ret = CK_ZEN_ETC; // 全角のその他(漢字など)
}
Expand Down
2 changes: 1 addition & 1 deletion sakura_core/view/CTextMetrics.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -109,7 +109,7 @@ const int* CTextMetrics::GenerateDxArray(
vResultArray.push_back(cache.CalcPxWidthByFont(pText[i]) + spacing);
nIndent += vResultArray.back();

if (IsVariationSelector(pText + i + 1)) {
if (IsVariationSelector(std::wstring_view(pText + i + 1, nLength - (i + 1)))) {
vResultArray.push_back(0);
vResultArray.push_back(0);
i += 2;
Expand Down
21 changes: 21 additions & 0 deletions tests/unittests/test-codechecker.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -45,3 +45,24 @@ TEST(ConvertToUtf32, BinaryOnSurrogate)
const auto& s = L"\xdcff";
EXPECT_EQ(0, ConvertToUtf32(s));
}

TEST(IsVariationSelector, VariationSelectorCheck)
{
// 異体字セレクタ開始
const auto& vs1 = L"\U000E0100";
EXPECT_TRUE(IsVariationSelector(vs1));

// 異体字セレクタ終了
const auto& vs2 = L"\U000E01EF";
EXPECT_TRUE(IsVariationSelector(vs2));

// 非該当文字列
const auto& notvs1 = L"";
EXPECT_FALSE(IsVariationSelector(notvs1));
const auto& notvs2 = L"\xDB40";
EXPECT_FALSE(IsVariationSelector(notvs2));
const auto& notvs3 = L"\U000E00FF";
EXPECT_FALSE(IsVariationSelector(notvs3));
const auto& notvs4 = L"\U000E01F0";
EXPECT_FALSE(IsVariationSelector(notvs4));
}
2 changes: 1 addition & 1 deletion tests/unittests/test-ctextmetrics.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -225,7 +225,7 @@ TEST(CTextMetrics, GenerateDxArray8)
// IVSのVariantSelectorが続く文字列は先頭1文字 + 幅0×2で生成する
std::vector<int> v;
FakeCache1 cache;
CTextMetrics::GenerateDxArray(&v, L"葛󠄀", 2, 0, 0, 0, 10, cache);
CTextMetrics::GenerateDxArray(&v, L"葛󠄀", 3, 0, 0, 0, 10, cache);
Copy link
Member Author

@suconbu suconbu May 11, 2024

Choose a reason for hiding this comment

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

長さ指定が間違っていそうなのでついでに修正します。(PR反映後のテスト実行で失敗したため判明)

EXPECT_TRUE(v[0]);
EXPECT_FALSE(v[1]);
EXPECT_FALSE(v[2]);
Expand Down