From 47dd1b9f8b4c901ebb0f0448383632507c8c4e8f Mon Sep 17 00:00:00 2001 From: Timothy Flynn Date: Sun, 27 Nov 2022 10:20:14 -0500 Subject: [PATCH] LibSQL: Don't copy strings when searching for a column's index Also don't cast the return value to an int. --- Userland/Libraries/LibSQL/Tuple.cpp | 7 +++---- Userland/Libraries/LibSQL/Tuple.h | 2 +- 2 files changed, 4 insertions(+), 5 deletions(-) diff --git a/Userland/Libraries/LibSQL/Tuple.cpp b/Userland/Libraries/LibSQL/Tuple.cpp index 04fa97813f..c0dc6cc9e4 100644 --- a/Userland/Libraries/LibSQL/Tuple.cpp +++ b/Userland/Libraries/LibSQL/Tuple.cpp @@ -79,13 +79,12 @@ Tuple& Tuple::operator=(Tuple const& other) return *this; } -Optional Tuple::index_of(String name) const +Optional Tuple::index_of(StringView name) const { - auto n = move(name); for (auto ix = 0u; ix < m_descriptor->size(); ix++) { auto& part = (*m_descriptor)[ix]; - if (part.name == n) { - return (int)ix; + if (part.name == name) { + return ix; } } return {}; diff --git a/Userland/Libraries/LibSQL/Tuple.h b/Userland/Libraries/LibSQL/Tuple.h index 0488128097..297510f7a5 100644 --- a/Userland/Libraries/LibSQL/Tuple.h +++ b/Userland/Libraries/LibSQL/Tuple.h @@ -70,7 +70,7 @@ public: [[nodiscard]] u32 hash() const; protected: - [[nodiscard]] Optional index_of(String) const; + [[nodiscard]] Optional index_of(StringView) const; void copy_from(Tuple const&); virtual void serialize(Serializer&) const; virtual void deserialize(Serializer&);