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
3bfe6125
Commit
3bfe6125
authored
Mar 03, 2021
by
Carlos Alves
Browse files
Change CompactHistoryBlockList pointer to unique pointer
Obs.: Qt containers can't use unique_ptr, I'm using std container.
parent
94505d94
Changes
2
Hide whitespace changes
Inline
Side-by-side
src/history/compact/CompactHistoryBlockList.cpp
View file @
3bfe6125
...
...
@@ -12,53 +12,44 @@
using
namespace
Konsole
;
CompactHistoryBlockList
::
CompactHistoryBlockList
()
:
list
(
QList
<
CompactHistoryBlock
*>
()
)
:
_blocks
()
{
}
void
*
CompactHistoryBlockList
::
allocate
(
size_t
size
)
{
CompactHistoryBlock
*
block
;
if
(
list
.
isEmpty
()
||
list
.
last
()
->
remaining
()
<
size
)
{
block
=
new
CompactHistoryBlock
();
list
.
append
(
block
);
////qDebug() << "new block created, remaining " << block->remaining() << "number of blocks=" << list.size();
}
else
{
block
=
list
.
last
();
////qDebug() << "old block used, remaining " << block->remaining();
if
(
_blocks
.
empty
()
||
_blocks
.
back
()
->
remaining
()
<
size
)
{
_blocks
.
push_back
(
std
::
make_unique
<
CompactHistoryBlock
>
());
////qDebug() << "new block created, remaining " << block->remaining() << "number of blocks=" << _blocks.size();
}
return
block
->
allocate
(
size
);
return
_
block
s
.
back
()
->
allocate
(
size
);
}
void
CompactHistoryBlockList
::
deallocate
(
void
*
ptr
)
{
Q_ASSERT
(
!
list
.
isE
mpty
());
Q_ASSERT
(
!
_blocks
.
e
mpty
());
int
i
=
0
;
CompactHistoryBlock
*
block
=
list
.
at
(
i
);
while
(
i
<
list
.
size
()
&&
!
block
->
contains
(
ptr
))
{
i
++
;
block
=
list
.
at
(
i
);
auto
block
=
_blocks
.
begin
();
while
(
block
!=
_blocks
.
end
()
&&
!
(
*
block
)
->
contains
(
ptr
))
{
block
++
;
}
Q_ASSERT
(
i
<
list
.
size
());
Q_ASSERT
(
block
!=
_blocks
.
end
());
block
->
deallocate
();
(
*
block
)
->
deallocate
();
if
(
!
block
->
isInUse
())
{
list
.
removeAt
(
i
);
delete
block
;
if
(
!
(
*
block
)
->
isInUse
())
{
_blocks
.
erase
(
block
);
////qDebug() << "block deleted, new size = " << list.size();
}
}
int
CompactHistoryBlockList
::
length
()
{
return
list
.
size
();
return
_blocks
.
size
();
}
CompactHistoryBlockList
::~
CompactHistoryBlockList
()
{
qDeleteAll
(
list
.
begin
(),
list
.
end
());
list
.
clear
();
_blocks
.
clear
();
}
src/history/compact/CompactHistoryBlockList.h
View file @
3bfe6125
...
...
@@ -7,7 +7,9 @@
#ifndef COMPACTHISTORYBLOCKLIST_H
#define COMPACTHISTORYBLOCKLIST_H
#include <QList>
#include <memory>
#include <vector>
#include "CompactHistoryBlock.h"
namespace
Konsole
...
...
@@ -24,7 +26,7 @@ public:
int
length
();
private:
QList
<
CompactHistoryBlock
*>
list
;
std
::
vector
<
std
::
unique_ptr
<
CompactHistoryBlock
>>
_blocks
;
};
}
...
...
Write
Preview
Markdown
is supported
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