Qt: move packet list cache from record to model

Change-Id: Idf6a10374382c8521eb205c801a72af329e5d0d2
Reviewed-on: https://code.wireshark.org/review/31528
Petri-Dish: Michal Labedzki <michal.labedzki@wireshark.org>
Tested-by: Petri Dish Buildbot
Reviewed-by: Anders Broman <a.broman58@gmail.com>
This commit is contained in:
Michał Łabędzki 2019-01-09 18:09:11 +01:00 committed by Anders Broman
parent ace33ff48b
commit b54c9b62e8
4 changed files with 16 additions and 20 deletions

View File

@ -8,6 +8,7 @@
*/
#include <algorithm>
#include <glib.h>
#include "packet_list_model.h"
@ -49,7 +50,6 @@ PacketListModel::PacketListModel(QObject *parent, capture_file *cf) :
idle_dissection_row_(0)
{
setCaptureFile(cf);
PacketListRecord::clearStringPool();
physical_rows_.reserve(reserved_packets_);
visible_rows_.reserve(reserved_packets_);
@ -60,11 +60,14 @@ PacketListModel::PacketListModel(QObject *parent, capture_file *cf) :
this, &PacketListModel::emitItemHeightChanged,
Qt::QueuedConnection);
idle_dissection_timer_ = new QElapsedTimer();
string_cache_pool_ = g_string_chunk_new(1 * 1024 * 1024);
}
PacketListModel::~PacketListModel()
{
delete idle_dissection_timer_;
g_string_chunk_free(string_cache_pool_);
}
void PacketListModel::setCaptureFile(capture_file *cf)
@ -130,7 +133,7 @@ void PacketListModel::clear() {
visible_rows_.resize(0);
new_visible_rows_.resize(0);
number_to_row_.resize(0);
PacketListRecord::clearStringPool();
g_string_chunk_clear(string_cache_pool_);
endResetModel();
max_row_height_ = 0;
max_line_count_ = 1;
@ -697,7 +700,7 @@ void PacketListModel::dissectIdle(bool reset)
// line counts?
gint PacketListModel::appendPacket(frame_data *fdata)
{
PacketListRecord *record = new PacketListRecord(fdata);
PacketListRecord *record = new PacketListRecord(fdata, string_cache_pool_);
gint pos = -1;
#ifdef DEBUG_PACKET_LIST_MODEL

View File

@ -111,6 +111,8 @@ private:
QElapsedTimer *idle_dissection_timer_;
int idle_dissection_row_;
struct _GStringChunk *string_cache_pool_;
bool isNumericColumn(int column);
private slots:

View File

@ -36,14 +36,15 @@ public:
QMap<int, int> PacketListRecord::cinfo_column_;
unsigned PacketListRecord::col_data_ver_ = 1;
PacketListRecord::PacketListRecord(frame_data *frameData) :
PacketListRecord::PacketListRecord(frame_data *frameData, struct _GStringChunk *string_cache_pool) :
col_text_(0),
fdata_(frameData),
lines_(1),
line_count_changed_(false),
data_ver_(0),
colorized_(false),
conv_(NULL)
conv_(NULL),
string_cache_pool_(string_cache_pool)
{
}
@ -197,14 +198,6 @@ void PacketListRecord::dissect(capture_file *cap_file, bool dissect_color)
wtap_rec_cleanup(&rec);
}
// This assumes only one packet list. We might want to move this to
// PacketListModel (or replace this with a wmem allocator).
struct _GStringChunk *PacketListRecord::string_pool_ = g_string_chunk_new(1 * 1024 * 1024);
void PacketListRecord::clearStringPool()
{
g_string_chunk_clear(string_pool_);
}
//#define MINIMIZE_STRING_COPYING 1
void PacketListRecord::cacheColumnStrings(column_info *cinfo)
{
@ -298,7 +291,7 @@ void PacketListRecord::cacheColumnStrings(column_info *cinfo)
// https://git.gnome.org/browse/glib/tree/glib/gstringchunk.c
// We might be better off adding the equivalent functionality to
// wmem_tree.
col_text_->append(g_string_chunk_insert_const(string_pool_, col_str));
col_text_->append(g_string_chunk_insert_const(string_cache_pool_, col_str));
for (int i = 0; col_str[i]; i++) {
if (col_str[i] == '\n') col_lines++;
}

View File

@ -31,7 +31,7 @@ class ColumnTextList;
class PacketListRecord
{
public:
PacketListRecord(frame_data *frameData);
PacketListRecord(frame_data *frameData, struct _GStringChunk *string_cache_pool);
// Allocate our records using wmem.
static void *operator new(size_t size);
@ -52,8 +52,6 @@ public:
inline int lineCount() { return lines_; }
inline int lineCountChanged() { return line_count_changed_; }
static void clearStringPool();
private:
/** The column text for some columns */
ColumnTextList *col_text_;
@ -72,11 +70,11 @@ private:
/** Conversation. Used by RelatedPacketDelegate */
struct conversation *conv_;
struct _GStringChunk *string_cache_pool_;
void dissect(capture_file *cap_file, bool dissect_color = false);
void cacheColumnStrings(column_info *cinfo);
static struct _GStringChunk *string_pool_;
};
#endif // PACKET_LIST_RECORD_H