OSDN Git Service

Preliminary exit (performance optimization) for Scrollbars calculation (#1574)
authorYurii Hordiienko <45203053+hordi@users.noreply.github.com>
Wed, 16 Nov 2022 23:14:17 +0000 (18:14 -0500)
committerGitHub <noreply@github.com>
Wed, 16 Nov 2022 23:14:17 +0000 (08:14 +0900)
* Add files via upload

optimized scrollbar calculation for big files

* Update ccrystaltextview.cpp

build error due wrong prev change

Externals/crystaledit/editlib/ccrystaltextview.cpp
Externals/crystaledit/editlib/ccrystaltextview.h
Externals/crystaledit/editlib/ccrystaltextview2.cpp

index f0d7d7e..3b8b26d 100644 (file)
@@ -3310,6 +3310,17 @@ GetMaxLineLength (int nTopLine, int nLines)
   return nMaxLineLength;
 }
 
+bool CCrystalTextView::
+CoverLength(int nTopLine, int nLines, int min_length)
+{
+    const int nLineCount = (std::min)(nTopLine + nLines, GetLineCount());
+    for (int I = nTopLine; I != nLineCount; I++) {
+        if (GetLineActualLength(I) >= min_length)
+            return true;
+    }
+    return false;
+}
+
 CCrystalTextView *CCrystalTextView::
 GetSiblingView (int nRow, int nCol)
 {
@@ -3888,8 +3899,8 @@ AttachToBuffer (CCrystalTextBuffer * pBuf /*= nullptr*/ )
                                          ESB_DISABLE_BOTH : ESB_ENABLE_BOTH);
   CScrollBar *pHorzScrollBarCtrl = GetScrollBarCtrl (SB_HORZ);
   if (pHorzScrollBarCtrl != nullptr)
-    pHorzScrollBarCtrl->EnableScrollBar (GetScreenChars () >= GetMaxLineLength (m_nTopLine, GetScreenLines())?
-                                         ESB_DISABLE_BOTH : ESB_ENABLE_BOTH);
+      pHorzScrollBarCtrl->EnableScrollBar(CoverLength(m_nTopLine, GetScreenLines(), GetScreenChars()) ?
+          ESB_DISABLE_BOTH : ESB_ENABLE_BOTH);
 
   //  Update scrollbars
   InvalidateVertScrollBar ();
index 9eae12c..fae9c39 100644 (file)
@@ -406,6 +406,7 @@ protected :
     //END SW
     int GetCharWidth ();
     int GetMaxLineLength (int nTopLine, int nLines);
+    bool CoverLength(int nTopLine, int nLines, int min_length);
     int GetScreenLines ();
     int GetScreenChars ();
 
index e775652..dd74a2e 100644 (file)
@@ -478,7 +478,7 @@ ScrollLeft ()
 void CCrystalTextView::
 ScrollRight ()
 {
-  if (m_nOffsetChar < GetMaxLineLength (m_nTopLine, GetScreenLines()) - 1)
+  if (CoverLength(m_nTopLine, GetScreenLines(), m_nOffsetChar))
     {
       ScrollToChar (m_nOffsetChar + 1);
       UpdateCaret ();