diff options
| author | nyamatongwe <unknown> | 2012-09-04 19:07:18 +1000 | 
|---|---|---|
| committer | nyamatongwe <unknown> | 2012-09-04 19:07:18 +1000 | 
| commit | 4ad8875e7e798bc679a6835e309db717a693941a (patch) | |
| tree | 6c8ad0dc96474c2b810d49663b8f2e5bb7c7957c /src | |
| parent | 64e8c5fe5f09220d138539e70291f8dd4cbf1e18 (diff) | |
| download | scintilla-mirror-4ad8875e7e798bc679a6835e309db717a693941a.tar.gz | |
Cache the CaseFolder object between FindText calls so that finding many instances
of a common string in the document doesn't spend excessive time constructing case
folder objects.
Diffstat (limited to 'src')
| -rw-r--r-- | src/Document.cxx | 24 | ||||
| -rw-r--r-- | src/Document.h | 6 | ||||
| -rw-r--r-- | src/Editor.cxx | 40 | 
3 files changed, 42 insertions, 28 deletions
| diff --git a/src/Document.cxx b/src/Document.cxx index 4ce62c45b..1938149e7 100644 --- a/src/Document.cxx +++ b/src/Document.cxx @@ -69,6 +69,7 @@ void LexInterface::Colourise(int start, int end) {  Document::Document() {  	refCount = 0; +	pcf = NULL;  #ifdef _WIN32  	eolMode = SC_EOL_CRLF;  #else @@ -123,6 +124,8 @@ Document::~Document() {  	regex = 0;  	delete pli;  	pli = 0; +	delete pcf; +	pcf = 0;  }  void Document::Init() { @@ -132,6 +135,16 @@ void Document::Init() {  	}  } +bool Document::SetDBCSCodePage(int dbcsCodePage_) { +	if (dbcsCodePage != dbcsCodePage_) { +		dbcsCodePage = dbcsCodePage_; +		SetCaseFolder(NULL); +		return true; +	} else { +		return false; +	} +} +  void Document::InsertLine(int line) {  	for (int j=0; j<ldSize; j++) {  		if (perLineData[j]) @@ -1419,6 +1432,15 @@ bool Document::MatchesWordOptions(bool word, bool wordStart, int pos, int length  			(wordStart && IsWordStartAt(pos));  } +bool Document::HasCaseFolder(void) const { +	return pcf != 0; +} + +void Document::SetCaseFolder(CaseFolder *pcf_) { +	delete pcf; +	pcf = pcf_; +} +  /**   * Find text in document, supporting both forward and backward   * searches (just pass minPos > maxPos to do a backward search) @@ -1426,7 +1448,7 @@ bool Document::MatchesWordOptions(bool word, bool wordStart, int pos, int length   */  long Document::FindText(int minPos, int maxPos, const char *search,                          bool caseSensitive, bool word, bool wordStart, bool regExp, int flags, -                        int *length, CaseFolder *pcf) { +                        int *length) {  	if (*length <= 0)  		return minPos;  	if (regExp) { diff --git a/src/Document.h b/src/Document.h index 30c6aee1c..36d670937 100644 --- a/src/Document.h +++ b/src/Document.h @@ -212,6 +212,7 @@ private:  	int refCount;  	CellBuffer cb;  	CharClassify charClass; +	CaseFolder *pcf;  	char stylingMask;  	int endStyled;  	int styleClock; @@ -255,6 +256,7 @@ public:  	int SCI_METHOD Release();  	virtual void Init(); +	bool SetDBCSCodePage(int dbcsCodePage_);  	virtual void InsertLine(int line);  	virtual void RemoveLine(int line); @@ -355,8 +357,10 @@ public:  	int SCI_METHOD Length() const { return cb.Length(); }  	void Allocate(int newSize) { cb.Allocate(newSize); }  	bool MatchesWordOptions(bool word, bool wordStart, int pos, int length); +	bool HasCaseFolder(void) const; +	void SetCaseFolder(CaseFolder *pcf_);  	long FindText(int minPos, int maxPos, const char *search, bool caseSensitive, bool word, -		bool wordStart, bool regExp, int flags, int *length, CaseFolder *pcf); +		bool wordStart, bool regExp, int flags, int *length);  	const char *SubstituteByPosition(const char *text, int *length);  	int LinesTotal() const; diff --git a/src/Editor.cxx b/src/Editor.cxx index 17b899d87..fea5a2336 100644 --- a/src/Editor.cxx +++ b/src/Editor.cxx @@ -5732,15 +5732,15 @@ long Editor::FindText(  	Sci_TextToFind *ft = reinterpret_cast<Sci_TextToFind *>(lParam);  	int lengthFound = istrlen(ft->lpstrText); -	std::auto_ptr<CaseFolder> pcf(CaseFolderForEncoding()); +	if (!pdoc->HasCaseFolder()) +		pdoc->SetCaseFolder(CaseFolderForEncoding());  	int pos = pdoc->FindText(ft->chrg.cpMin, ft->chrg.cpMax, ft->lpstrText,  	        (wParam & SCFIND_MATCHCASE) != 0,  	        (wParam & SCFIND_WHOLEWORD) != 0,  	        (wParam & SCFIND_WORDSTART) != 0,  	        (wParam & SCFIND_REGEXP) != 0,  	        wParam, -	        &lengthFound, -			pcf.get()); +	        &lengthFound);  	if (pos != -1) {  		ft->chrgText.cpMin = pos;  		ft->chrgText.cpMax = pos + lengthFound; @@ -5763,19 +5763,6 @@ void Editor::SearchAnchor() {  	searchAnchor = SelectionStart().Position();  } -// Simple RAII wrapper for CaseFolder as std::auto_ptr is now deprecated -class ScopedCaseFolder { -	CaseFolder *pcf; -public: -	ScopedCaseFolder(CaseFolder *pcf_) : pcf(pcf_) { -	} -	~ScopedCaseFolder() { -		delete pcf; -		pcf = 0; -	} -	CaseFolder *get() const { return pcf; } -}; -  /**   * Find text from current search anchor: Must call @c SearchAnchor first.   * Used for next text and previous text requests. @@ -5790,7 +5777,8 @@ long Editor::SearchText(  	const char *txt = reinterpret_cast<char *>(lParam);  	int pos;  	int lengthFound = istrlen(txt); -	ScopedCaseFolder pcf(CaseFolderForEncoding()); +	if (!pdoc->HasCaseFolder()) +		pdoc->SetCaseFolder(CaseFolderForEncoding());  	if (iMessage == SCI_SEARCHNEXT) {  		pos = pdoc->FindText(searchAnchor, pdoc->Length(), txt,  		        (wParam & SCFIND_MATCHCASE) != 0, @@ -5798,8 +5786,7 @@ long Editor::SearchText(  		        (wParam & SCFIND_WORDSTART) != 0,  		        (wParam & SCFIND_REGEXP) != 0,  		        wParam, -		        &lengthFound, -				pcf.get()); +		        &lengthFound);  	} else {  		pos = pdoc->FindText(searchAnchor, 0, txt,  		        (wParam & SCFIND_MATCHCASE) != 0, @@ -5807,8 +5794,7 @@ long Editor::SearchText(  		        (wParam & SCFIND_WORDSTART) != 0,  		        (wParam & SCFIND_REGEXP) != 0,  		        wParam, -		        &lengthFound, -				pcf.get()); +		        &lengthFound);  	}  	if (pos != -1) {  		SetSelection(pos, pos + lengthFound); @@ -5841,15 +5827,15 @@ std::string Editor::CaseMapString(const std::string &s, int caseMapping) {  long Editor::SearchInTarget(const char *text, int length) {  	int lengthFound = length; -	ScopedCaseFolder pcf(CaseFolderForEncoding()); +	if (!pdoc->HasCaseFolder()) +		pdoc->SetCaseFolder(CaseFolderForEncoding());  	int pos = pdoc->FindText(targetStart, targetEnd, text,  	        (searchFlags & SCFIND_MATCHCASE) != 0,  	        (searchFlags & SCFIND_WHOLEWORD) != 0,  	        (searchFlags & SCFIND_WORDSTART) != 0,  	        (searchFlags & SCFIND_REGEXP) != 0,  	        searchFlags, -	        &lengthFound, -			pcf.get()); +	        &lengthFound);  	if (pos != -1) {  		targetStart = pos;  		targetEnd = pos + lengthFound; @@ -7098,6 +7084,7 @@ void Editor::StyleSetMessage(unsigned int iMessage, uptr_t wParam, sptr_t lParam  		break;  	case SCI_STYLESETCHARACTERSET:  		vs.styles[wParam].characterSet = lParam; +		pdoc->SetCaseFolder(NULL);  		break;  	case SCI_STYLESETVISIBLE:  		vs.styles[wParam].visible = lParam != 0; @@ -8076,8 +8063,9 @@ sptr_t Editor::WndProc(unsigned int iMessage, uptr_t wParam, sptr_t lParam) {  	case SCI_SETCODEPAGE:  		if (ValidCodePage(wParam)) { -			pdoc->dbcsCodePage = wParam; -			InvalidateStyleRedraw(); +			if (pdoc->SetDBCSCodePage(wParam)) { +				InvalidateStyleRedraw(); +			}  		}  		break; | 
