Commit 047449b4 authored by Gustavo Carneiro's avatar Gustavo Carneiro Committed by Tomaz Canabrava
Browse files

ExtendedCharTable: Remove konsoleprivate dependencies.

parent 55c67162
......@@ -9,12 +9,6 @@
#include "konsoledebug.h"
// Konsole
#include "terminalDisplay/TerminalDisplay.h"
#include "session/SessionManager.h"
#include "session/Session.h"
#include "Screen.h"
using namespace Konsole;
ExtendedCharTable::ExtendedCharTable() :
......@@ -35,7 +29,7 @@ ExtendedCharTable::~ExtendedCharTable()
// global instance
ExtendedCharTable ExtendedCharTable::instance;
uint ExtendedCharTable::createExtendedChar(const uint *unicodePoints, ushort length)
uint ExtendedCharTable::createExtendedChar(const uint *unicodePoints, ushort length, const pExtendedChars extendedChars)
{
// look for this sequence of points in the table
uint hash = extendedCharHash(unicodePoints, length);
......@@ -58,14 +52,7 @@ uint ExtendedCharTable::createExtendedChar(const uint *unicodePoints, ushort len
triedCleaningSolution = true;
// All the hashes are full, go to all Screens and try to free any
// This is slow but should happen very rarely
QSet<uint> usedExtendedChars;
const QList<Session *> sessionsList = SessionManager::instance()->sessions();
for (const Session *s : sessionsList) {
const QList<TerminalDisplay *> displayList = s->views();
for (const QPointer<TerminalDisplay> display : displayList) {
usedExtendedChars += display->screenWindow()->screen()->usedExtendedChars();
}
}
QSet<uint> usedExtendedChars = extendedChars();
QHash<uint, uint *>::iterator it = _extendedCharTable.begin();
QHash<uint, uint *>::iterator itEnd = _extendedCharTable.end();
......
......@@ -10,6 +10,8 @@
// Qt
#include <QHash>
#include <functional>
namespace Konsole {
/**
* A table which stores sequences of unicode characters, referenced
......@@ -20,6 +22,8 @@ namespace Konsole {
class ExtendedCharTable
{
public:
typedef std::function<QSet<uint> ()> pExtendedChars;
/** Constructs a new character table. */
ExtendedCharTable();
~ExtendedCharTable();
......@@ -35,7 +39,7 @@ public:
* @param unicodePoints An array of unicode character points
* @param length Length of @p unicodePoints
*/
uint createExtendedChar(const uint *unicodePoints, ushort length);
uint createExtendedChar(const uint *unicodePoints, ushort length, const pExtendedChars extendedChars);
/**
* Looks up and returns a pointer to a sequence of unicode characters
* which was added to the table using createExtendedChar().
......@@ -61,5 +65,7 @@ private:
// themselves.
QHash<uint, uint *> _extendedCharTable;
};
}
#endif // end of EXTENDEDCHARTABLE_H
......@@ -9,6 +9,7 @@
#include "Screen.h"
// Qt
#include <QSet>
#include <QTextStream>
// Konsole
......@@ -741,7 +742,8 @@ void Screen::displayCharacter(uint c)
if ((currentChar.rendition & RE_EXTENDED_CHAR) == 0) {
const uint chars[2] = { currentChar.character, c };
currentChar.rendition |= RE_EXTENDED_CHAR;
currentChar.character = ExtendedCharTable::instance.createExtendedChar(chars, 2);
auto extChars = [this]() { return usedExtendedChars(); };
currentChar.character = ExtendedCharTable::instance.createExtendedChar(chars, 2, extChars);
} else {
ushort extendedCharLength;
const uint* oldChars = ExtendedCharTable::instance.lookupExtendedChar(currentChar.character, extendedCharLength);
......@@ -752,7 +754,8 @@ void Screen::displayCharacter(uint c)
auto chars = new uint[extendedCharLength + 1];
memcpy(chars, oldChars, sizeof(uint) * extendedCharLength);
chars[extendedCharLength] = c;
currentChar.character = ExtendedCharTable::instance.createExtendedChar(chars, extendedCharLength + 1);
auto extChars = [this]() { return usedExtendedChars(); };
currentChar.character = ExtendedCharTable::instance.createExtendedChar(chars, extendedCharLength + 1, extChars);
delete[] chars;
}
}
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment