[prev in list] [next in list] [prev in thread] [next in thread] 

List:       kde-commits
Subject:    KDE/kdelibs/kate/part
From:       Christoph Cullmann <cullmann () kde ! org>
Date:       2007-05-05 10:22:32
Message-ID: 1178360552.254556.30670.nullmailer () svn ! kde ! org
[Download RAW message or body]

SVN commit 661356 by cullmann:

use vector, even more error checking..., speed is here no issue, the qvector overhead \
is better than later memory probs...

 M  +10 -5     katedocument.cpp  


--- trunk/KDE/kdelibs/kate/part/katedocument.cpp #661355:661356
@@ -1793,14 +1793,14 @@
 
     // init hay line ring buffer
     int hayLinesZeroIndex = 0;
-    KateTextLine::Ptr * hayLinesWindow = new KateTextLine::Ptr[numNeedleLines];
+    QVector<KateTextLine::Ptr> hayLinesWindow;
     for (int i = 0; i < numNeedleLines; i++) {
       KateTextLine::Ptr textLine = m_buffer->plainLine((backwards ? forMax : forMin) \
+ i);  
       if (!textLine)
         return KTextEditor::Range::invalid();
     
-      hayLinesWindow[i] = textLine;
+      hayLinesWindow.append (textLine);
       kDebug() << "searchText | hayLinesWindow[" << i << "] = \"" << \
hayLinesWindow[i]->string() << "\"" << endl;  }
 
@@ -1841,7 +1841,6 @@
           if (matches && (foundAt == 0) && !((k == lastLine)
               && (static_cast<uint>(foundAt + myMatchLen) > maxRight))) // full \
match!  {
-            delete [] hayLinesWindow;
             kDebug() << "searchText | [" << j << " + " << k << "] line " << j + k << \
                ": yes" << endl;
             return KTextEditor::Range(j, startCol, j + k, needleLine.length());
           }
@@ -1864,7 +1863,14 @@
         if (backwards)
         {
           hayLinesZeroIndex = (hayLinesZeroIndex + numNeedleLines - 1) % \
                numNeedleLines;
-          hayLinesWindow[hayLinesZeroIndex] = m_buffer->plainLine(j - 1);
+          
+          KateTextLine::Ptr textLine = m_buffer->plainLine(j - 1);
+      
+          if (!textLine)
+            return KTextEditor::Range::invalid();
+        
+          hayLinesWindow[hayLinesZeroIndex] = textLine;
+          
           kDebug() << "searchText | filling slot " << hayLinesZeroIndex << " with \
                line "
             << j - 1 << ": " << hayLinesWindow[hayLinesZeroIndex]->string() << endl;
         }
@@ -1879,7 +1885,6 @@
     }
 
     // not found
-    delete [] hayLinesWindow;
     return KTextEditor::Range::invalid();
   }
   else


[prev in list] [next in list] [prev in thread] [next in thread] 

Configure | About | News | Add a list | Sponsored by KoreLogic