Important: Please read the Qt Code of Conduct - https://forum.qt.io/topic/113070/qt-code-of-conduct

How does qHash(QStringRef&) work?



  • I'm curious as to how this method works. Is it just an overload that calls QStringRef::toString() (thereby making a copy of the referenced substring since this is how I'm using QStringRef) and passes that to qHash(QString&)? Or is it cleverer than that?

    I'd like to use this function, so I'd like to know if it does any copying.

    Thanks.



  • Source:

    @uint qHash(const QStringRef &key)
    {
    return hash(key.unicode(), key.size());
    }@

    QStringRef::unicode()
    Returns a Unicode representation of the string reference. Since the data stems directly from the referenced string, it is not null-terminated unless the string reference includes the string's null terminator.



  • Nice! Thanks!


Log in to reply