help search is much faster now (7 times! that's what I call optimization ;-)
git-svn-id: https://svn.wxwidgets.org/svn/wx/wxWidgets/trunk@5485 c3d73ce0-8a6f-49c7-b76d-6d57e0e08775
This commit is contained in:
parent
57e3f9d9cc
commit
b5a7b00057
@ -582,7 +582,7 @@ wxHtmlSearchStatus::wxHtmlSearchStatus(wxHtmlHelpData* data, const wxString& key
|
||||
}
|
||||
m_Engine.LookFor(keyword, case_sensitive, whole_words_only);
|
||||
m_Active = (m_CurIndex < m_MaxIndex);
|
||||
m_LastPage = wxEmptyString;
|
||||
m_LastPage = NULL;
|
||||
}
|
||||
|
||||
bool wxHtmlSearchStatus::Search()
|
||||
@ -591,6 +591,7 @@ bool wxHtmlSearchStatus::Search()
|
||||
wxFSFile *file;
|
||||
int i = m_CurIndex; // shortcut
|
||||
bool found = FALSE;
|
||||
wxChar *thepage;
|
||||
|
||||
if (!m_Active) {
|
||||
// sanity check. Illegal use, but we'll try to prevent a crash anyway
|
||||
@ -602,22 +603,35 @@ bool wxHtmlSearchStatus::Search()
|
||||
return FALSE;
|
||||
}
|
||||
|
||||
m_ContentsItem = NULL;
|
||||
m_Name = wxEmptyString;
|
||||
m_ContentsItem = NULL;
|
||||
thepage = m_Data->m_Contents[i].m_Page;
|
||||
|
||||
file = fsys.OpenFile(m_Data->m_Contents[i].m_Book -> GetBasePath() + m_Data->m_Contents[i].m_Page);
|
||||
if (file) {
|
||||
if (m_LastPage != file->GetLocation()) {
|
||||
m_LastPage = file->GetLocation();
|
||||
if (m_Engine.Scan(file -> GetStream())) {
|
||||
m_Name = m_Data->m_Contents[i].m_Name;
|
||||
m_ContentsItem = m_Data->m_Contents + i;
|
||||
found = TRUE;
|
||||
}
|
||||
m_Active = (++m_CurIndex < m_MaxIndex);
|
||||
// check if it is same page with different anchor:
|
||||
if (m_LastPage != NULL)
|
||||
{
|
||||
wxChar *p1, *p2;
|
||||
for (p1 = thepage, p2 = m_LastPage;
|
||||
*p1 != 0 && *p1 != _T('#') && *p1 == *p2; p1++, p2++) {}
|
||||
|
||||
m_LastPage = thepage;
|
||||
|
||||
if (*p1 == 0 || *p1 == _T('#'))
|
||||
return FALSE;
|
||||
}
|
||||
else m_LastPage = thepage;
|
||||
|
||||
file = fsys.OpenFile(m_Data->m_Contents[i].m_Book -> GetBasePath() + thepage);
|
||||
if (file)
|
||||
{
|
||||
if (m_Engine.Scan(file -> GetStream())) {
|
||||
m_Name = m_Data->m_Contents[i].m_Name;
|
||||
m_ContentsItem = m_Data->m_Contents + i;
|
||||
found = TRUE;
|
||||
}
|
||||
delete file;
|
||||
}
|
||||
m_Active = (++m_CurIndex < m_MaxIndex);
|
||||
return found;
|
||||
}
|
||||
|
||||
|
@ -365,7 +365,7 @@ bool wxHtmlHelpFrame::Create(wxWindow* parent, wxWindowID id, const wxString& ti
|
||||
}
|
||||
m_HtmlWin -> Show(TRUE);
|
||||
|
||||
//RefreshLists();
|
||||
RefreshLists();
|
||||
|
||||
// showtime
|
||||
if (m_NavigPan && m_Splitter) {
|
||||
@ -480,14 +480,13 @@ bool wxHtmlHelpFrame::KeywordSearch(const wxString& keyword)
|
||||
|
||||
while (status.IsActive()) {
|
||||
curi = status.GetCurIndex();
|
||||
if (curi % 10 == 0 && progress.Update(curi) == FALSE)
|
||||
if (curi % 32 == 0 && progress.Update(curi) == FALSE)
|
||||
break;
|
||||
if (status.Search()) {
|
||||
foundstr.Printf(_("Found %i matches"), ++foundcnt);
|
||||
progress.Update(status.GetCurIndex(), foundstr);
|
||||
m_SearchList -> Append(status.GetName(), status.GetContentsItem());
|
||||
}
|
||||
wxYield();
|
||||
}
|
||||
|
||||
m_SearchButton -> Enable(TRUE);
|
||||
@ -502,27 +501,18 @@ bool wxHtmlHelpFrame::KeywordSearch(const wxString& keyword)
|
||||
|
||||
#define MAX_ROOTS 64
|
||||
|
||||
void wxHtmlHelpFrame::CreateContents(bool show_progress)
|
||||
void wxHtmlHelpFrame::CreateContents()
|
||||
{
|
||||
if (! m_ContentsBox)
|
||||
return ;
|
||||
|
||||
wxProgressDialog *progress = NULL;
|
||||
wxString proginfo;
|
||||
|
||||
m_ContentsBox->Clear();
|
||||
|
||||
int cnt = m_Data->GetContentsCnt();
|
||||
int div = (cnt / PROGRESS_STEP) + 1;
|
||||
int i;
|
||||
|
||||
wxHtmlContentsItem *it;
|
||||
|
||||
if (show_progress)
|
||||
progress = new wxProgressDialog(_("Building contents tree..."), wxEmptyString,
|
||||
cnt, this, wxPD_APP_MODAL | wxPD_CAN_ABORT |
|
||||
wxPD_AUTO_HIDE);
|
||||
|
||||
wxTreeItemId roots[MAX_ROOTS];
|
||||
bool imaged[MAX_ROOTS];
|
||||
|
||||
@ -533,12 +523,6 @@ void wxHtmlHelpFrame::CreateContents(bool show_progress)
|
||||
imaged[0] = TRUE;
|
||||
|
||||
for (it = m_Data->GetContents(), i = 0; i < cnt; i++, it++) {
|
||||
if (show_progress && ((i % div) == 0)) {
|
||||
proginfo.Printf(_("Added %d/%d items"), i, cnt);
|
||||
if (! progress->Update(i, proginfo))
|
||||
break;
|
||||
wxYield();
|
||||
}
|
||||
roots[it -> m_Level + 1] = m_ContentsBox -> AppendItem(
|
||||
roots[it -> m_Level], it -> m_Name, IMG_Page, -1,
|
||||
new wxHtmlHelpTreeItemData(it));
|
||||
@ -556,20 +540,15 @@ void wxHtmlHelpFrame::CreateContents(bool show_progress)
|
||||
imaged[it -> m_Level] = TRUE;
|
||||
}
|
||||
}
|
||||
if (show_progress)
|
||||
delete progress;
|
||||
m_ContentsBox -> Expand(roots[0]);
|
||||
}
|
||||
|
||||
|
||||
void wxHtmlHelpFrame::CreateIndex(bool show_progress)
|
||||
void wxHtmlHelpFrame::CreateIndex()
|
||||
{
|
||||
if (! m_IndexList)
|
||||
return ;
|
||||
|
||||
wxProgressDialog *progress = NULL;
|
||||
wxString proginfo;
|
||||
|
||||
m_IndexList->Clear();
|
||||
|
||||
int cnt = m_Data->GetIndexCnt();
|
||||
@ -580,26 +559,10 @@ void wxHtmlHelpFrame::CreateIndex(bool show_progress)
|
||||
m_IndexCountInfo -> SetLabel(cnttext);
|
||||
if (cnt > INDEX_IS_SMALL) return;
|
||||
|
||||
int div = (cnt / PROGRESS_STEP) + 1;
|
||||
|
||||
wxHtmlContentsItem* index = m_Data->GetIndex();
|
||||
|
||||
if (show_progress)
|
||||
progress = new wxProgressDialog(_("Building index list..."), wxEmptyString,
|
||||
cnt, this, wxPD_APP_MODAL | wxPD_CAN_ABORT |
|
||||
wxPD_AUTO_HIDE);
|
||||
for (int i = 0; i < cnt; i++) {
|
||||
if (show_progress && ((i % div) == 0)) {
|
||||
proginfo.Printf(_("Added %d/%d items"), i, cnt);
|
||||
if (! progress->Update(i, proginfo))
|
||||
break;
|
||||
wxYield();
|
||||
}
|
||||
for (int i = 0; i < cnt; i++)
|
||||
m_IndexList -> Append(index[i].m_Name, (char*)(index + i));
|
||||
}
|
||||
|
||||
if (show_progress)
|
||||
delete progress;
|
||||
}
|
||||
|
||||
void wxHtmlHelpFrame::CreateSearch()
|
||||
@ -617,10 +580,10 @@ void wxHtmlHelpFrame::CreateSearch()
|
||||
}
|
||||
|
||||
|
||||
void wxHtmlHelpFrame::RefreshLists(bool show_progress)
|
||||
void wxHtmlHelpFrame::RefreshLists()
|
||||
{
|
||||
CreateContents(show_progress);
|
||||
CreateIndex(show_progress);
|
||||
CreateContents();
|
||||
CreateIndex();
|
||||
CreateSearch();
|
||||
}
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user