Commit 1c977621 authored by Jan Möbius's avatar Jan Möbius
Browse files

Cache row in BaseObject for speeding up object traversal. Slows down deletion at the same time

git-svn-id: http://www.openflipper.org/svnrepo/OpenFlipper/branches/Free@15194 383ad7c9-94d9-4d36-a494-682f7c89f535
parent 35a89604
......@@ -60,6 +60,9 @@
#include <OpenFlipper/BasePlugin/PluginFunctions.hh>
#include <QFileInfo>
#ifdef USE_OPENMP
#include <omp.h>
#endif
//== TYPEDEFS =================================================================
......@@ -82,9 +85,11 @@ BaseObject::BaseObject(const BaseObject& _object) :
flags_(_object.flags_),
visible_(_object.visible_),
parentItem_(0),
row_(0),
path_("."),
filename_("")
{
// Increase id generator as we created a new object
++idGenerator;
......@@ -140,6 +145,7 @@ BaseObject::BaseObject(BaseObject* _parent) :
flags_(),
visible_(true),
parentItem_(_parent),
row_(0),
name_("NONAME")
{
id_ = idGenerator;
......@@ -458,10 +464,7 @@ int BaseObject::level() {
int BaseObject::row() const
{
if (parentItem_)
return parentItem_->childItems_.indexOf(const_cast<BaseObject*>(this));
return 0;
return row_;
}
BaseObject* BaseObject::parent()
......@@ -493,9 +496,10 @@ void BaseObject::setParent(BaseObject* _parent) {
void BaseObject::appendChild(BaseObject *item)
{
if ( !childItems_.contains(item) )
if ( !childItems_.contains(item) ) {
childItems_.append(item);
else
item->row_ = childItems_.size() - 1;
} else
std::cerr << "Warning! Trying to append a child twice! Remove the append calls from your File plugin!" << std::endl;
}
......@@ -543,21 +547,22 @@ BaseObject* BaseObject::childExists(QString _name) {
void BaseObject::removeChild( BaseObject* _item ) {
bool found = false;
QList<BaseObject*>::iterator i;
for (i = childItems_.begin(); i != childItems_.end(); ++i) {
if ( *i == _item ) {
found = true;
break;
}
}
int idx = (_item != 0) ? _item->row_ : -1;
if ( !found ) {
std::cerr << "Illegal remove request" << std::endl;
if ( (idx < 0) || (idx >= childItems_.size()) || (childItems_[idx] != _item) ) {
std::cerr << "BaseObject: Illegal removeChild request" << std::endl;
return;
}
childItems_.erase(i);
childItems_.removeAt(idx);
#ifdef USE_OPENMP
#pragma omp parallel for
#endif
for ( int i = idx ; i < childItems_.size(); ++i ) {
--(childItems_[idx]->row_);
}
}
QList< BaseObject* > BaseObject::getLeafs() {
......@@ -592,23 +597,6 @@ void BaseObject::deleteSubtree() {
}
// TreeItem* TreeItem::inConsistent() {
//
// BaseObjectData* object;
//
// // If id is -1 this is a group or rootitem so dont stop here
// if ( (objectId_ != -1) && !PluginFunctions::getObject(objectId_,object) )
// return this;
//
// for ( int i = 0 ; i < childItems.size(); ++i ) {
// TreeItem* tmp = childItems[i]->inConsistent();
// if ( tmp != 0)
// return tmp;
// }
//
// return 0;
// }
// ===============================================================================
// Grouping
// ===============================================================================
......
......@@ -339,6 +339,11 @@ class DLLEXPORTONLY BaseObject : public QObject {
/// Set the parent pointer
void setParent(BaseObject* _parent);
private:
// Cache the row in the parents array for speed efficiency
int row_;
/** @} */
//===========================================================================
......
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