Skip to content
GitLab
Menu
Projects
Groups
Snippets
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
Menu
Open sidebar
Utilities
Konsole
Commits
07c69ba7
Commit
07c69ba7
authored
Jan 04, 2021
by
Carlos Alves
Browse files
Reduce the number of loops to Reflow
Reduce the number of needed loops to reflow the lines to increase preformance.
parent
48aef6ab
Changes
3
Hide whitespace changes
Inline
Side-by-side
src/Screen.cpp
View file @
07c69ba7
...
...
@@ -79,9 +79,7 @@ Screen::Screen(int lines, int columns):
{
_escapeSequenceUrlExtractor
->
setScreen
(
this
);
_lineProperties
.
resize
(
_lines
+
1
);
for
(
int
i
=
0
;
i
<
_lines
+
1
;
i
++
)
{
_lineProperties
[
i
]
=
LINE_DEFAULT
;
}
std
::
fill
(
_lineProperties
.
begin
(),
_lineProperties
.
end
(),
LINE_DEFAULT
);
initTabStops
();
clearSelection
();
...
...
@@ -440,12 +438,12 @@ void Screen::resizeImage(int new_lines, int new_columns)
fastAddHistLine
();
cursorLine
--
;
}
// Join
everything in _history
// Join
the line and move the data to next line if needed
currentPos
=
0
;
while
(
currentPos
<
_history
->
getLines
()
-
1
)
{
// if it's true, join the line with next line
while
(
currentPos
<
_history
->
getLines
())
{
int
curr_linelen
=
_history
->
getLineLen
(
currentPos
);
// Join wrapped line in current history position
if
(
_history
->
isWrappedLine
(
currentPos
))
{
int
curr_linelen
=
_history
->
getLineLen
(
currentPos
);
int
next_linelen
=
_history
->
getLineLen
(
currentPos
+
1
);
auto
*
new_line
=
getCharacterBuffer
(
curr_linelen
+
next_linelen
);
bool
new_line_property
=
_history
->
isWrappedLine
(
currentPos
+
1
);
...
...
@@ -460,12 +458,6 @@ void Screen::resizeImage(int new_lines, int new_columns)
_history
->
removeCells
(
currentPos
+
1
);
continue
;
}
currentPos
++
;
}
// Now move data to next line if needed
currentPos
=
0
;
while
(
currentPos
<
_history
->
getLines
())
{
int
curr_linelen
=
_history
->
getLineLen
(
currentPos
);
// if the current line > new_columns it will need a new line
if
(
curr_linelen
>
new_columns
)
{
...
...
@@ -494,10 +486,10 @@ void Screen::resizeImage(int new_lines, int new_columns)
}
if
(
_enableReflowLines
)
{
//
Join everything in screenLines
.
//
Analize the lines and move the data to lines below
.
currentPos
=
0
;
while
(
currentPos
<
cursorLine
&&
currentPos
<
_screenLines
.
count
()
-
1
)
{
//
if the line have the 'LINE_WRAPPED' property, concat with the next line and remove it.
//
Join wrapped line in current position
if
((
_lineProperties
[
currentPos
]
&
LINE_WRAPPED
)
!=
0
)
{
_screenLines
[
currentPos
].
append
(
_screenLines
[
currentPos
+
1
]);
_screenLines
.
remove
(
currentPos
+
1
);
...
...
@@ -505,20 +497,15 @@ void Screen::resizeImage(int new_lines, int new_columns)
cursorLine
--
;
continue
;
}
currentPos
++
;
}
// Then move the data to lines below.
currentPos
=
0
;
while
(
currentPos
<
cursorLine
&&
currentPos
<
_screenLines
.
count
())
{
// Ignore whitespaces at the end of the line
int
lineSize
=
_screenLines
[
currentPos
].
size
();
while
(
lineSize
>
0
&&
QChar
(
_screenLines
[
currentPos
][
lineSize
-
1
].
character
).
isSpace
())
{
lineSize
--
;
}
const
bool
shouldCopy
=
lineSize
>
new_columns
;
//
C
opy from the current line, to the next one.
if
(
shouldCopy
)
{
//
If need to move to line below, c
opy from the current line, to the next one.
if
(
lineSize
>
new_columns
)
{
auto
values
=
_screenLines
[
currentPos
].
mid
(
new_columns
);
_screenLines
[
currentPos
].
remove
(
new_columns
,
values
.
size
());
_lineProperties
.
insert
(
currentPos
+
1
,
_lineProperties
[
currentPos
]);
...
...
src/history/compact/CompactHistoryLine.cpp
View file @
07c69ba7
...
...
@@ -25,14 +25,13 @@ CompactHistoryLine::CompactHistoryLine(const TextLine &line, CompactHistoryBlock
_formatLength
(
0
),
_wrapped
(
false
)
{
_length
=
line
.
size
();
if
(
!
line
.
isEmpty
())
{
_length
=
line
.
size
();
_formatLength
=
1
;
int
k
=
1
;
// count number of different formats in this text line
Character
c
=
line
[
0
];
int
k
=
0
;
while
(
k
<
_length
)
{
if
(
!
(
line
[
k
].
equalsFormat
(
c
)))
{
_formatLength
++
;
// format change detected
...
...
@@ -41,40 +40,26 @@ CompactHistoryLine::CompactHistoryLine(const TextLine &line, CompactHistoryBlock
k
++
;
}
////qDebug() << "number of different formats in string: " << _formatLength;
_formatArray
=
static_cast
<
CharacterFormat
*>
(
_blockListRef
.
allocate
(
sizeof
(
CharacterFormat
)
*
_formatLength
));
Q_ASSERT
(
_formatArray
!=
nullptr
);
_text
=
static_cast
<
uint
*>
(
_blockListRef
.
allocate
(
sizeof
(
uint
)
*
line
.
size
()));
Q_ASSERT
(
_text
!=
nullptr
);
_length
=
line
.
size
();
_wrapped
=
false
;
// record formats and their positions in the format array
c
=
line
[
0
];
_formatArray
[
0
].
setFormat
(
c
);
_formatArray
[
0
].
startPos
=
0
;
// there's always at least 1 format (for the entire line, unless a change happens)
k
=
1
;
// look for possible format changes
int
j
=
1
;
while
(
k
<
_length
&&
j
<
_formatLength
)
{
if
(
!
(
line
[
k
].
equalsFormat
(
c
)))
{
c
=
line
[
k
];
_formatArray
[
j
].
setFormat
(
c
);
_formatArray
[
j
].
startPos
=
k
;
////qDebug() << "format entry " << j << " at pos " << _formatArray[j].startPos << " " << &(_formatArray[j].startPos) ;
j
++
;
_formatArray
[
0
].
startPos
=
0
;
for
(
int
i
=
0
,
k
=
1
;
i
<
_length
;
i
++
)
{
if
(
!
line
[
i
].
equalsFormat
(
c
))
{
c
=
line
[
i
];
_formatArray
[
k
].
setFormat
(
c
);
_formatArray
[
k
].
startPos
=
i
;
k
++
;
}
k
++
;
}
// copy character values
for
(
int
i
=
0
;
i
<
line
.
size
();
i
++
)
{
_text
[
i
]
=
line
[
i
].
character
;
////qDebug() << "char " << i << " at mem " << &(text[i]);
}
_wrapped
=
false
;
}
////qDebug() << "line created, length " << length << " at " << &(length);
}
CompactHistoryLine
::~
CompactHistoryLine
()
...
...
@@ -86,28 +71,25 @@ CompactHistoryLine::~CompactHistoryLine()
_blockListRef
.
deallocate
(
this
);
}
void
CompactHistoryLine
::
getCharacter
(
int
index
,
Character
&
r
)
{
Q_ASSERT
(
index
<
_length
);
int
formatPos
=
0
;
while
((
formatPos
+
1
)
<
_formatLength
&&
index
>=
_formatArray
[
formatPos
+
1
].
startPos
)
{
formatPos
++
;
}
r
.
character
=
_text
[
index
];
r
.
rendition
=
_formatArray
[
formatPos
].
rendition
;
r
.
foregroundColor
=
_formatArray
[
formatPos
].
fgColor
;
r
.
backgroundColor
=
_formatArray
[
formatPos
].
bgColor
;
r
.
isRealCharacter
=
_formatArray
[
formatPos
].
isRealCharacter
;
}
void
CompactHistoryLine
::
getCharacters
(
Character
*
array
,
int
size
,
int
startColumn
)
{
Q_ASSERT
(
startColumn
>=
0
&&
size
>=
0
);
Q_ASSERT
(
startColumn
+
size
<=
static_cast
<
int
>
(
getLength
()));
int
formatPos
=
0
;
while
((
formatPos
+
1
)
<
_formatLength
&&
startColumn
>=
_formatArray
[
formatPos
+
1
].
startPos
)
{
formatPos
++
;
}
for
(
int
i
=
startColumn
;
i
<
size
+
startColumn
;
i
++
)
{
getCharacter
(
i
,
array
[
i
-
startColumn
]);
if
((
formatPos
+
1
)
<
_formatLength
&&
i
==
_formatArray
[
formatPos
+
1
].
startPos
)
{
formatPos
++
;
}
array
[
i
-
startColumn
]
=
Character
(
_text
[
i
],
_formatArray
[
formatPos
].
fgColor
,
_formatArray
[
formatPos
].
bgColor
,
_formatArray
[
formatPos
].
rendition
,
_formatArray
[
formatPos
].
isRealCharacter
);
}
}
...
...
src/history/compact/CompactHistoryLine.h
View file @
07c69ba7
...
...
@@ -28,7 +28,6 @@ public:
static
void
operator
delete
(
void
*
);
virtual
void
getCharacters
(
Character
*
array
,
int
size
,
int
startColumn
);
virtual
void
getCharacter
(
int
index
,
Character
&
r
);
virtual
bool
isWrapped
()
const
;
virtual
void
setWrapped
(
bool
value
);
virtual
unsigned
int
getLength
()
const
;
...
...
Write
Preview
Supports
Markdown
0%
Try again
or
attach a new file
.
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment