Re: Fw: Fwd: [Qt bugreports] Updates for QTBUG-75585: Massive performance regression in QML Date object

Robert Krawitz <rlk-FrUbXkNCsVf2fBVCVOL8/[email protected]> Thu, 24 Sep 2020 21:53:21 -0400
Newsgroups gmane.comp.kde.kimdaba
Message-ID <[email protected]>
This is a multi-part message in MIME format.
--------------FBCDF1282F0C04889AF69AAF
Content-Type: text/plain; charset=utf-8
Content-Transfer-Encoding: 7bit

So I've taken a crack at a FastDateTime (wrote the header file and made the changes elsewhere, but
haven't actually implemented it).  However, it looks like I don't have ssh keys installed so I can't
push now.

I've attached the header file for reference.

--------------FBCDF1282F0C04889AF69AAF
Content-Type: text/x-chdr; charset=UTF-8;
 name="FastDateTime.h"
Content-Transfer-Encoding: 7bit
Content-Disposition: attachment;
 filename="FastDateTime.h"

/* Copyright (C) 2020 the KPhotoAlbum development team

   This program is free software; you can redistribute it and/or
   modify it under the terms of the GNU General Public
   License as published by the Free Software Foundation; either
   version 2 of the License, or (at your option) any later version.

   This program is distributed in the hope that it will be useful,
   but WITHOUT ANY WARRANTY; without even the implied warranty of
   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
   General Public License for more details.

   You should have received a copy of the GNU General Public License
   along with this program; see the file COPYING.  If not, write to
   the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
   Boston, MA 02110-1301, USA.
*/

#ifndef UTILITIES_FASTDATETIME_H
#define UTILITIES_FASTDATETIME_H
#include <QDateTime>
#include <QDate>
#include <QTime>

namespace Utilities
{

/**
 * The FastDateTime class implements a datetime that is much faster
 * than QDateTime for comparing dates.  It caches the linear time
 * since the epoch for use in comparisons.  See
 * https://bugreports.qt.io/browse/QTBUG-41714 and
 * https://bugreports.qt.io/browse/QTBUG-75585 for an explanation
 * of why the standard QDateTime is extremely slow (on the order of
 * 1 usec per comparison).
 *
 * The distinguished value INT64_MIN is used to indicate an invalid
 * date/time.  Invalid date/times are passed to QDateTime for handling.
 */

class FastDateTime
{
public:
    FastDateTime();
    FastDateTime(const QDate &, const QTime &, Qt::TimeSpec spec = Qt::LocalTime);
    FastDateTime(const FastDateTime &other) noexcept;
    // Needed for QDate(Y, M, D).startOfDay()
    FastDateTime(const QDateTime &other) noexcept;
    ~FastDateTime();

    void setTimeSpec(Qt::TimeSpec spec);

    bool operator==(const FastDateTime &other) const;
    bool operator!=(const FastDateTime &other) const;
    bool operator< (const FastDateTime &other) const;
    bool operator<=(const FastDateTime &other) const;
    bool operator> (const FastDateTime &other) const;
    bool operator>=(const FastDateTime &other) const;
    bool isNull() const;
    bool isValid() const;
    QDate date() const;
    QTime time() const;
    QString toString(Qt::DateFormat format = Qt::TextDate) const;
    QString toString(QStringView format) const;
    qint64 secsTo(const FastDateTime &) const;
    qint64 toSecsSinceEpoch() const;

    Q_REQUIRED_RESULT FastDateTime addDays(qint64 days) const;
    Q_REQUIRED_RESULT FastDateTime addMonths(qint64 months) const;
    Q_REQUIRED_RESULT FastDateTime addYears(qint64 years) const;
    Q_REQUIRED_RESULT FastDateTime addSecs(qint64 secs) const;

    static FastDateTime currentDateTime();
    static FastDateTime fromString(const QString &s, Qt::DateFormat f = Qt::TextDate);

private:
    QDateTime m_dateTime;
    qint64 m_msecSinceEpoch;
};
}

#endif /* UTILITIES_FASTDATETIME_H */

// vi:expandtab:tabstop=4 shiftwidth=4:

--------------FBCDF1282F0C04889AF69AAF
Content-Type: text/plain; charset="us-ascii"
MIME-Version: 1.0
Content-Transfer-Encoding: 7bit
Content-Disposition: inline

_______________________________________________
KPhotoAlbum mailing list
[email protected]
https://mail.kdab.com/mailman/listinfo/kphotoalbum

--------------FBCDF1282F0C04889AF69AAF--