From ea10b6290dd14c79fd3192a2f772093310b94f22 Mon Sep 17 00:00:00 2001 From: Michele Calgaro Date: Tue, 14 Feb 2023 12:19:56 +0900 Subject: [PATCH] tdeio: only create the internal guarded pointer for TDEIO::Job if it is really required. This fix avoid creation and destruction of unnecessary TQObjects and helps speeding up operations which requires lot of Jobs. Signed-off-by: Michele Calgaro --- tdeio/tdeio/job.cpp | 32 +++++++++++++++++++++++++------- 1 file changed, 25 insertions(+), 7 deletions(-) diff --git a/tdeio/tdeio/job.cpp b/tdeio/tdeio/job.cpp index 2c17d8534..43b0c808b 100644 --- a/tdeio/tdeio/job.cpp +++ b/tdeio/tdeio/job.cpp @@ -89,15 +89,23 @@ template class TQPtrList; class Job::JobPrivate { public: - JobPrivate() : m_autoErrorHandling( false ), m_autoWarningHandling( true ), - m_interactive( true ), m_parentJob( 0L ), m_extraFlags(0), - m_processedSize(0), m_userTimestamp(0) + JobPrivate() : m_autoErrorHandling(false), m_autoWarningHandling(true), + m_interactive(true), m_errorParentWidgetGP(0), m_parentJob(0L), + m_extraFlags(0), m_processedSize(0), m_userTimestamp(0) {} + ~JobPrivate() + { + if (m_errorParentWidgetGP) + { + delete m_errorParentWidgetGP; + } + } + bool m_autoErrorHandling; bool m_autoWarningHandling; bool m_interactive; - TQGuardedPtr m_errorParentWidget; + TQGuardedPtr *m_errorParentWidgetGP; // Maybe we could use the TQObject parent/child mechanism instead // (requires a new ctor, and moving the ctor code to some init()). Job* m_parentJob; @@ -143,7 +151,9 @@ Job::~Job() delete m_speedTimer; delete d; if (kapp) - kapp->deref(); + { + kapp->deref(); + } } int& Job::extraFlags() @@ -233,7 +243,7 @@ void Job::emitResult() if ( m_progressId ) // Did we get an ID from the observer ? Observer::self()->jobFinished( m_progressId ); if ( m_error && d->m_interactive && d->m_autoErrorHandling ) - showErrorDialog( d->m_errorParentWidget ); + showErrorDialog( d->m_errorParentWidgetGP ? *d->m_errorParentWidgetGP : nullptr); emit result(this); deleteLater(); } @@ -322,8 +332,16 @@ void Job::showErrorDialog( TQWidget * parent ) void Job::setAutoErrorHandlingEnabled( bool enable, TQWidget *parentWidget ) { + if (d->m_errorParentWidgetGP && (TQWidget*)(*d->m_errorParentWidgetGP) != parentWidget) + { + delete d->m_errorParentWidgetGP; + d->m_errorParentWidgetGP = nullptr; + } d->m_autoErrorHandling = enable; - d->m_errorParentWidget = parentWidget; + if (enable && parentWidget && !d->m_errorParentWidgetGP) + { + d->m_errorParentWidgetGP = new TQGuardedPtr(parentWidget); + } } bool Job::isAutoErrorHandlingEnabled() const