Do not free the membuffer, reuse it

This is an attempt to make fewer calls to alloc functions when the mouse
is moving.

We were creating a membuffer, filling it (malloc / realloc), then freeing
it just after use. but we could simply hold that allocated area and reuse
it again.

Signed-off-by: Tomaz Canabrava <tomaz.canabrava@intel.com>
Signed-off-by: Dirk Hohndel <dirk@hohndel.org>
This commit is contained in:
Tomaz Canabrava 2015-01-14 22:18:20 -02:00 committed by Dirk Hohndel
parent dc7397b06e
commit 54898b15ff

View file

@ -234,14 +234,16 @@ void ToolTipItem::refresh(const QPointF &pos)
struct plot_data *entry; struct plot_data *entry;
static QPixmap tissues(16,60); static QPixmap tissues(16,60);
static QPainter painter(&tissues); static QPainter painter(&tissues);
static struct membuffer mb = { 0 };
int time = timeAxis->valueAt(pos); int time = timeAxis->valueAt(pos);
if (time == lastTime) if (time == lastTime)
return; return;
lastTime = time; lastTime = time;
clear(); clear();
struct membuffer mb = { 0 };
mb.len = 0;
entry = get_plot_details_new(&pInfo, time, &mb); entry = get_plot_details_new(&pInfo, time, &mb);
if (entry) { if (entry) {
tissues.fill(); tissues.fill();
@ -262,7 +264,6 @@ void ToolTipItem::refresh(const QPointF &pos)
} }
addToolTip(QString::fromUtf8(mb.buffer, mb.len),QIcon(), tissues); addToolTip(QString::fromUtf8(mb.buffer, mb.len),QIcon(), tissues);
} }
free_buffer(&mb);
Q_FOREACH (QGraphicsItem *item, scene()->items(pos, Qt::IntersectsItemBoundingRect Q_FOREACH (QGraphicsItem *item, scene()->items(pos, Qt::IntersectsItemBoundingRect
,Qt::DescendingOrder, scene()->views().first()->transform())) { ,Qt::DescendingOrder, scene()->views().first()->transform())) {