Qt: Allocate packet list records using wmem.
Add PacketListRecord::operator new, which uses wmem_alloc. Roughly matches the GTK+ UI behavior. Add ColumnTextList which also uses wmem_alloc. Lazily allocate our column text. Change-Id: I86a63cd8ace7764eaab1561bf71b4358af72fe03 Reviewed-on: https://code.wireshark.org/review/16418 Reviewed-by: Gerald Combs <gerald@wireshark.org> Petri-Dish: Gerald Combs <gerald@wireshark.org> Tested-by: Petri Dish Buildbot <buildbot-no-reply@wireshark.org> Reviewed-by: Anders Broman <a.broman58@gmail.com>
This commit is contained in:
parent
ed27ad491d
commit
0d73ae3161
|
@ -27,16 +27,29 @@
|
|||
#include <epan/column-info.h>
|
||||
#include <epan/column.h>
|
||||
#include <epan/conversation.h>
|
||||
#include <epan/wmem/wmem.h>
|
||||
|
||||
#include <epan/color_filters.h>
|
||||
|
||||
#include "frame_tvbuff.h"
|
||||
|
||||
#include <QStringList>
|
||||
|
||||
class ColumnTextList : public QList<const char *> {
|
||||
public:
|
||||
// Allocate our records using wmem.
|
||||
static void *operator new(size_t size) {
|
||||
return wmem_alloc(wmem_file_scope(), size);
|
||||
}
|
||||
|
||||
static void operator delete(void *) {}
|
||||
};
|
||||
|
||||
QMap<int, int> PacketListRecord::cinfo_column_;
|
||||
unsigned PacketListRecord::col_data_ver_ = 1;
|
||||
|
||||
PacketListRecord::PacketListRecord(frame_data *frameData) :
|
||||
col_text_(0),
|
||||
fdata_(frameData),
|
||||
lines_(1),
|
||||
line_count_changed_(false),
|
||||
|
@ -46,6 +59,11 @@ PacketListRecord::PacketListRecord(frame_data *frameData) :
|
|||
{
|
||||
}
|
||||
|
||||
void *PacketListRecord::operator new(size_t size)
|
||||
{
|
||||
return wmem_alloc(wmem_file_scope(), size);
|
||||
}
|
||||
|
||||
// We might want to return a const char * instead. This would keep us from
|
||||
// creating excessive QByteArrays, e.g. in PacketListModel::recordLessThan.
|
||||
const QByteArray PacketListRecord::columnString(capture_file *cap_file, int column, bool colorized)
|
||||
|
@ -58,11 +76,11 @@ const QByteArray PacketListRecord::columnString(capture_file *cap_file, int colu
|
|||
}
|
||||
|
||||
bool dissect_color = colorized && !colorized_;
|
||||
if (column >= col_text_.size() || !col_text_[column] || data_ver_ != col_data_ver_ || dissect_color) {
|
||||
if (!col_text_ || column >= col_text_->size() || !col_text_->at(column) || data_ver_ != col_data_ver_ || dissect_color) {
|
||||
dissect(cap_file, dissect_color);
|
||||
}
|
||||
|
||||
return col_text_.value(column, QByteArray());
|
||||
return col_text_->value(column, QByteArray());
|
||||
}
|
||||
|
||||
void PacketListRecord::resetColumns(column_info *cinfo)
|
||||
|
@ -96,7 +114,9 @@ void PacketListRecord::dissect(capture_file *cap_file, bool dissect_color)
|
|||
gboolean create_proto_tree;
|
||||
struct wtap_pkthdr phdr; /* Packet header */
|
||||
Buffer buf; /* Packet data */
|
||||
gboolean dissect_columns = col_text_.isEmpty() || data_ver_ != col_data_ver_;
|
||||
|
||||
if (!col_text_) col_text_ = new ColumnTextList;
|
||||
gboolean dissect_columns = col_text_->isEmpty() || data_ver_ != col_data_ver_;
|
||||
|
||||
if (!cap_file) {
|
||||
return;
|
||||
|
@ -190,7 +210,11 @@ void PacketListRecord::cacheColumnStrings(column_info *cinfo)
|
|||
return;
|
||||
}
|
||||
|
||||
col_text_.clear();
|
||||
if (col_text_) {
|
||||
col_text_->clear();
|
||||
} else {
|
||||
col_text_ = new ColumnTextList;
|
||||
}
|
||||
lines_ = 1;
|
||||
line_count_changed_ = false;
|
||||
|
||||
|
@ -203,7 +227,7 @@ void PacketListRecord::cacheColumnStrings(column_info *cinfo)
|
|||
/* Column based on frame_data or it already contains a value */
|
||||
if (text_col < 0) {
|
||||
col_fill_in_frame_data(fdata_, cinfo, column, FALSE);
|
||||
col_text_.append(cinfo->columns[column].col_data);
|
||||
col_text_->append(cinfo->columns[column].col_data);
|
||||
continue;
|
||||
}
|
||||
|
||||
|
@ -220,7 +244,7 @@ void PacketListRecord::cacheColumnStrings(column_info *cinfo)
|
|||
// XXX - ui/gtk/packet_list_store.c uses G_MAXUSHORT. We don't do proper UTF8
|
||||
// truncation in either case.
|
||||
int col_text_len = MIN(qstrlen(cinfo->col_data[column]) + 1, COL_MAX_INFO_LEN);
|
||||
col_text_.append(QByteArray::fromRawData(cinfo->columns[column].col_data, col_text_len));
|
||||
col_text_->append(QByteArray::fromRawData(cinfo->columns[column].col_data, col_text_len));
|
||||
break;
|
||||
}
|
||||
/* !! FALL-THROUGH!! */
|
||||
|
@ -247,9 +271,9 @@ void PacketListRecord::cacheColumnStrings(column_info *cinfo)
|
|||
if (!get_column_resolved(column) && cinfo->col_expr.col_expr_val[column]) {
|
||||
/* Use the unresolved value in col_expr_val */
|
||||
// XXX Use QContiguousCache?
|
||||
col_text_.append(cinfo->col_expr.col_expr_val[column]);
|
||||
col_text_->append(cinfo->col_expr.col_expr_val[column]);
|
||||
} else {
|
||||
col_text_.append(cinfo->columns[column].col_data);
|
||||
col_text_->append(cinfo->columns[column].col_data);
|
||||
}
|
||||
break;
|
||||
}
|
||||
|
@ -271,7 +295,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_pool_, col_str));
|
||||
for (int i = 0; col_str[i]; i++) {
|
||||
if (col_str[i] == '\n') col_lines++;
|
||||
}
|
||||
|
|
|
@ -38,10 +38,17 @@
|
|||
struct conversation;
|
||||
struct _GStringChunk;
|
||||
|
||||
class ColumnTextList;
|
||||
|
||||
class PacketListRecord
|
||||
{
|
||||
public:
|
||||
PacketListRecord(frame_data *frameData);
|
||||
|
||||
// Allocate our records using wmem.
|
||||
static void *operator new(size_t size);
|
||||
static void operator delete(void *) {}
|
||||
|
||||
// Return the string value for a column. Data is cached if possible.
|
||||
const QByteArray columnString(capture_file *cap_file, int column, bool colorized = false);
|
||||
frame_data *frameData() const { return fdata_; }
|
||||
|
@ -60,7 +67,7 @@ public:
|
|||
|
||||
private:
|
||||
/** The column text for some columns */
|
||||
QList<const char *> col_text_;
|
||||
ColumnTextList *col_text_;
|
||||
|
||||
frame_data *fdata_;
|
||||
int lines_;
|
||||
|
|
Loading…
Reference in New Issue