constexpr size_t length() const { return size_; }
};
+/**
+ * \brief Faster comparison for string views (compare size before data)
+ *
+ * Still stable, but faster than the normal ordering. */
+static inline int StringViewCompareFast(StringView a, StringView b) {
+ if (a.size() != b.size())
+ return a.size() - b.size();
+
+ return memcmp(a.data(), b.data(), a.size());
+}
+
}
// Look at the hash bucket for the group
Group *Grp = GrpP + HeaderP->GrpHashTableP()[sHash(Name)];
for (; Grp != GrpP; Grp = GrpP + Grp->Next) {
- int const cmp = Name.compare(ViewString(Grp->Name));
+ int const cmp = StringViewCompareFast(Name, ViewString(Grp->Name));
if (cmp == 0)
return GrpIterator(*this, Grp);
else if (cmp < 0)
unsigned long const Hash = Cache.Hash(Name);
map_pointer_t *insertAt = &Cache.HeaderP->GrpHashTableP()[Hash];
- while (*insertAt != 0 && Name.compare(Cache.ViewString((Cache.GrpP + *insertAt)->Name)) > 0)
+ while (*insertAt != 0 && StringViewCompareFast(Name, Cache.ViewString((Cache.GrpP + *insertAt)->Name)) > 0)
insertAt = &(Cache.GrpP + *insertAt)->Next;
Grp->Next = *insertAt;
*insertAt = Group;
// Insert it into the hash table
map_id_t const Hash = Cache.Hash(Name);
map_pointer_t *insertAt = &Cache.HeaderP->PkgHashTableP()[Hash];
- while (*insertAt != 0 && Name.compare(Cache.StrP + (Cache.GrpP + (Cache.PkgP + *insertAt)->Group)->Name) > 0)
+ while (*insertAt != 0 && StringViewCompareFast(Name, Cache.ViewString((Cache.GrpP + (Cache.PkgP + *insertAt)->Group)->Name)) > 0)
insertAt = &(Cache.PkgP + *insertAt)->NextPackage;
Pkg->NextPackage = *insertAt;
*insertAt = Package;