aboutsummaryrefslogtreecommitdiffhomepage
diff options
context:
space:
mode:
authorZufu Liu <unknown>2022-12-21 08:48:45 +1100
committerZufu Liu <unknown>2022-12-21 08:48:45 +1100
commit61508c02e7e2ea4de857a2be604e1d80222083c1 (patch)
treed6cdd35a3f1c9df729430a36ea707600975de041
parentdb320f1668fceec9c625ac5ccdf9864200386f0e (diff)
downloadscintilla-mirror-61508c02e7e2ea4de857a2be604e1d80222083c1.tar.gz
Bug [#2340]. Avoid repeated call in GetFoldParent for around 10% performance
gain with Visual C++ 64-bit release mode on 300,000 line file. Remove duplicated code and simplify. GetFoldLevel and thus GetFoldParent can't throw so mark as noexcept.
-rw-r--r--src/Document.cxx22
-rw-r--r--src/Document.h4
2 files changed, 10 insertions, 16 deletions
diff --git a/src/Document.cxx b/src/Document.cxx
index 00ac8e618..2d1acd7e1 100644
--- a/src/Document.cxx
+++ b/src/Document.cxx
@@ -558,7 +558,7 @@ int SCI_METHOD Document::GetLevel(Sci_Position line) const {
return Levels()->GetLevel(line);
}
-FoldLevel Document::GetFoldLevel(Sci_Position line) const {
+FoldLevel Document::GetFoldLevel(Sci_Position line) const noexcept {
return static_cast<FoldLevel>(Levels()->GetLevel(line));
}
@@ -597,21 +597,15 @@ Sci::Line Document::GetLastChild(Sci::Line lineParent, std::optional<FoldLevel>
return lineMaxSubord;
}
-Sci::Line Document::GetFoldParent(Sci::Line line) const {
+Sci::Line Document::GetFoldParent(Sci::Line line) const noexcept {
const FoldLevel level = LevelNumberPart(GetFoldLevel(line));
- Sci::Line lineLook = line - 1;
- while ((lineLook > 0) && (
- (!LevelIsHeader(GetFoldLevel(lineLook))) ||
- (LevelNumberPart(GetFoldLevel(lineLook)) >= level))
- ) {
- lineLook--;
- }
- if (LevelIsHeader(GetFoldLevel(lineLook)) &&
- (LevelNumberPart(GetFoldLevel(lineLook)) < level)) {
- return lineLook;
- } else {
- return -1;
+ for (Sci::Line lineLook = line - 1; lineLook >= 0; lineLook--) {
+ const FoldLevel levelTry = GetFoldLevel(lineLook);
+ if (LevelIsHeader(levelTry) && LevelNumberPart(levelTry) < level) {
+ return lineLook;
+ }
}
+ return -1;
}
void Document::GetHighlightDelimiters(HighlightDelimiter &highlightDelimiter, Sci::Line line, Sci::Line lastLine) {
diff --git a/src/Document.h b/src/Document.h
index 3b0c8ab5a..8d5643e90 100644
--- a/src/Document.h
+++ b/src/Document.h
@@ -461,10 +461,10 @@ public:
int SCI_METHOD SetLevel(Sci_Position line, int level) override;
int SCI_METHOD GetLevel(Sci_Position line) const override;
- Scintilla::FoldLevel GetFoldLevel(Sci_Position line) const;
+ Scintilla::FoldLevel GetFoldLevel(Sci_Position line) const noexcept;
void ClearLevels();
Sci::Line GetLastChild(Sci::Line lineParent, std::optional<Scintilla::FoldLevel> level = {}, Sci::Line lastLine = -1);
- Sci::Line GetFoldParent(Sci::Line line) const;
+ Sci::Line GetFoldParent(Sci::Line line) const noexcept;
void GetHighlightDelimiters(HighlightDelimiter &highlightDelimiter, Sci::Line line, Sci::Line lastLine);
Sci::Position ExtendWordSelect(Sci::Position pos, int delta, bool onlyWordCharacters=false) const;