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

CViewSelect::PrintSelectionInfoMsg の高速化、及び行のEOL長を取得する処理の高速化 #993

Merged
merged 2 commits into from
Aug 15, 2019
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.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
17 changes: 1 addition & 16 deletions sakura_core/CEol.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -46,16 +46,7 @@ const EEolType gm_pnEolTypeArr[EOL_TYPE_NUM] = {
// 固定データ
//-----------------------------------------------

struct SEolDefinition{
const TCHAR* m_szName;
const WCHAR* m_szDataW;
const ACHAR* m_szDataA;
int m_nLen;

bool StartsWith(const WCHAR* pData, int nLen) const{ return m_nLen<=nLen && 0==auto_memcmp(pData,m_szDataW,m_nLen); }
bool StartsWith(const ACHAR* pData, int nLen) const{ return m_nLen<=nLen && m_szDataA[0] != '\0' && 0==auto_memcmp(pData,m_szDataA,m_nLen); }
};
static const SEolDefinition g_aEolTable[] = {
const SEolDefinition g_aEolTable[] = {
{ _T("改行無"), L"", "", 0 },
{ _T("CRLF"), L"\x0d\x0a", "\x0d\x0a", 2 },
{ _T("LF"), L"\x0a", "\x0a", 1 },
Expand Down Expand Up @@ -129,12 +120,6 @@ EEolType _GetEOLType_unibe( const char* pszData, int nDataLen )
// 実装部
//-----------------------------------------------

//! 現在のEOL長を取得。文字単位。
CLogicInt CEol::GetLen() const
{
return CLogicInt(g_aEolTable[ m_eEolType ].m_nLen);
}

//! 現在のEOLの名称取得
const TCHAR* CEol::GetName() const
{
Expand Down
13 changes: 12 additions & 1 deletion sakura_core/CEol.h
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,17 @@ enum EEolType {
EOL_UNKNOWN = -1 //
};

struct SEolDefinition{
const TCHAR* m_szName;
const WCHAR* m_szDataW;
const ACHAR* m_szDataA;
int m_nLen;

bool StartsWith(const WCHAR* pData, int nLen) const{ return m_nLen<=nLen && 0==auto_memcmp(pData,m_szDataW,m_nLen); }
bool StartsWith(const ACHAR* pData, int nLen) const{ return m_nLen<=nLen && m_szDataA[0] != '\0' && 0==auto_memcmp(pData,m_szDataA,m_nLen); }
};
extern const SEolDefinition g_aEolTable[];

#define EOL_TYPE_NUM EOL_CODEMAX // 8

/* 行終端子の配列 */
Expand Down Expand Up @@ -90,7 +101,7 @@ class CEol{

//取得
EEolType GetType() const{ return m_eEolType; } //!< 現在のTypeを取得
CLogicInt GetLen() const; //!< 現在のEOL長を取得。文字単位。
CLogicInt GetLen() const { return CLogicInt(g_aEolTable[ m_eEolType ].m_nLen); } //!< 現在のEOL長を取得。文字単位。
const TCHAR* GetName() const; //!< 現在のEOLの名称取得
const wchar_t* GetValue2() const; //!< 現在のEOL文字列先頭へのポインタを取得
//#####
Expand Down
29 changes: 13 additions & 16 deletions sakura_core/view/CViewSelect.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -673,9 +673,7 @@ void CViewSelect::PrintSelectionInfoMsg() const
else {
// 通常の選択では選択範囲の中身を数える
int select_sum = 0; // バイト数合計
const wchar_t *pLine; // データを受け取る
CLogicInt nLineLen; // 行の長さ
const CLayout* pcLayout;
const CLayout* __restrict pcLayout;
CViewSelect* thiz = const_cast<CViewSelect*>( this ); // const外しthis

// 共通設定・選択文字数を文字単位ではなくバイト単位で表示する
Expand All @@ -685,8 +683,8 @@ void CViewSelect::PrintSelectionInfoMsg() const
pView->m_pcEditWnd->m_nSelectCountMode == SELECT_COUNT_BY_BYTE );

// 1行目
pLine = pView->m_pcEditDoc->m_cLayoutMgr.GetLineStr( m_sSelect.GetFrom().GetY2(), &nLineLen, &pcLayout );
if( pLine ){
pcLayout = pView->m_pcEditDoc->m_cLayoutMgr.SearchLineByLayoutY(m_sSelect.GetFrom().GetY2());
if( pcLayout ){
if( bCountByByte ){
// バイト数でカウント
// 内部文字コードから現在の文字コードに変換し、バイト数を取得する。
Expand All @@ -701,8 +699,8 @@ void CViewSelect::PrintSelectionInfoMsg() const
bool bSelExtend; // 選択領域拡大フラグ

// 最終行の処理
pLine = pView->m_pcEditDoc->m_cLayoutMgr.GetLineStr( m_sSelect.GetTo().y, &nLineLen, &pcLayout );
if( pLine ){
pcLayout = pView->m_pcEditDoc->m_cLayoutMgr.SearchLineByLayoutY( m_sSelect.GetTo().y );
if( pcLayout ){
if( pView->LineColumnToIndex( pcLayout, m_sSelect.GetTo().GetX2() ) == 0 ){
// 最終行の先頭にキャレットがある場合は
// その行を行数に含めない
Expand Down Expand Up @@ -781,19 +779,18 @@ void CViewSelect::PrintSelectionInfoMsg() const
// GetSelectedDataと似ているが,先頭行と最終行は排除している
// Aug. 16, 2005 aroka nLineNumはfor以降でも使われるのでforの前で宣言する
// VC .NET以降でもMicrosoft拡張を有効にした標準動作はVC6と同じことに注意
CLayoutInt nLineNum;
for( nLineNum = m_sSelect.GetFrom().GetY2() + CLayoutInt(1);
nLineNum < m_sSelect.GetTo().GetY2(); ++nLineNum ){
pLine = pView->m_pcEditDoc->m_cLayoutMgr.GetLineStr( nLineNum, &nLineLen, &pcLayout );
CLayoutInt nLineNum = m_sSelect.GetFrom().GetY2() + CLayoutInt(1);
CLayoutInt nLineTo = m_sSelect.GetTo().GetY2();
pcLayout = pView->m_pcEditDoc->m_cLayoutMgr.SearchLineByLayoutY( nLineNum );
for( ; nLineNum < nLineTo && pcLayout; ++nLineNum ){
// 2006.06.06 ryoji 指定行のデータが存在しない場合の対策
if( NULL == pLine )
break;
select_sum += pcLayout->GetLengthWithoutEOL() + pcLayout->GetLayoutEol().GetLen();
select_sum += pcLayout->GetLengthWithEOL() - 1 + pcLayout->GetLayoutEol().GetLen();
pcLayout = pcLayout->GetNextLayout();
}

// 最終行の処理
pLine = pView->m_pcEditDoc->m_cLayoutMgr.GetLineStr( nLineNum, &nLineLen, &pcLayout );
if( pLine ){
pcLayout = pView->m_pcEditDoc->m_cLayoutMgr.SearchLineByLayoutY( nLineNum );
if( pcLayout ){
int last_line_chars = pView->LineColumnToIndex( pcLayout, m_sSelect.GetTo().GetX2() );
select_sum += last_line_chars;
if( last_line_chars == 0 ){
Expand Down