[Development] QVariant comparison in Qt6

Thiago Macieira thiago.macieira at intel.com
Tue Sep 22 16:17:49 CEST 2020

On Tuesday, 22 September 2020 06:55:35 PDT Lars Knoll wrote:
> > For internal APIs, please return just a plain int.
> Those compare() methods are meant to be public.

The public API does not have to be non-inline library call.

> Really? Are we now making API decisions on how well a compiler manages to
> micro-optimize this? We have been using int as a return value for
> QString::compare(). qsizetype feels unnatural in this context, so I don’t
> want to use it.

Yes. If someone tries to use this new comparison for sorting a QMap, for 
example, there could be a lot of calls. A simple, micro-optimisation by 
choosing the size and layout of the parameters might improve performance quite 
a bit.

And especially if there's no impact to how the user uses the API.

> 1)
> std::optional<int> compare();
> 2)
> enum class Ordering { Less = -1, Equal = 0, Greater = 1, Unordered = 0xff
> };
>  Ordering compare();
> 3)
> Implement a Qt replacement for std::partial_ordering (could use the std
> stuff if C++ 20 is available) and use that.

I'd rather stay simple and allow extending for <compare> where more details 
are necessary.

For that, I think #1.

Thiago Macieira - thiago.macieira (AT) intel.com
  Software Architect - Intel DPG Cloud Engineering

More information about the Development mailing list