Skip to content

Commit 205b8d1

Browse files
committed
optimizations for large file handling
1 parent e9105f1 commit 205b8d1

File tree

3 files changed

+31
-7
lines changed

3 files changed

+31
-7
lines changed

src/MainWindow.cpp

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3425,6 +3425,8 @@ void CMainWindow::AddHotSpots() const
34253425
auto lineCount = m_editor.Scintilla().LineCount();
34263426
auto endPos = m_editor.Scintilla().PositionFromLine(m_editor.Scintilla().DocLineFromVisible(firstVisibleLine + min(linesOnScreen, lineCount)));
34273427

3428+
if (startPos < 0 || endPos < 0)
3429+
return;
34283430
// to speed up the search, first search for "://" without using the regex engine
34293431
auto fStartPos = startPos;
34303432
auto fEndPos = endPos;

src/ScintillaWnd.cpp

Lines changed: 26 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -90,6 +90,7 @@ CScintillaWnd::CScintillaWnd(HINSTANCE hInst)
9090
, m_bCursorShown(true)
9191
, m_bScratch(false)
9292
, m_eraseBkgnd(true)
93+
, m_hugeLevelReached(false)
9394
, m_cursorTimeout(-1)
9495
, m_bInFolderMargin(false)
9596
, m_hasConsolas(false)
@@ -1023,7 +1024,7 @@ void CScintillaWnd::RestoreCurrentPos(const CPosData& pos)
10231024
UpdateLineNumberWidth();
10241025
}
10251026

1026-
void CScintillaWnd::SetupLexerForLang(const std::string& lang) const
1027+
void CScintillaWnd::SetupLexerForLang(const std::string& lang)
10271028
{
10281029
const auto& lexerData = CLexStyles::Instance().GetLexerDataForLang(lang);
10291030
const auto& keywords = CLexStyles::Instance().GetKeywordsForLang(lang);
@@ -1103,6 +1104,14 @@ void CScintillaWnd::SetupLexerForLang(const std::string& lang) const
11031104
{
11041105
m_scintilla.SetProperty(propName.c_str(), propValue.c_str());
11051106
}
1107+
auto length = m_scintilla.Length();
1108+
m_hugeLevelReached = false;
1109+
if (length > 500 * 1024 * 1024)
1110+
{
1111+
// turn off folding
1112+
m_scintilla.SetProperty("fold", "0");
1113+
m_hugeLevelReached = true;
1114+
}
11061115
for (const auto& [styleId, styleData] : lexerData.styles)
11071116
{
11081117
m_scintilla.StyleSetFore(styleId, theme.GetThemeColor(styleData.foregroundColor, true));
@@ -1476,16 +1485,17 @@ void CScintillaWnd::MarkSelectedWord(bool clear, bool edit)
14761485
m_scintilla.SetIndicatorCurrent(INDIC_SELECTION_MARK);
14771486
m_scintilla.IndicatorClearRange(startStylePos, len);
14781487

1479-
auto sSelText = m_scintilla.GetSelText();
1480-
auto selTextLen = sSelText.size();
1481-
if ((selTextLen == 0) || (clear))
1488+
auto selSpan = m_scintilla.SelectionSpan();
1489+
if (clear || selSpan.Length() == 0 || selSpan.Length() + 10000)
14821490
{
14831491
lastSelText.clear();
14841492
m_docScroll.Clear(DOCSCROLLTYPE_SELTEXT);
14851493
m_selTextMarkerCount = 0;
14861494
SendMessage(*this, WM_NCPAINT, static_cast<WPARAM>(1), 0);
14871495
return;
14881496
}
1497+
auto sSelText = m_scintilla.GetSelText();
1498+
auto selTextLen = sSelText.size();
14891499
auto origSelStart = m_scintilla.SelectionStart();
14901500
auto origSelEnd = m_scintilla.SelectionEnd();
14911501
auto selStartLine = m_scintilla.LineFromPosition(origSelStart);
@@ -1692,7 +1702,8 @@ void CScintillaWnd::MatchBraces(BraceMatch what)
16921702
SetTimer(*this, TIM_BRACEHIGHLIGHTTEXT, 1000, nullptr);
16931703
}
16941704

1695-
if ((what == BraceMatch::Highlight) && (m_scintilla.IndentationGuides() != Scintilla::IndentView::None))
1705+
if ((braceAtCaret >= 0) && (braceOpposite >= 0) && (what == BraceMatch::Highlight) &&
1706+
(m_scintilla.IndentationGuides() != Scintilla::IndentView::None))
16961707
{
16971708
auto columnAtCaret = m_scintilla.Column(braceAtCaret);
16981709
auto columnOpposite = m_scintilla.Column(braceOpposite);
@@ -2548,6 +2559,16 @@ void CScintillaWnd::ReflectEvents(SCNotification* pScn)
25482559
case SCN_SAVEPOINTREACHED:
25492560
EnableChangeHistory();
25502561
break;
2562+
case SCN_MODIFIED:
2563+
if (pScn->modificationType & SC_MOD_INSERTTEXT)
2564+
{
2565+
if (!m_hugeLevelReached && m_scintilla.Length() > 500 * 1024 * 1024)
2566+
{
2567+
// turn off folding
2568+
m_scintilla.SetProperty("fold", "0");
2569+
m_hugeLevelReached = true;
2570+
}
2571+
}
25512572
default:
25522573
break;
25532574
}

src/ScintillaWnd.h

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
// This file is part of BowPad.
22
//
3-
// Copyright (C) 2013-2022 - Stefan Kueng
3+
// Copyright (C) 2013-2022, 2024 - Stefan Kueng
44
//
55
// This program is free software: you can redistribute it and/or modify
66
// it under the terms of the GNU General Public License as published by
@@ -99,7 +99,7 @@ class CScintillaWnd : public CWindow
9999
void UpdateLineNumberWidth() const;
100100
void SaveCurrentPos(CPosData& pos);
101101
void RestoreCurrentPos(const CPosData& pos);
102-
void SetupLexerForLang(const std::string& lang) const;
102+
void SetupLexerForLang(const std::string& lang);
103103
void MarginClick(SCNotification* pNotification);
104104
void SelectionUpdated() const;
105105
void MarkSelectedWord(bool clear, bool edit);
@@ -162,6 +162,7 @@ class CScintillaWnd : public CWindow
162162
bool m_bCursorShown;
163163
bool m_bScratch;
164164
bool m_eraseBkgnd;
165+
bool m_hugeLevelReached;
165166
int m_cursorTimeout;
166167
bool m_bInFolderMargin;
167168
bool m_hasConsolas;

0 commit comments

Comments
 (0)