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:
@@ -582,7 +582,7 @@ wxHtmlSearchStatus::wxHtmlSearchStatus(wxHtmlHelpData* data, const wxString& key
|
|||||||
}
|
}
|
||||||
m_Engine.LookFor(keyword, case_sensitive, whole_words_only);
|
m_Engine.LookFor(keyword, case_sensitive, whole_words_only);
|
||||||
m_Active = (m_CurIndex < m_MaxIndex);
|
m_Active = (m_CurIndex < m_MaxIndex);
|
||||||
m_LastPage = wxEmptyString;
|
m_LastPage = NULL;
|
||||||
}
|
}
|
||||||
|
|
||||||
bool wxHtmlSearchStatus::Search()
|
bool wxHtmlSearchStatus::Search()
|
||||||
@@ -591,6 +591,7 @@ bool wxHtmlSearchStatus::Search()
|
|||||||
wxFSFile *file;
|
wxFSFile *file;
|
||||||
int i = m_CurIndex; // shortcut
|
int i = m_CurIndex; // shortcut
|
||||||
bool found = FALSE;
|
bool found = FALSE;
|
||||||
|
wxChar *thepage;
|
||||||
|
|
||||||
if (!m_Active) {
|
if (!m_Active) {
|
||||||
// sanity check. Illegal use, but we'll try to prevent a crash anyway
|
// sanity check. Illegal use, but we'll try to prevent a crash anyway
|
||||||
@@ -602,22 +603,35 @@ bool wxHtmlSearchStatus::Search()
|
|||||||
return FALSE;
|
return FALSE;
|
||||||
}
|
}
|
||||||
|
|
||||||
m_ContentsItem = NULL;
|
|
||||||
m_Name = wxEmptyString;
|
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);
|
m_Active = (++m_CurIndex < m_MaxIndex);
|
||||||
if (file) {
|
// check if it is same page with different anchor:
|
||||||
if (m_LastPage != file->GetLocation()) {
|
if (m_LastPage != NULL)
|
||||||
m_LastPage = file->GetLocation();
|
{
|
||||||
|
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())) {
|
if (m_Engine.Scan(file -> GetStream())) {
|
||||||
m_Name = m_Data->m_Contents[i].m_Name;
|
m_Name = m_Data->m_Contents[i].m_Name;
|
||||||
m_ContentsItem = m_Data->m_Contents + i;
|
m_ContentsItem = m_Data->m_Contents + i;
|
||||||
found = TRUE;
|
found = TRUE;
|
||||||
}
|
}
|
||||||
}
|
|
||||||
delete file;
|
delete file;
|
||||||
}
|
}
|
||||||
m_Active = (++m_CurIndex < m_MaxIndex);
|
|
||||||
return found;
|
return found;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@@ -365,7 +365,7 @@ bool wxHtmlHelpFrame::Create(wxWindow* parent, wxWindowID id, const wxString& ti
|
|||||||
}
|
}
|
||||||
m_HtmlWin -> Show(TRUE);
|
m_HtmlWin -> Show(TRUE);
|
||||||
|
|
||||||
//RefreshLists();
|
RefreshLists();
|
||||||
|
|
||||||
// showtime
|
// showtime
|
||||||
if (m_NavigPan && m_Splitter) {
|
if (m_NavigPan && m_Splitter) {
|
||||||
@@ -480,14 +480,13 @@ bool wxHtmlHelpFrame::KeywordSearch(const wxString& keyword)
|
|||||||
|
|
||||||
while (status.IsActive()) {
|
while (status.IsActive()) {
|
||||||
curi = status.GetCurIndex();
|
curi = status.GetCurIndex();
|
||||||
if (curi % 10 == 0 && progress.Update(curi) == FALSE)
|
if (curi % 32 == 0 && progress.Update(curi) == FALSE)
|
||||||
break;
|
break;
|
||||||
if (status.Search()) {
|
if (status.Search()) {
|
||||||
foundstr.Printf(_("Found %i matches"), ++foundcnt);
|
foundstr.Printf(_("Found %i matches"), ++foundcnt);
|
||||||
progress.Update(status.GetCurIndex(), foundstr);
|
progress.Update(status.GetCurIndex(), foundstr);
|
||||||
m_SearchList -> Append(status.GetName(), status.GetContentsItem());
|
m_SearchList -> Append(status.GetName(), status.GetContentsItem());
|
||||||
}
|
}
|
||||||
wxYield();
|
|
||||||
}
|
}
|
||||||
|
|
||||||
m_SearchButton -> Enable(TRUE);
|
m_SearchButton -> Enable(TRUE);
|
||||||
@@ -502,27 +501,18 @@ bool wxHtmlHelpFrame::KeywordSearch(const wxString& keyword)
|
|||||||
|
|
||||||
#define MAX_ROOTS 64
|
#define MAX_ROOTS 64
|
||||||
|
|
||||||
void wxHtmlHelpFrame::CreateContents(bool show_progress)
|
void wxHtmlHelpFrame::CreateContents()
|
||||||
{
|
{
|
||||||
if (! m_ContentsBox)
|
if (! m_ContentsBox)
|
||||||
return ;
|
return ;
|
||||||
|
|
||||||
wxProgressDialog *progress = NULL;
|
|
||||||
wxString proginfo;
|
|
||||||
|
|
||||||
m_ContentsBox->Clear();
|
m_ContentsBox->Clear();
|
||||||
|
|
||||||
int cnt = m_Data->GetContentsCnt();
|
int cnt = m_Data->GetContentsCnt();
|
||||||
int div = (cnt / PROGRESS_STEP) + 1;
|
|
||||||
int i;
|
int i;
|
||||||
|
|
||||||
wxHtmlContentsItem *it;
|
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];
|
wxTreeItemId roots[MAX_ROOTS];
|
||||||
bool imaged[MAX_ROOTS];
|
bool imaged[MAX_ROOTS];
|
||||||
|
|
||||||
@@ -533,12 +523,6 @@ void wxHtmlHelpFrame::CreateContents(bool show_progress)
|
|||||||
imaged[0] = TRUE;
|
imaged[0] = TRUE;
|
||||||
|
|
||||||
for (it = m_Data->GetContents(), i = 0; i < cnt; i++, it++) {
|
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 + 1] = m_ContentsBox -> AppendItem(
|
||||||
roots[it -> m_Level], it -> m_Name, IMG_Page, -1,
|
roots[it -> m_Level], it -> m_Name, IMG_Page, -1,
|
||||||
new wxHtmlHelpTreeItemData(it));
|
new wxHtmlHelpTreeItemData(it));
|
||||||
@@ -556,20 +540,15 @@ void wxHtmlHelpFrame::CreateContents(bool show_progress)
|
|||||||
imaged[it -> m_Level] = TRUE;
|
imaged[it -> m_Level] = TRUE;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
if (show_progress)
|
|
||||||
delete progress;
|
|
||||||
m_ContentsBox -> Expand(roots[0]);
|
m_ContentsBox -> Expand(roots[0]);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
void wxHtmlHelpFrame::CreateIndex(bool show_progress)
|
void wxHtmlHelpFrame::CreateIndex()
|
||||||
{
|
{
|
||||||
if (! m_IndexList)
|
if (! m_IndexList)
|
||||||
return ;
|
return ;
|
||||||
|
|
||||||
wxProgressDialog *progress = NULL;
|
|
||||||
wxString proginfo;
|
|
||||||
|
|
||||||
m_IndexList->Clear();
|
m_IndexList->Clear();
|
||||||
|
|
||||||
int cnt = m_Data->GetIndexCnt();
|
int cnt = m_Data->GetIndexCnt();
|
||||||
@@ -580,26 +559,10 @@ void wxHtmlHelpFrame::CreateIndex(bool show_progress)
|
|||||||
m_IndexCountInfo -> SetLabel(cnttext);
|
m_IndexCountInfo -> SetLabel(cnttext);
|
||||||
if (cnt > INDEX_IS_SMALL) return;
|
if (cnt > INDEX_IS_SMALL) return;
|
||||||
|
|
||||||
int div = (cnt / PROGRESS_STEP) + 1;
|
|
||||||
|
|
||||||
wxHtmlContentsItem* index = m_Data->GetIndex();
|
wxHtmlContentsItem* index = m_Data->GetIndex();
|
||||||
|
|
||||||
if (show_progress)
|
for (int i = 0; i < cnt; i++)
|
||||||
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();
|
|
||||||
}
|
|
||||||
m_IndexList -> Append(index[i].m_Name, (char*)(index + i));
|
m_IndexList -> Append(index[i].m_Name, (char*)(index + i));
|
||||||
}
|
|
||||||
|
|
||||||
if (show_progress)
|
|
||||||
delete progress;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
void wxHtmlHelpFrame::CreateSearch()
|
void wxHtmlHelpFrame::CreateSearch()
|
||||||
@@ -617,10 +580,10 @@ void wxHtmlHelpFrame::CreateSearch()
|
|||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
void wxHtmlHelpFrame::RefreshLists(bool show_progress)
|
void wxHtmlHelpFrame::RefreshLists()
|
||||||
{
|
{
|
||||||
CreateContents(show_progress);
|
CreateContents();
|
||||||
CreateIndex(show_progress);
|
CreateIndex();
|
||||||
CreateSearch();
|
CreateSearch();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Reference in New Issue
Block a user