Reduce TQString allocation/deallocation load in populateControlElementDataFromWidget

Remove unneeded mutex locks around certain TQString operations
pull/2/head
Timothy Pearson 11 years ago
parent 1ee1ffbae6
commit eced6bf82e

@ -140,6 +140,27 @@ static const char * const check_list_controller_xpm[] = {
" ",
" "};
// Increase speed by avoiding constant allocation/deallocation of commonly used strings
static QString QPushButton_static_string("QPushButton");
static QString QToolButton_static_string("QToolButton");
static QString QButton_static_string("QButton");
static QString QTabBar_static_string("QTabBar");
static QString QTitleBar_static_string("QTitleBar");
static QString QToolBox_static_string("QToolBox");
static QString QProgressBar_static_string("QProgressBar");
static QString QPopupMenu_static_string("QPopupMenu");
static QString QComboBox_static_string("QComboBox");
static QString QCheckBox_static_string("QCheckBox");
static QString QRadioButton_static_string("QRadioButton");
static QString QHeader_static_string("QHeader");
static QString QScrollBar_static_string("QScrollBar");
static QString QSlider_static_string("QSlider");
static QString QDialogButtons_static_string("QDialogButtons");
static QString QSpinWidget_static_string("QSpinWidget");
static QString QListView_static_string("QListView");
static QString QDockWindow_static_string("QDockWindow");
static QString QFrame_static_string("QFrame");
#include <qmetaobject.h>
QStringList getObjectTypeListForObject(const QObject* object) {
@ -163,7 +184,7 @@ QStyle::ControlElementFlags getControlElementFlagsForObject(const QObject* objec
QStyle::ControlElementFlags cef = QStyle::CEF_None;
if (object) {
if (objectTypeList.contains("QPushButton")) {
if (objectTypeList.contains(QPushButton_static_string)) {
const QPushButton *button = dynamic_cast<const QPushButton*>(object);
if (button) {
if (button->isDefault()) cef = cef | QStyle::CEF_IsDefault;
@ -173,7 +194,7 @@ QStyle::ControlElementFlags getControlElementFlagsForObject(const QObject* objec
if (button->isFlat()) cef = cef | QStyle::CEF_IsFlat;
}
}
if (objectTypeList.contains("QToolButton")) {
if (objectTypeList.contains(QToolButton_static_string)) {
const QToolButton *button = dynamic_cast<const QToolButton*>(object);
if (button) {
if (button->isToggleButton()) cef = cef | QStyle::CEF_BiState;
@ -182,7 +203,7 @@ QStyle::ControlElementFlags getControlElementFlagsForObject(const QObject* objec
if (button->popup()) cef = cef | QStyle::CEF_HasPopupMenu;
}
}
if (objectTypeList.contains("QButton")) {
if (objectTypeList.contains(QButton_static_string)) {
const QButton *button = dynamic_cast<const QButton*>(object);
if (button) {
if (button->isDown()) cef = cef | QStyle::CEF_IsDown;
@ -190,39 +211,39 @@ QStyle::ControlElementFlags getControlElementFlagsForObject(const QObject* objec
if (button->isToggleButton()) cef = cef | QStyle::CEF_BiState;
}
}
if (objectTypeList.contains("QTabBar")) {
if (objectTypeList.contains(QTabBar_static_string)) {
const QTabBar *tb = dynamic_cast<const QTabBar*>(object);
QTab * t = opt.tab();
if ((t) && (tb)) {
if (t->identifier() == tb->currentTab()) cef = cef | QStyle::CEF_IsActive;
}
}
if (objectTypeList.contains("QTitleBar")) {
if (objectTypeList.contains(QTitleBar_static_string)) {
const QTitleBar *tb = dynamic_cast<const QTitleBar*>(object);
if (tb) {
if (tb->isActive()) cef = cef | QStyle::CEF_IsActive;
}
}
if (objectTypeList.contains("QToolBox")) {
if (objectTypeList.contains(QToolBox_static_string)) {
const QToolBox *tb = dynamic_cast<const QToolBox*>(object);
if (tb) {
if (!tb->currentItem()) cef = cef | QStyle::CEF_IsContainerEmpty;
}
}
if (objectTypeList.contains("QProgressBar")) {
if (objectTypeList.contains(QProgressBar_static_string)) {
const QProgressBar *pb = dynamic_cast<const QProgressBar*>(object);
if (pb) {
if (pb->centerIndicator()) cef = cef | QStyle::CEF_CenterIndicator;
if (pb->indicatorFollowsStyle()) cef = cef | QStyle::CEF_IndicatorFollowsStyle;
}
}
if (objectTypeList.contains("QPopupMenu")) {
if (objectTypeList.contains(QPopupMenu_static_string)) {
const QPopupMenu *pm = dynamic_cast<const QPopupMenu*>(object);
if (pm) {
if (pm->isCheckable()) cef = cef | QStyle::CEF_IsCheckable;
}
}
if (objectTypeList.contains("QComboBox")) {
if (objectTypeList.contains(QComboBox_static_string)) {
const QComboBox *cb = dynamic_cast<const QComboBox*>(object);
if (cb) {
if (cb->editable()) cef = cef | QStyle::CEF_IsEditable;
@ -295,7 +316,7 @@ QStyleControlElementData populateControlElementDataFromWidget(const QWidget* wid
ceData.name = widget->name();
ceData.caption = widget->caption();
if (!populateMinimumNumberOfFields) {
if (ceData.widgetObjectTypes.contains("QPushButton")) {
if (ceData.widgetObjectTypes.contains(QPushButton_static_string)) {
const QPushButton *button = dynamic_cast<const QPushButton*>(widget);
if (button) {
QIconSet* iconSet = 0;
@ -310,7 +331,7 @@ QStyleControlElementData populateControlElementDataFromWidget(const QWidget* wid
}
}
}
if (ceData.widgetObjectTypes.contains("QToolButton")) {
if (ceData.widgetObjectTypes.contains(QToolButton_static_string)) {
const QToolButton *button = dynamic_cast<const QToolButton*>(widget);
if (button) {
const QPixmap* fgPixmap = 0;
@ -324,7 +345,7 @@ QStyleControlElementData populateControlElementDataFromWidget(const QWidget* wid
ceData.popupDelay = button->popupDelay();
}
}
if (ceData.widgetObjectTypes.contains("QCheckBox")) {
if (ceData.widgetObjectTypes.contains(QCheckBox_static_string)) {
const QCheckBox *button = dynamic_cast<const QCheckBox*>(widget);
if (button) {
const QPixmap* fgPixmap = 0;
@ -334,7 +355,7 @@ QStyleControlElementData populateControlElementDataFromWidget(const QWidget* wid
}
}
}
if (ceData.widgetObjectTypes.contains("QRadioButton")) {
if (ceData.widgetObjectTypes.contains(QRadioButton_static_string)) {
const QRadioButton *button = dynamic_cast<const QRadioButton*>(widget);
if (button) {
const QPixmap* fgPixmap = 0;
@ -344,7 +365,7 @@ QStyleControlElementData populateControlElementDataFromWidget(const QWidget* wid
}
}
}
if (ceData.widgetObjectTypes.contains("QButton")) {
if (ceData.widgetObjectTypes.contains(QButton_static_string)) {
const QButton *button = dynamic_cast<const QButton*>(widget);
if (button) {
ceData.text = button->text();
@ -355,7 +376,7 @@ QStyleControlElementData populateControlElementDataFromWidget(const QWidget* wid
}
}
}
if (ceData.widgetObjectTypes.contains("QTabBar")) {
if (ceData.widgetObjectTypes.contains(QTabBar_static_string)) {
const QTabBar *tb = dynamic_cast<const QTabBar*>(widget);
if (tb) {
ceData.tabBarData.tabCount = tb->count();
@ -403,7 +424,7 @@ QStyleControlElementData populateControlElementDataFromWidget(const QWidget* wid
}
}
}
if (ceData.widgetObjectTypes.contains("QToolBox")) {
if (ceData.widgetObjectTypes.contains(QToolBox_static_string)) {
const QToolBox *tb = dynamic_cast<const QToolBox*>(widget);
if (tb) {
const QWidget* currentItem = tb->currentItem();
@ -412,7 +433,7 @@ QStyleControlElementData populateControlElementDataFromWidget(const QWidget* wid
}
}
}
if (ceData.widgetObjectTypes.contains("QProgressBar")) {
if (ceData.widgetObjectTypes.contains(QProgressBar_static_string)) {
const QProgressBar *pb = dynamic_cast<const QProgressBar*>(widget);
if (pb) {
ceData.currentStep = pb->progress();
@ -422,7 +443,7 @@ QStyleControlElementData populateControlElementDataFromWidget(const QWidget* wid
ceData.orientation = pb->orientation();
}
}
if (ceData.widgetObjectTypes.contains("QHeader")) {
if (ceData.widgetObjectTypes.contains(QHeader_static_string)) {
const QHeader *header = dynamic_cast<const QHeader*>(widget);
if (header) {
int section = opt.headerSection();
@ -435,7 +456,7 @@ QStyleControlElementData populateControlElementDataFromWidget(const QWidget* wid
}
}
// Complex Controls
if (ceData.widgetObjectTypes.contains("QScrollBar")) {
if (ceData.widgetObjectTypes.contains(QScrollBar_static_string)) {
const QScrollBar *sb = dynamic_cast<const QScrollBar*>(widget);
if (sb) {
ceData.orientation = sb->orientation();
@ -450,7 +471,7 @@ QStyleControlElementData populateControlElementDataFromWidget(const QWidget* wid
}
}
}
if (ceData.widgetObjectTypes.contains("QSlider")) {
if (ceData.widgetObjectTypes.contains(QSlider_static_string)) {
const QSlider *sl = dynamic_cast<const QSlider*>(widget);
if (sl) {
ceData.orientation = sl->orientation();
@ -467,7 +488,7 @@ QStyleControlElementData populateControlElementDataFromWidget(const QWidget* wid
}
}
}
if (ceData.widgetObjectTypes.contains("QDialogButtons")) {
if (ceData.widgetObjectTypes.contains(QDialogButtons_static_string)) {
const QDialogButtons *dlgbtns = dynamic_cast<const QDialogButtons*>(widget);
if (dlgbtns) {
ceData.orientation = dlgbtns->orientation();
@ -481,7 +502,7 @@ QStyleControlElementData populateControlElementDataFromWidget(const QWidget* wid
}
}
if (ceData.widgetObjectTypes.contains("QTitleBar")) {
if (ceData.widgetObjectTypes.contains(QTitleBar_static_string)) {
const QTitleBar *tb = dynamic_cast<const QTitleBar*>(widget);
if (tb) {
ceData.titleBarData.hasWindow = !!(tb->window());
@ -494,7 +515,7 @@ QStyleControlElementData populateControlElementDataFromWidget(const QWidget* wid
ceData.titleBarData.visibleText = tb->visibleText();
}
}
if (ceData.widgetObjectTypes.contains("QSpinWidget")) {
if (ceData.widgetObjectTypes.contains(QSpinWidget_static_string)) {
const QSpinWidget *sw = dynamic_cast<const QSpinWidget*>(widget);
if (sw) {
ceData.spinWidgetData.buttonSymbols = sw->buttonSymbols();
@ -504,7 +525,7 @@ QStyleControlElementData populateControlElementDataFromWidget(const QWidget* wid
ceData.spinWidgetData.downEnabled = sw->isDownEnabled();
}
}
if (ceData.widgetObjectTypes.contains("QListView")) {
if (ceData.widgetObjectTypes.contains(QListView_static_string)) {
const QListView *lv = dynamic_cast<const QListView*>(widget);
if (lv) {
ceData.listViewData.rootDecorated = lv->rootIsDecorated();
@ -546,7 +567,7 @@ QStyleControlElementData populateControlElementDataFromWidget(const QWidget* wid
}
}
}
if (ceData.widgetObjectTypes.contains("QComboBox")) {
if (ceData.widgetObjectTypes.contains(QComboBox_static_string)) {
const QComboBox *cb = dynamic_cast<const QComboBox*>(widget);
if (cb) {
const QLineEdit* lineEdit = cb->lineEdit();
@ -559,7 +580,7 @@ QStyleControlElementData populateControlElementDataFromWidget(const QWidget* wid
}
}
}
if (ceData.widgetObjectTypes.contains("QFrame")) {
if (ceData.widgetObjectTypes.contains(QFrame_static_string)) {
const QFrame *frame = dynamic_cast<const QFrame*>(widget);
if (frame) {
ceData.frameStyle = frame->frameStyle();
@ -2776,7 +2797,7 @@ int QCommonStyle::pixelMetric(PixelMetric m, const QStyleControlElementData &ceD
if ( ceData.wflags & WStyle_Tool ) {
ret = QMAX( QFontMetrics(ceData.font).lineSpacing(), 16 );
#ifndef QT_NO_MAINWINDOW
} else if ( ceData.widgetObjectTypes.contains("QDockWindow") ) {
} else if ( ceData.widgetObjectTypes.contains(QDockWindow_static_string) ) {
ret = QMAX( QFontMetrics(ceData.font).lineSpacing(), 13 );
#endif
} else {
@ -2924,7 +2945,7 @@ int QCommonStyle::pixelMetric(PixelMetric m, const QStyleControlElementData &ceD
#ifndef QT_NO_TABBAR
case PM_TabBarTabVSpace:
{
if ( ceData.widgetObjectTypes.contains("QTabBar") && ( ceData.tabBarData.shape == QTabBar::RoundedAbove ||
if ( ceData.widgetObjectTypes.contains(QTabBar_static_string) && ( ceData.tabBarData.shape == QTabBar::RoundedAbove ||
ceData.tabBarData.shape == QTabBar::RoundedBelow ) )
ret = 10;
else

@ -1048,13 +1048,9 @@ QStringData::QStringData() : QShared(),
islatin1(FALSE),
security_unpaged(FALSE) {
#ifdef QT_THREAD_SUPPORT
mutex = new QMutex( TRUE );
mutex->lock();
mutex = new QMutex(FALSE);
#endif // QT_THREAD_SUPPORT
ref();
#ifdef QT_THREAD_SUPPORT
mutex->unlock();
#endif // QT_THREAD_SUPPORT
}
QStringData::QStringData(QChar *u, uint l, uint m) : QShared(),
@ -1066,7 +1062,7 @@ QStringData::QStringData(QChar *u, uint l, uint m) : QShared(),
islatin1(FALSE),
security_unpaged(FALSE) {
#ifdef QT_THREAD_SUPPORT
mutex = new QMutex( TRUE );
mutex = new QMutex(FALSE);
#endif // QT_THREAD_SUPPORT
}
@ -1494,13 +1490,6 @@ QString::QString() :
d(0)
{
d = shared_null ? shared_null : makeSharedNull();
#ifdef QT_THREAD_SUPPORT
d->mutex->lock();
#endif // QT_THREAD_SUPPORT
d->ref();
#ifdef QT_THREAD_SUPPORT
d->mutex->unlock();
#endif // QT_THREAD_SUPPORT
}
/*!
@ -1519,15 +1508,15 @@ QString::QString( QChar ch )
QString::QString( const QString &s ) :
d(s.d)
{
if (d != shared_null) {
#ifdef QT_THREAD_SUPPORT
d->mutex->lock();
d->mutex->lock();
#endif // QT_THREAD_SUPPORT
d->ref();
d->ref();
#ifdef QT_THREAD_SUPPORT
d->mutex->unlock();
d->mutex->unlock();
#endif // QT_THREAD_SUPPORT
}
}
/*!
@ -1550,13 +1539,6 @@ QString::QString( int size, bool /*dummy*/ )
d = new QStringData( uc, 0, l );
} else {
d = shared_null ? shared_null : (shared_null=new QStringData);
#ifdef QT_THREAD_SUPPORT
d->mutex->lock();
#endif // QT_THREAD_SUPPORT
d->ref();
#ifdef QT_THREAD_SUPPORT
d->mutex->unlock();
#endif // QT_THREAD_SUPPORT
}
}
@ -1598,13 +1580,6 @@ QString::QString( const QChar* unicode, uint length )
{
if ( !unicode && !length ) {
d = shared_null ? shared_null : makeSharedNull();
#ifdef QT_THREAD_SUPPORT
d->mutex->lock();
#endif // QT_THREAD_SUPPORT
d->ref();
#ifdef QT_THREAD_SUPPORT
d->mutex->unlock();
#endif // QT_THREAD_SUPPORT
}
else {
QChar* uc = QT_ALLOC_QCHAR_VEC( length );
@ -1689,22 +1664,19 @@ QString::~QString()
}
#endif
if (d == shared_null) {
return;
}
#ifdef QT_THREAD_SUPPORT
d->mutex->lock();
#endif // QT_THREAD_SUPPORT
if ( d->deref() ) {
if ( d != shared_null ) {
#ifdef QT_THREAD_SUPPORT
d->mutex->unlock();
#endif // QT_THREAD_SUPPORT
d->deleteSelf();
d = NULL;
}
else {
#ifdef QT_THREAD_SUPPORT
d->mutex->unlock();
d->mutex->unlock();
#endif // QT_THREAD_SUPPORT
}
d->deleteSelf();
d = NULL;
}
else {
#ifdef QT_THREAD_SUPPORT
@ -1730,7 +1702,7 @@ void QString::real_detach()
void QString::deref()
{
if ( d ) {
if ( d && (d != shared_null) ) {
#ifdef QT_THREAD_SUPPORT
d->mutex->lock();
#endif // QT_THREAD_SUPPORT
@ -1788,13 +1760,15 @@ void QStringData::deleteSelf()
*/
QString &QString::operator=( const QString &s )
{
if (s.d != shared_null) {
#ifdef QT_THREAD_SUPPORT
s.d->mutex->lock();
s.d->mutex->lock();
#endif // QT_THREAD_SUPPORT
s.d->ref();
s.d->ref();
#ifdef QT_THREAD_SUPPORT
s.d->mutex->unlock();
s.d->mutex->unlock();
#endif // QT_THREAD_SUPPORT
}
deref();
d = s.d;
@ -6527,13 +6501,6 @@ QString& QString::setUnicode( const QChar *unicode, uint len )
if ( d != shared_null ) { // beware of nullstring being set to nullstring
deref();
d = shared_null ? shared_null : makeSharedNull();
#ifdef QT_THREAD_SUPPORT
d->mutex->lock();
#endif // QT_THREAD_SUPPORT
d->ref();
#ifdef QT_THREAD_SUPPORT
d->mutex->unlock();
#endif // QT_THREAD_SUPPORT
}
}
else {

Loading…
Cancel
Save