Commit d5701be9 authored by Adam Reichold's avatar Adam Reichold Committed by Albert Astals Cid

Replace GooHash by std::unordered_map in OutputDev.

parent f559cc94
......@@ -39,6 +39,7 @@
// Copyright (C) 2012 Lu Wang <coolwanglu@gmail.com>
// Copyright (C) 2014 Jason Crain <jason@aquaticape.us>
// Copyright (C) 2017, 2018 Klarälvdalens Datakonsult AB, a KDAB Group company, <info@kdab.com>. Work sponsored by the LiMux project of the city of Munich
// Copyright (C) 2018 Adam Reichold <adam.reichold@t-online.de>
//
// To see a description of the changes please see the Changelog file that
// came with your tarball or type make ChangeLog if you are building from git
......@@ -59,7 +60,6 @@
#include <memory>
#include "goo/gmem.h"
#include "goo/GooTimer.h"
#include "goo/GooHash.h"
#include "GlobalParams.h"
#include "CharTypes.h"
#include "Object.h"
......@@ -748,21 +748,9 @@ void Gfx::go(GBool topLevel) {
// Update the profile information
if (unlikely(profileCommands)) {
GooHash *hash;
hash = out->getProfileHash ();
if (hash) {
GooString *cmd_g;
ProfileData *data_p;
cmd_g = new GooString (obj.getCmd());
data_p = (ProfileData *)hash->lookup (cmd_g);
if (data_p == nullptr) {
data_p = new ProfileData();
hash->add (cmd_g, data_p);
}
data_p->addElement(timer->getElapsed ());
if (auto* const hash = out->getProfileHash()) {
auto& data = (*hash)[obj.getCmd()];
data.addElement(timer->getElapsed());
}
delete timer;
}
......
......@@ -19,6 +19,7 @@
// Copyright (C) 2009 Carlos Garcia Campos <carlosgc@gnome.org>
// Copyright (C) 2009, 2012, 2013 Albert Astals Cid <aacid@kde.org>
// Copyright (C) 2012 Thomas Freitag <Thomas.Freitag@alfa.de>
// Copyright (C) 2018 Adam Reichold <adam.reichold@t-online.de>
//
// To see a description of the changes please see the Changelog file that
// came with your tarball or type make ChangeLog if you are building from git
......@@ -36,7 +37,6 @@
#include "Stream.h"
#include "GfxState.h"
#include "OutputDev.h"
#include "goo/GooHash.h"
//------------------------------------------------------------------------
// OutputDev
......@@ -179,18 +179,11 @@ void OutputDev::opiEnd(GfxState *state, Dict *opiDict) {
#endif
void OutputDev::startProfile() {
if (profileHash)
delete profileHash;
profileHash = new GooHash (true);
profileHash.reset(new std::unordered_map<std::string, ProfileData>);
}
GooHash *OutputDev::endProfile() {
GooHash *profile = profileHash;
profileHash = nullptr;
return profile;
std::unique_ptr<std::unordered_map<std::string, ProfileData>> OutputDev::endProfile() {
return std::move(profileHash);
}
#ifdef USE_CMS
......
......@@ -25,6 +25,7 @@
// Copyright (C) 2012 William Bader <williambader@hotmail.com>
// Copyright (C) 2017, 2018 Oliver Sander <oliver.sander@tu-dresden.de>
// Copyright (C) 2018 Klarlvdalens Datakonsult AB, a KDAB Group company, <info@kdab.com>. Work sponsored by the LiMux project of the city of Munich
// Copyright (C) 2018 Adam Reichold <adam.reichold@t-online.de>
//
// To see a description of the changes please see the Changelog file that
// came with your tarball or type make ChangeLog if you are building from git
......@@ -43,10 +44,13 @@
#include "CharTypes.h"
#include "Object.h"
#include "PopplerCache.h"
#include "ProfileData.h"
#include <memory>
#include <unordered_map>
#include <string>
class Annot;
class Dict;
class GooHash;
class GooString;
class GfxState;
class Gfx;
......@@ -80,7 +84,6 @@ public:
: iccColorSpaceCache(5)
#endif
{
profileHash = nullptr;
}
// Destructor.
......@@ -333,9 +336,9 @@ public:
virtual void psXObject(Stream * /*psStream*/, Stream * /*level1Stream*/) {}
//----- Profiling
virtual void startProfile();
virtual GooHash *getProfileHash() {return profileHash; }
virtual GooHash *endProfile();
void startProfile();
std::unordered_map<std::string, ProfileData>* getProfileHash() const { return profileHash.get(); }
std::unique_ptr<std::unordered_map<std::string, ProfileData>> endProfile();
//----- transparency groups and soft masks
virtual GBool checkTransparencyGroup(GfxState * /*state*/, GBool /*knockout*/) { return gTrue; }
......@@ -365,7 +368,7 @@ private:
double defCTM[6]; // default coordinate transform matrix
double defICTM[6]; // inverse of default CTM
GooHash *profileHash;
std::unique_ptr<std::unordered_map<std::string, ProfileData>> profileHash;
#ifdef USE_CMS
PopplerCache iccColorSpaceCache;
......
......@@ -25,6 +25,7 @@
// Copyright (C) 2011, 2014, 2017 Adrian Johnson <ajohnson@redneon.com>
// Copyright (C) 2012 Fabio D'Urso <fabiodurso@hotmail.it>
// Copyright (C) 2018 Klarälvdalens Datakonsult AB, a KDAB Group company, <info@kdab.com>. Work sponsored by the LiMux project of the city of Munich
// Copyright (C) 2018 Adam Reichold <adam.reichold@t-online.de>
//
// To see a description of the changes please see the Changelog file that
// came with your tarball or type make ChangeLog if you are building from git
......@@ -48,7 +49,7 @@
#include <map>
#include <vector>
class GHooash;
class GooHash;
class PDFDoc;
class XRef;
class Function;
......
......@@ -3,6 +3,7 @@
// ProfileData.cc
//
// Copyright 2005 Jonathan Blandford <jrb@gnome.org>
// Copyright 2018 Adam Reichold <adam.reichold@t-online.de>
//
//========================================================================
......@@ -12,21 +13,12 @@
#pragma implementation
#endif
#include <stdlib.h>
#include <stddef.h>
#include "ProfileData.h"
//------------------------------------------------------------------------
// ProfileData
//------------------------------------------------------------------------
ProfileData::ProfileData() {
count = 0;
total = 0.0;
min = 0.0;
max = 0.0;
}
void
ProfileData::addElement (double elapsed) {
if (count == 0) {
......
......@@ -3,6 +3,7 @@
// ProfileData.h
//
// Copyright 2005 Jonathan Blandford <jrb@gnome.org>
// Copyright 2018 Adam Reichold <adam.reichold@t-online.de>
//
//========================================================================
......@@ -19,23 +20,17 @@
class ProfileData {
public:
// Constructor.
ProfileData ();
// Destructor.
~ProfileData() {}
void addElement (double elapsed);
int getCount () { return count; }
double getTotal () { return total; }
double getMin () { return max; }
double getMax () { return max; }
int getCount () const { return count; }
double getTotal () const { return total; }
double getMin () const { return max; }
double getMax () const { return max; }
private:
int count; // size of <elems> array
double total; // number of elements in array
double min; // reference count
double max; // reference count
int count = 0; // size of <elems> array
double total = 0.0; // number of elements in array
double min = 0.0; // reference count
double max = 0.0; // reference count
};
#endif
......@@ -3,6 +3,7 @@
// pdf-inspector.cc
//
// Copyright 2005 Jonathan Blandford <jrb@redhat.com>
// Copyright 2018 Adam Reichold <adam.reichold@t-online.de>
//
//========================================================================
......@@ -13,7 +14,6 @@
#endif
#include <goo/gmem.h>
#include <goo/GooHash.h>
#include <goo/GooTimer.h>
#include <splash/SplashTypes.h>
#include <splash/SplashBitmap.h>
......@@ -214,10 +214,6 @@ PdfInspector::on_analyze_clicked (GtkWidget *widget, PdfInspector *inspector)
void
PdfInspector::analyze_page (int page)
{
GooHashIter *iter;
GooHash *hash;
GooString *key;
void *p;
GtkWidget *label;
char *text;
cairo_t *cr;
......@@ -245,24 +241,21 @@ PdfInspector::analyze_page (int page)
g_free (text);
// Individual times;
hash = output->endProfile ();
hash->startIter(&iter);
while (hash->getNext(&iter, &key, &p))
auto hash = output->endProfile ();
for (const auto& kvp : *hash)
{
GtkTreeIter tree_iter;
ProfileData *data_p = (ProfileData *) p;
const auto* const data_p = &kvp.second;
gtk_list_store_append (GTK_LIST_STORE (model), &tree_iter);
gtk_list_store_set (GTK_LIST_STORE (model), &tree_iter,
OP_STRING, key->getCString(),
OP_STRING, kvp.first.c_str (),
OP_COUNT, data_p->getCount (),
OP_TOTAL, data_p->getTotal (),
OP_MIN, data_p->getMin (),
OP_MAX, data_p->getMax (),
-1);
}
hash->killIter(&iter);
deleteGooHash (hash, ProfileData);
}
void
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment