From d5a068f90c530c596dbf8cd6e4e2d9a9107018b1 Mon Sep 17 00:00:00 2001 From: Bananymous Date: Tue, 20 Dec 2022 11:36:01 +0200 Subject: [PATCH] BAN: String and StringView don't have to compute strlen for equality --- BAN/BAN/String.cpp | 4 ++-- BAN/BAN/StringView.cpp | 4 ++-- 2 files changed, 4 insertions(+), 4 deletions(-) diff --git a/BAN/BAN/String.cpp b/BAN/BAN/String.cpp index cefbeb30..296878b9 100644 --- a/BAN/BAN/String.cpp +++ b/BAN/BAN/String.cpp @@ -141,9 +141,9 @@ namespace BAN bool String::operator==(const char* other) const { - if (m_size != strlen(other)) + if (memcmp(m_data, other, m_size)) return false; - return memcmp(m_data, other, m_size) == 0; + return other[m_size] == '\0'; } ErrorOr String::Resize(size_type size, char ch) diff --git a/BAN/BAN/StringView.cpp b/BAN/BAN/StringView.cpp index b86d78c7..2881d2e9 100644 --- a/BAN/BAN/StringView.cpp +++ b/BAN/BAN/StringView.cpp @@ -45,9 +45,9 @@ namespace BAN bool StringView::operator==(const char* other) const { - if (m_size != strlen(other)) + if (memcmp(m_data, other, m_size)) return false; - return memcmp(m_data, other, m_size) == 0; + return other[m_size] == '\0'; } StringView StringView::Substring(size_type index, size_type len) const