Skip to content

Commit

Permalink
Merge pull request sakura-editor#125 from beru/file_loading_speed_up
Browse files Browse the repository at this point in the history
ファイル読み込みとgrepの高速化
  • Loading branch information
kobake authored Jul 11, 2018
2 parents d8f068b + 86ba686 commit 990b683
Show file tree
Hide file tree
Showing 5 changed files with 94 additions and 61 deletions.
35 changes: 24 additions & 11 deletions sakura_core/CGrepAgent.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -22,14 +22,16 @@
#include <deque>
#include "sakura_rc.h"

#define UICHECK_INTERVAL_MILLISEC 50 // UI確認の時間間隔
#define UICHECK_INTERVAL_MILLISEC 100 // UI確認の時間間隔
#define ADDTAIL_INTERVAL_MILLISEC 50 // 結果出力の時間間隔
#define UIFILENAME_INTERVAL_MILLISEC 15 // Cancelダイアログのファイル名表示更新間隔

CGrepAgent::CGrepAgent()
: m_bGrepMode( false ) /* Grepモードか */
, m_bGrepRunning( false ) /* Grep処理中 */
, m_dwTickAddTail( 0 )
, m_dwTickUICheck( 0 )
, m_dwTickUIFileName( 0 )
{
}

Expand Down Expand Up @@ -196,13 +198,15 @@ DWORD CGrepAgent::DoGrep(
// Jun. 27, 2001 genta 正規表現ライブラリの差し替え
CBregexp cRegexp;
CNativeW cmemMessage;
CNativeW cUnicodeBuffer;
int nWork;
SGrepOption sGrepOption;

/*
|| バッファサイズの調整
*/
cmemMessage.AllocStringBuffer( 4000 );
cUnicodeBuffer.AllocStringBuffer( 4000 );

pcViewDst->m_bDoing_UndoRedo = true;

Expand Down Expand Up @@ -574,7 +578,8 @@ DWORD CGrepAgent::DoGrep(
0,
bOutputBaseFolder,
&nHitCount,
cmemMessage
cmemMessage,
cUnicodeBuffer
);
if( nTreeRet == -1 ){
nGrepTreeResult = -1;
Expand Down Expand Up @@ -671,7 +676,8 @@ int CGrepAgent::DoGrepTree(
int nNest, //!< [in] ネストレベル
bool& bOutputBaseFolder, //!< [i/o] ベースフォルダ名出力
int* pnHitCount, //!< [i/o] ヒット数の合計
CNativeW& cmemMessage //!< [i/o] Grep結果文字列
CNativeW& cmemMessage, //!< [i/o] Grep結果文字列
CNativeW& cUnicodeBuffer
)
{
int i;
Expand Down Expand Up @@ -710,8 +716,11 @@ int CGrepAgent::DoGrepTree(
);
}

//GREP実行!
::DlgItem_SetText( pcDlgCancel->GetHwnd(), IDC_STATIC_CURFILE, lpFileName );
// 定期的に grep 中のファイル名表示を更新
if( dwNow - m_dwTickUIFileName > UIFILENAME_INTERVAL_MILLISEC ){
m_dwTickUIFileName = dwNow;
::DlgItem_SetText( pcDlgCancel->GetHwnd(), IDC_STATIC_CURFILE, lpFileName );
}

std::tstring currentFile = pszPath;
currentFile += _T("\\");
Expand Down Expand Up @@ -741,7 +750,8 @@ int CGrepAgent::DoGrepTree(
(sGrepOption.bGrepSeparateFolder ? lpFileName : currentFile.c_str() + nBasePathLen + 1),
bOutputBaseFolder,
bOutputFolderName,
cmemMessage
cmemMessage,
cUnicodeBuffer
);
}else{
nRet = DoGrepFile(
Expand All @@ -760,7 +770,8 @@ int CGrepAgent::DoGrepTree(
(sGrepOption.bGrepSeparateFolder ? lpFileName : currentFile.c_str() + nBasePathLen + 1),
bOutputBaseFolder,
bOutputFolderName,
cmemMessage
cmemMessage,
cUnicodeBuffer
);
}

Expand Down Expand Up @@ -842,7 +853,8 @@ int CGrepAgent::DoGrepTree(
nNest + 1,
bOutputBaseFolder,
pnHitCount,
cmemMessage
cmemMessage,
cUnicodeBuffer
);
if( -1 == nGrepTreeResult ){
goto cancel_return;
Expand Down Expand Up @@ -1045,7 +1057,8 @@ int CGrepAgent::DoGrepFile(
const TCHAR* pszRelPath, //!< [in] 相対パス File.ext(bGrepSeparateFolder) または SubFolder\File.ext(!bGrepSeparateFolder)
bool& bOutputBaseFolder, //!<
bool& bOutputFolderName, //!<
CNativeW& cmemMessage //!< [i/o] Grep結果文字列
CNativeW& cmemMessage, //!< [i/o] Grep結果文字列
CNativeW& cUnicodeBuffer
)
{
int nHitCount;
Expand Down Expand Up @@ -1205,7 +1218,6 @@ int CGrepAgent::DoGrepFile(
}

// 注意 : cfl.ReadLine が throw する可能性がある
CNativeW cUnicodeBuffer;
while( RESULT_FAILURE != cfl.ReadLine( &cUnicodeBuffer, &cEol ) )
{
const wchar_t* pLine = cUnicodeBuffer.GetStringPtr();
Expand Down Expand Up @@ -1606,7 +1618,8 @@ int CGrepAgent::DoGrepReplaceFile(
const TCHAR* pszRelPath,
bool& bOutputBaseFolder,
bool& bOutputFolderName,
CNativeW& cmemMessage
CNativeW& cmemMessage,
CNativeW& cUnicodeBuffer
)
{
LONGLONG nLine = 0;
Expand Down
10 changes: 7 additions & 3 deletions sakura_core/CGrepAgent.h
Original file line number Diff line number Diff line change
Expand Up @@ -118,7 +118,8 @@ class CGrepAgent : public CDocListenerEx{
int nNest, //!< [in] ネストレベル
bool& bOutputBaseFolder,
int* pnHitCount, //!< [i/o] ヒット数の合計
CNativeW& cmemMessage
CNativeW& cmemMessage,
CNativeW& cUnicodeBuffer
);

// Grep実行
Expand All @@ -138,7 +139,8 @@ class CGrepAgent : public CDocListenerEx{
const TCHAR* pszRelPath,
bool& bOutputBaseFolder,
bool& bOutputFolderName,
CNativeW& cmemMessage
CNativeW& cmemMessage,
CNativeW& cUnicodeBuffer
);

int DoGrepReplaceFile(
Expand All @@ -158,7 +160,8 @@ class CGrepAgent : public CDocListenerEx{
const TCHAR* pszRelPath,
bool& bOutputBaseFolder,
bool& bOutputFolderName,
CNativeW& cmemMessage
CNativeW& cmemMessage,
CNativeW& cUnicodeBuffer
);

// Grep結果をpszWorkに格納
Expand All @@ -183,6 +186,7 @@ class CGrepAgent : public CDocListenerEx{

DWORD m_dwTickAddTail; // AddTail() を呼び出した時間
DWORD m_dwTickUICheck; // 処理中にユーザーによるUI操作が行われていないか確認した時間
DWORD m_dwTickUIFileName; // Cancelダイアログのファイル名表示更新を行った時間

public: //$$ 仮
bool m_bGrepMode; //!< Grepモードか
Expand Down
2 changes: 1 addition & 1 deletion sakura_core/charset/CESI.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1027,7 +1027,7 @@ ECodeType CESI::AutoDetectByHTML( const char* pBuf, int nSize )
for( int i = 0; i + 14 < nSize; i++ ){
// 「<meta http-equiv="Content-Type" content="text/html; Charset=Shift_JIS">」
// 「<meta charset="utf-8">」
if( 0 == memicmp(pBuf + i, "<meta", 5) && IsXMLWhiteSpace(pBuf[i+5]) ){
if( pBuf[i] == '<' && 0 == memicmp(&pBuf[i+1], "meta", 4) && IsXMLWhiteSpace(pBuf[i+5]) ){
i += 5;
ECodeType encoding = CODE_NONE;
bool bContentType = false;
Expand Down
46 changes: 30 additions & 16 deletions sakura_core/charset/CShiftJis.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -116,25 +116,39 @@ EConvertResult CShiftJis::SJISToUnicode( const CMemory& cSrc, CNativeW* pDstMem
int nSrcLen;
const char* pSrc = reinterpret_cast<const char*>( cSrc.GetRawPtr(&nSrcLen) );

// 変換先バッファサイズを設定してメモリ領域確保
wchar_t* pDst;
try{
pDst = new wchar_t[nSrcLen];
}catch( ... ){
pDst = NULL;
}
if( pDst == NULL ){
return RESULT_FAILURE;
}
if( &cSrc == pDstMem->_GetMemory() )
{
// 変換先バッファサイズを設定してメモリ領域確保
wchar_t* pDst;
try{
pDst = new wchar_t[nSrcLen];
}catch( ... ){
pDst = NULL;
}
if( pDst == NULL ){
return RESULT_FAILURE;
}

// 変換
int nDstLen = SjisToUni( pSrc, nSrcLen, pDst, &bError );
// 変換
int nDstLen = SjisToUni( pSrc, nSrcLen, pDst, &bError );

// pDstを更新
pDstMem->_GetMemory()->SetRawDataHoldBuffer( pDst, nDstLen*sizeof(wchar_t) );
// pDstを更新
pDstMem->_GetMemory()->SetRawDataHoldBuffer( pDst, nDstLen*sizeof(wchar_t) );

// 後始末
delete [] pDst;
// 後始末
delete [] pDst;
}
else
{
// 変換先バッファサイズを設定してメモリ領域確保
pDstMem->AllocStringBuffer( nSrcLen + 1 );
wchar_t* pDst = pDstMem->GetStringPtr();

// 変換
int nDstLen = SjisToUni( pSrc, nSrcLen, pDst, &bError );

pDstMem->_SetStringLength( nDstLen );
}

if( bError == false ){
return RESULT_COMPLETE;
Expand Down
62 changes: 32 additions & 30 deletions sakura_core/charset/CUtf8.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -95,39 +95,41 @@ EConvertResult CUtf8::_UTF8ToUnicode( const CMemory& cSrc, CNativeW* pDstMem, bo
// データ取得
int nSrcLen;
const char* pSrc = reinterpret_cast<const char*>( cSrc.GetRawPtr(&nSrcLen) );

const char* psrc = pSrc;
int nsrclen = nSrcLen;

// CMemory cmem;
// // MIME ヘッダーデコード
// if( decodeMime == true ){
// bool bret = MIMEHeaderDecode( pSrc, nSrcLen, &cmem, CODE_UTF8 );
// if( bret == true ){
// psrc = reinterpret_cast<char*>( cmem.GetRawPtr() );
// nsrclen = cmem.GetRawLength();
// }
// }

// 必要なバッファサイズを調べて確保する
wchar_t* pDst;
try{
pDst = new wchar_t[nsrclen];
}catch( ... ){
pDst = NULL;
}
if( pDst == NULL ){
return RESULT_FAILURE;
}

// 変換
int nDstLen = Utf8ToUni( psrc, nsrclen, pDst, bCESU8Mode );
if( &cSrc == pDstMem->_GetMemory() )
{
// 必要なバッファサイズを調べて確保する
wchar_t* pDst;
try{
pDst = new wchar_t[nSrcLen];
}catch( ... ){
pDst = NULL;
}
if( pDst == NULL ){
return RESULT_FAILURE;
}

// pDstMem を更新
pDstMem->_GetMemory()->SetRawDataHoldBuffer( pDst, nDstLen*sizeof(wchar_t) );
// 変換
int nDstLen = Utf8ToUni( pSrc, nSrcLen, pDst, bCESU8Mode );

// 後始末
delete [] pDst;
// pDstMem を更新
pDstMem->_GetMemory()->SetRawDataHoldBuffer( pDst, nDstLen*sizeof(wchar_t) );

// 後始末
delete [] pDst;
}
else
{
// 変換先バッファサイズを設定してメモリ領域確保
pDstMem->AllocStringBuffer( nSrcLen + 1 );
wchar_t* pDst = pDstMem->GetStringPtr();

// 変換
size_t nDstLen = Utf8ToUni(pSrc, nSrcLen, pDst, bCESU8Mode);

// pDstMem を更新
pDstMem->_SetStringLength( nDstLen );
}

if( bError == false ){
return RESULT_COMPLETE;
Expand Down

0 comments on commit 990b683

Please sign in to comment.