BAN: String and StringView don't have to compute strlen for equality

This commit is contained in:
Bananymous 2022-12-20 11:36:01 +02:00
parent c82caacbaa
commit d5a068f90c
2 changed files with 4 additions and 4 deletions

View File

@ -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<void> String::Resize(size_type size, char ch)

View File

@ -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