Improve Document Peeker performance issue for large files

This commit is contained in:
Don HO 2017-05-17 10:01:28 +02:00
parent 8dbd956344
commit a067de8ce2
3 changed files with 20 additions and 3 deletions

View File

@ -2025,6 +2025,9 @@ bool NppParameters::getSessionFromXmlTree(TiXmlDocument *pSessionDoc, Session *p
mapPosStr = (childNode->ToElement())->Attribute(TEXT("mapHeight"), &mapPosVal);
if (mapPosStr)
mapPosition._height = mapPosVal;
mapPosStr = (childNode->ToElement())->Attribute(TEXT("mapKByteInDoc"), &mapPosVal);
if (mapPosStr)
mapPosition._KByteInDoc = mapPosVal;
mapPosStr = (childNode->ToElement())->Attribute(TEXT("mapWrapIndentMode"), &mapPosVal);
if (mapPosStr)
mapPosition._wrapIndentMode = mapPosVal;
@ -2979,6 +2982,7 @@ void NppParameters::writeSession(const Session & session, const TCHAR *fileName)
(fileNameNode->ToElement())->SetAttribute(TEXT("mapHigherPos"), viewSessionFiles[i]._mapPos._higherPos);
(fileNameNode->ToElement())->SetAttribute(TEXT("mapWidth"), viewSessionFiles[i]._mapPos._width);
(fileNameNode->ToElement())->SetAttribute(TEXT("mapHeight"), viewSessionFiles[i]._mapPos._height);
(fileNameNode->ToElement())->SetAttribute(TEXT("mapKByteInDoc"), static_cast<int>(viewSessionFiles[i]._mapPos._KByteInDoc));
(fileNameNode->ToElement())->SetAttribute(TEXT("mapWrapIndentMode"), viewSessionFiles[i]._mapPos._wrapIndentMode);
fileNameNode->ToElement()->SetAttribute(TEXT("mapIsWrap"), viewSessionFiles[i]._mapPos._isWrap ? TEXT("yes") : TEXT("no"));

View File

@ -149,8 +149,15 @@ struct MapPosition
int32_t _width = -1;
int32_t _height = -1;
int32_t _wrapIndentMode = -1;
int64_t _KByteInDoc = _maxPeekLenInKB;
bool _isWrap = false;
bool isValid() { return _firstVisibleDisplayLine != -1; };
bool isValid() const { return (_firstVisibleDisplayLine != -1); };
bool canScroll() const { return (_KByteInDoc < _maxPeekLenInKB); }; // _nbCharInDoc < _maxPeekLen : Don't scroll the document for the performance issue
private:
int64_t _maxPeekLenInKB = 512; // 512 KB
};

View File

@ -68,6 +68,7 @@ void DocumentPeeker::goTo(POINT p)
::SetWindowPos(_hSelf, HWND_TOP, p.x, p.y + 10, _rc.right - _rc.left, _rc.bottom - _rc.top, SWP_SHOWWINDOW);
}
void DocumentPeeker::syncDisplay(Buffer *buf, ScintillaEditView & scintSource)
{
if (_pPeekerView)
@ -85,8 +86,10 @@ void DocumentPeeker::syncDisplay(Buffer *buf, ScintillaEditView & scintSource)
// Wraping & scrolling
//
MapPosition mp = buf->getMapPosition();
if (mp.isValid())
if (mp.isValid() && mp.canScroll())
{
scrollSnapshotWith(mp);
}
Buffer *buf = _pPeekerView->getCurrentBuffer();
_pPeekerView->defineDocType(buf->getLangType());
@ -140,7 +143,7 @@ void DocumentPeeker::scrollSnapshotWith(const MapPosition & mapPos)
//
// scroll to the first visible display line
_pPeekerView->execute(SCI_LINESCROLL, 0,mapPos._firstVisibleDisplayLine);
_pPeekerView->execute(SCI_LINESCROLL, 0, mapPos._firstVisibleDisplayLine);
}
}
@ -180,6 +183,9 @@ void DocumentPeeker::saveCurrentSnapshot(ScintillaEditView & editView)
mapPos._higherPos = static_cast<int32_t>(editView.execute(SCI_POSITIONFROMPOINT, 0, 0));
}
// Length of document
mapPos._KByteInDoc = editView.getCurrentDocLen() / 1024;
// set current map position in buffer
buffer->setMapPosition(mapPos);
}