summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorRhys Weatherley <rhys.weatherley@nokia.com>2009-10-02 01:38:10 (GMT)
committerRhys Weatherley <rhys.weatherley@nokia.com>2009-10-02 01:38:10 (GMT)
commitad90350d0ba3971591554f871ec17544be414038 (patch)
tree4a60d321ee52242f092d0a96fed5e114d8147ff3
parent53b3a0572242d0a425e74848afba1293f195d29b (diff)
downloadQt-ad90350d0ba3971591554f871ec17544be414038.zip
Qt-ad90350d0ba3971591554f871ec17544be414038.tar.gz
Qt-ad90350d0ba3971591554f871ec17544be414038.tar.bz2
Remove QHash overhead from QGLShareRegister
Move the list of shared contexts from QGLShareRegister into QGLContextGroup. There is then no need for the QHash. Reviewed-by: trustme
-rw-r--r--src/opengl/qgl.cpp40
-rw-r--r--src/opengl/qgl_p.h8
2 files changed, 20 insertions, 28 deletions
diff --git a/src/opengl/qgl.cpp b/src/opengl/qgl.cpp
index 665290c..0402268 100644
--- a/src/opengl/qgl.cpp
+++ b/src/opengl/qgl.cpp
@@ -4860,44 +4860,40 @@ void QGLShareRegister::addShare(const QGLContext *context, const QGLContext *sha
return;
// Make sure 'context' is not already shared with another group of contexts.
- Q_ASSERT(reg.find(context->d_ptr->group) == reg.end());
Q_ASSERT(context->d_ptr->group->m_refs == 1);
// Free 'context' group resources and make it use the same resources as 'share'.
+ QGLContextGroup *group = share->d_ptr->group;
delete context->d_ptr->group;
- context->d_ptr->group = share->d_ptr->group;
- context->d_ptr->group->m_refs.ref();
+ context->d_ptr->group = group;
+ group->m_refs.ref();
// Maintain a list of all the contexts in each group of sharing contexts.
- SharingHash::iterator it = reg.find(share->d_ptr->group);
- if (it == reg.end())
- it = reg.insert(share->d_ptr->group, ContextList() << share);
- it.value() << context;
+ // The list is empty if the "share" context wasn't sharing already.
+ if (group->m_shares.isEmpty())
+ group->m_shares.append(share);
+ group->m_shares.append(context);
}
QList<const QGLContext *> QGLShareRegister::shares(const QGLContext *context) {
- SharingHash::const_iterator it = reg.find(context->d_ptr->group);
- if (it == reg.end())
- return ContextList();
- return it.value();
+ return context->d_ptr->group->m_shares;
}
void QGLShareRegister::removeShare(const QGLContext *context) {
- SharingHash::iterator it = reg.find(context->d_ptr->group);
- if (it == reg.end())
+ // Remove the context from the group.
+ QGLContextGroup *group = context->d_ptr->group;
+ if (group->m_shares.isEmpty())
return;
-
- int count = it.value().removeAll(context);
- Q_ASSERT(count == 1);
- Q_UNUSED(count);
+ group->m_shares.removeAll(context);
// Update context group representative.
- if (context->d_ptr->group->m_context == context)
- context->d_ptr->group->m_context = it.value().first();
+ Q_ASSERT(group->m_shares.size() != 0);
+ if (group->m_context == context)
+ group->m_context = group->m_shares[0];
- Q_ASSERT(it.value().size() != 0);
- if (it.value().size() == 1)
- reg.erase(it);
+ // If there is only one context left, then make the list empty.
+ if (group->m_shares.size() == 1)
+ group->m_shares.clear();
}
QGLContextResource::QGLContextResource(FreeFunc f, QObject *parent)
diff --git a/src/opengl/qgl_p.h b/src/opengl/qgl_p.h
index 991c948..1957429 100644
--- a/src/opengl/qgl_p.h
+++ b/src/opengl/qgl_p.h
@@ -233,6 +233,7 @@ private:
QGLExtensionFuncs m_extensionFuncs;
const QGLContext *m_context; // context group's representative
+ QList<const QGLContext *> m_shares;
QAtomicInt m_refs;
friend class QGLShareRegister;
@@ -401,16 +402,11 @@ class Q_AUTOTEST_EXPORT QGLShareRegister
{
public:
QGLShareRegister() {}
- ~QGLShareRegister() { reg.clear(); }
+ ~QGLShareRegister() {}
void addShare(const QGLContext *context, const QGLContext *share);
QList<const QGLContext *> shares(const QGLContext *context);
void removeShare(const QGLContext *context);
-private:
- // Use a context's 'group' pointer to uniquely identify a group.
- typedef QList<const QGLContext *> ContextList;
- typedef QHash<const QGLContextGroup *, ContextList> SharingHash;
- SharingHash reg;
};
extern Q_OPENGL_EXPORT QGLShareRegister* qgl_share_reg();