From 047449b4712105e1e0a8dd069943c78192f58b08 Mon Sep 17 00:00:00 2001 From: Gustavo Carneiro Date: Sun, 18 Oct 2020 01:32:29 -0300 Subject: [PATCH] ExtendedCharTable: Remove konsoleprivate dependencies. --- src/ExtendedCharTable.cpp | 17 ++--------------- src/ExtendedCharTable.h | 8 +++++++- src/Screen.cpp | 7 +++++-- 3 files changed, 14 insertions(+), 18 deletions(-) diff --git a/src/ExtendedCharTable.cpp b/src/ExtendedCharTable.cpp index ba157833..4ca90fe9 100644 --- a/src/ExtendedCharTable.cpp +++ b/src/ExtendedCharTable.cpp @@ -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 usedExtendedChars; - const QList sessionsList = SessionManager::instance()->sessions(); - for (const Session *s : sessionsList) { - const QList displayList = s->views(); - for (const QPointer display : displayList) { - usedExtendedChars += display->screenWindow()->screen()->usedExtendedChars(); - } - } + QSet usedExtendedChars = extendedChars(); QHash::iterator it = _extendedCharTable.begin(); QHash::iterator itEnd = _extendedCharTable.end(); diff --git a/src/ExtendedCharTable.h b/src/ExtendedCharTable.h index cc40e9fb..fc5a31c5 100644 --- a/src/ExtendedCharTable.h +++ b/src/ExtendedCharTable.h @@ -10,6 +10,8 @@ // Qt #include +#include + namespace Konsole { /** * A table which stores sequences of unicode characters, referenced @@ -20,6 +22,8 @@ namespace Konsole { class ExtendedCharTable { public: + typedef std::function ()> 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 _extendedCharTable; }; + } + #endif // end of EXTENDEDCHARTABLE_H diff --git a/src/Screen.cpp b/src/Screen.cpp index 8ce41a4c..d3a612c6 100644 --- a/src/Screen.cpp +++ b/src/Screen.cpp @@ -9,6 +9,7 @@ #include "Screen.h" // Qt +#include #include // 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; } }