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

List:       kde-commits
Subject:    [konsole/history-rework] src: Store flag if line is wrapped internally in a QBitArray
From:       Kurt Hindenburg <kurt.hindenburg () gmail ! com>
Date:       2012-02-22 5:00:27
Message-ID: 20120222050027.B3CD6A60A6 () git ! kde ! org
[Download RAW message or body]

Git commit 9c0faa058b96ad9f8b2bb427d9dfb5628bf767ab by Kurt Hindenburg.
Committed on 22/02/2012 at 05:59.
Pushed by hindenburg into branch 'history-rework'.

Store flag if line is wrapped internally in a QBitArray

For HistoryFile, the lineWrapped was stored in a temp file which seems
way overkill.

The resize() of the QBitArray seems awkward.

M  +9    -6    src/History.cpp
M  +2    -1    src/History.h

http://commits.kde.org/konsole/9c0faa058b96ad9f8b2bb427d9dfb5628bf767ab

diff --git a/src/History.cpp b/src/History.cpp
index 2b883cb..37e5816 100644
--- a/src/History.cpp
+++ b/src/History.cpp
@@ -200,6 +200,7 @@ bool HistoryScroll::hasScroll()
 HistoryScrollFile::HistoryScrollFile(const QString& logFileName)
     : HistoryScroll(new HistoryTypeFile(logFileName))
 {
+    lineWrapped.resize(200);
 }
 
 HistoryScrollFile::~HistoryScrollFile()
@@ -219,9 +220,7 @@ int HistoryScrollFile::getLineLen(int lineno)
 bool HistoryScrollFile::isWrappedLine(int lineno)
 {
     if (lineno >= 0 && lineno <= getLines()) {
-        unsigned char flag;
-        lineflags.get((unsigned char*)&flag, sizeof(unsigned char), (lineno)*sizeof(unsigned char));
-        return flag;
+        return lineWrapped.testBit(lineno);
     }
     return false;
 }
@@ -246,9 +245,13 @@ void HistoryScrollFile::addCells(const Character text[], int count)
 
 void HistoryScrollFile::addLine(bool previousWrapped)
 {
-    lineIndices<<(quint32)cells.len();
-    unsigned char flags = previousWrapped ? 0x01 : 0x00;
-    lineflags.add((unsigned char*)&flags, sizeof(unsigned char));
+    const quint32 row = lineIndices.size();
+    const quint32 index = (quint32)cells.len();
+    lineIndices<<index;
+    if (row >= lineWrapped.size()) {
+        lineWrapped.resize(lineWrapped.size() + 200);
+    }
+    lineWrapped.setBit(row, previousWrapped);
 }
 
 // History Scroll None //////////////////////////////////////
diff --git a/src/History.h b/src/History.h
index 76235ff..ad81db2 100644
--- a/src/History.h
+++ b/src/History.h
@@ -28,6 +28,7 @@
 #include <QtCore/QList>
 #include <QtCore/QVector>
 #include <QtCore/QTemporaryFile>
+#include <QBitArray>
 
 // Konsole
 #include "Character.h"
@@ -143,8 +144,8 @@ private:
     int startOfLine(int lineno);
 
     QList<quint32> lineIndices; // Index of each line
+    QBitArray lineWrapped; // is line wrapped?
     HistoryFile cells; // text  Row(Character)
-    HistoryFile lineflags; // flags Row(unsigned char)
 };
 
 //////////////////////////////////////////////////////////////////////
[prev in list] [next in list] [prev in thread] [next in thread] 

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