#define APT_STRINGVIEW_H
#include <string.h>
#include <string>
+#include <apt-pkg/macros.h>
namespace APT {
* used by APT. It is not meant to be used in programs, only inside the
* library for performance critical paths.
*/
-class StringView {
+class APT_HIDDEN StringView {
const char *data_;
size_t size_;
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());
+}
+
}