Skip to content

Commit

Permalink
Improve 200MB+ files loading/editing performance
Browse files Browse the repository at this point in the history
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.
  • Loading branch information
donho committed Jan 28, 2022
1 parent db33083 commit 774321e
Show file tree
Hide file tree
Showing 4 changed files with 32 additions and 19 deletions.
8 changes: 8 additions & 0 deletions PowerEditor/src/Notepad_plus.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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())

This comment has been minimized.

Copy link
@Yaron10

Yaron10 Jan 28, 2022

Shouldn't it be if (currentBuf->isLargeFile())?

return false;

intptr_t braceAtCaret = -1;
intptr_t braceOpposite = -1;
findMatchingBracePos(braceAtCaret, braceOpposite);
Expand Down Expand Up @@ -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())

This comment has been minimized.

Copy link
@Yaron10

Yaron10 Jan 28, 2022

Shouldn't it be if (currentBuf->isLargeFile())?

This comment has been minimized.

Copy link
@donho

donho Jan 29, 2022

Author Member

You're absolutely right!
Bad copy-paste. Thank you.

return;

ScintillaEditView* pView = view ? view : _pEditView;

int urlAction = (NppParameters::getInstance()).getNppGUI()._styleURL;
Expand Down
9 changes: 5 additions & 4 deletions PowerEditor/src/NppNotification.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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];
Expand All @@ -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;
Expand Down
31 changes: 17 additions & 14 deletions PowerEditor/src/ScintillaComponent/Buffer.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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();
Expand All @@ -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
}


Expand Down Expand Up @@ -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);
}


Expand Down Expand Up @@ -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;

Expand All @@ -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);
Expand All @@ -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);
Expand Down Expand Up @@ -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);
Expand All @@ -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);
Expand Down
3 changes: 2 additions & 1 deletion PowerEditor/src/ScintillaComponent/Buffer.h
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -150,7 +151,7 @@ class Buffer final {
//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
Expand Down

0 comments on commit 774321e

Please sign in to comment.