Improve 200MB+ files loading/editing performance

While loading files over more 200MB, they are all considered as Normal text files, that improve loading speed (for example for huge XML or SQL file).
Also, the feature as braces match, smart highlightingg, tag match and URL colorization are disabled for not penalizing the editing performance.
This commit is contained in:
Don Ho 2022-01-28 19:49:58 +01:00
parent db3308329b
commit 774321e099
4 changed files with 32 additions and 19 deletions

View File

@ -2567,6 +2567,10 @@ void Notepad_plus::findMatchingBracePos(intptr_t& braceAtCaret, intptr_t& braceO
// return true if 1 or 2 (matched) brace(s) is found
bool Notepad_plus::braceMatch()
{
Buffer* currentBuf = _pEditView->getCurrentBuffer();
if (!currentBuf->isLargeFile())
return false;
intptr_t braceAtCaret = -1;
intptr_t braceOpposite = -1;
findMatchingBracePos(braceAtCaret, braceOpposite);
@ -2977,6 +2981,10 @@ bool isUrl(TCHAR * text, int textLen, int start, int* segmentLen)
void Notepad_plus::addHotSpot(ScintillaEditView* view)
{
Buffer* currentBuf = _pEditView->getCurrentBuffer();
if (!currentBuf->isLargeFile())
return;
ScintillaEditView* pView = view ? view : _pEditView;
int urlAction = (NppParameters::getInstance()).getNppGUI()._styleURL;

View File

@ -867,9 +867,10 @@ BOOL Notepad_plus::notify(SCNotification *notification)
if (nppParam._isFindReplacing)
break;
if (notification->nmhdr.hwndFrom != _pEditView->getHSelf()) // notification come from unfocus view - both views ae visible
Buffer* currentBuf = _pEditView->getCurrentBuffer();
if (notification->nmhdr.hwndFrom != _pEditView->getHSelf() && !currentBuf->isLargeFile()) // notification come from unfocus view - both views ae visible
{
//ScintillaEditView * unfocusView = isFromPrimary ? &_subEditView : &_mainEditView;
if (nppGui._smartHiliteOnAnotherView)
{
TCHAR selectedText[1024];
@ -881,13 +882,13 @@ BOOL Notepad_plus::notify(SCNotification *notification)
braceMatch();
if (nppGui._enableTagsMatchHilite)
if (nppGui._enableTagsMatchHilite && !currentBuf->isLargeFile())
{
XmlMatchedTagsHighlighter xmlTagMatchHiliter(_pEditView);
xmlTagMatchHiliter.tagMatch(nppGui._enableTagAttrsHilite);
}
if (nppGui._enableSmartHilite)
if (nppGui._enableSmartHilite && !currentBuf->isLargeFile())
{
if (nppGui._disableSmartHiliteTmp)
nppGui._disableSmartHiliteTmp = false;

View File

@ -62,9 +62,9 @@ namespace // anonymous
} // anonymous namespace
Buffer::Buffer(FileManager * pManager, BufferID id, Document doc, DocFileStatus type, const TCHAR *fileName)
Buffer::Buffer(FileManager * pManager, BufferID id, Document doc, DocFileStatus type, const TCHAR *fileName, bool isLargeFile)
// type must be either DOC_REGULAR or DOC_UNNAMED
: _pManager(pManager) , _id(id), _doc(doc), _lang(L_TEXT)
: _pManager(pManager) , _id(id), _doc(doc), _lang(L_TEXT), _isLargeFile(isLargeFile)
{
NppParameters& nppParamInst = NppParameters::getInstance();
const NewDocDefaultSettings& ndds = (nppParamInst.getNppGUI()).getNewDocDefaultSettings();
@ -82,9 +82,7 @@ Buffer::Buffer(FileManager * pManager, BufferID id, Document doc, DocFileStatus
checkFileState();
// reset after initialization
_isDirty = false;
_canNotify = true;
_needLexer = false; // new buffers do not need lexing, Scintilla takes care of that
}
@ -228,14 +226,21 @@ void Buffer::setFileName(const TCHAR *fn, LangType defaultLang)
updateTimeStamp();
BufferStatusInfo lang2Change = BufferChangeNone;
if (!_hasLangBeenSetFromMenu && (newLang != _lang || _lang == L_USER))
{
_lang = newLang;
doNotify(BufferChangeFilename | BufferChangeLanguage | BufferChangeTimestamp);
return;
if (_isLargeFile)
{
_lang = L_TEXT;
}
else
{
_lang = newLang;
lang2Change = BufferChangeLanguage;
}
}
doNotify(BufferChangeFilename | BufferChangeTimestamp);
doNotify(BufferChangeFilename | BufferChangeTimestamp | lang2Change);
}
@ -711,7 +716,7 @@ BufferID FileManager::loadFile(const TCHAR* filename, Document doc, int encoding
if (res)
{
Buffer* newBuf = new Buffer(this, _nextBufferID, doc, DOC_REGULAR, fullpath);
Buffer* newBuf = new Buffer(this, _nextBufferID, doc, DOC_REGULAR, fullpath, isLargeFile);
BufferID id = static_cast<BufferID>(newBuf);
newBuf->_id = id;
@ -727,8 +732,6 @@ BufferID FileManager::loadFile(const TCHAR* filename, Document doc, int encoding
if (res != 0) // res == 1 or res == -1
newBuf->_timeStamp = fileNameTimestamp;
newBuf->_isLargeFile = isLargeFile;
_buffers.push_back(newBuf);
++_nbBufs;
Buffer* buf = _buffers.at(_nbBufs - 1);
@ -737,7 +740,7 @@ BufferID FileManager::loadFile(const TCHAR* filename, Document doc, int encoding
buf->setEncoding(-1);
// if no file extension, and the language has been detected, we use the detected value
if ((buf->getLangType() == L_TEXT) && (loadedFileFormat._language != L_TEXT))
if (!newBuf->_isLargeFile && ((buf->getLangType() == L_TEXT) && (loadedFileFormat._language != L_TEXT)))
buf->setLangType(loadedFileFormat._language);
setLoadedBufferEncodingAndEol(buf, UnicodeConvertor, loadedFileFormat._encoding, loadedFileFormat._eolFormat);
@ -1249,7 +1252,7 @@ BufferID FileManager::newEmptyDocument()
newTitle += nb;
Document doc = (Document)_pscratchTilla->execute(SCI_CREATEDOCUMENT); //this already sets a reference for filemanager
Buffer* newBuf = new Buffer(this, _nextBufferID, doc, DOC_UNNAMED, newTitle.c_str());
Buffer* newBuf = new Buffer(this, _nextBufferID, doc, DOC_UNNAMED, newTitle.c_str(), false);
BufferID id = static_cast<BufferID>(newBuf);
newBuf->_id = id;
_buffers.push_back(newBuf);
@ -1267,7 +1270,7 @@ BufferID FileManager::bufferFromDocument(Document doc, bool dontIncrease, bool d
if (!dontRef)
_pscratchTilla->execute(SCI_ADDREFDOCUMENT, 0, doc); //set reference for FileManager
Buffer* newBuf = new Buffer(this, _nextBufferID, doc, DOC_UNNAMED, newTitle.c_str());
Buffer* newBuf = new Buffer(this, _nextBufferID, doc, DOC_UNNAMED, newTitle.c_str(), false);
BufferID id = static_cast<BufferID>(newBuf);
newBuf->_id = id;
_buffers.push_back(newBuf);

View File

@ -37,6 +37,7 @@ enum DocFileStatus {
};
enum BufferStatusInfo {
BufferChangeNone = 0x000, // Nothing to change
BufferChangeLanguage = 0x001, // Language was altered
BufferChangeDirty = 0x002, // Buffer has changed dirty state
BufferChangeFormat = 0x004, // EOL type was changed
@ -150,7 +151,7 @@ public:
//Load the document into Scintilla/add to TabBar
//The entire lifetime if the buffer, the Document has reference count of _atleast_ one
//Destructor makes sure its purged
Buffer(FileManager * pManager, BufferID id, Document doc, DocFileStatus type, const TCHAR *fileName);
Buffer(FileManager * pManager, BufferID id, Document doc, DocFileStatus type, const TCHAR *fileName, bool isLargeFile);
// this method 1. copies the file name
// 2. determinates the language from the ext of file name