From 9584830badea05b31b335f9d65ce8cf9f9e7e8af Mon Sep 17 00:00:00 2001 From: Sam Hocevar Date: Sat, 22 Jun 2013 15:32:09 +0000 Subject: [PATCH] base: leverage the libc for string comparisons. --- src/lol/base/string.h | 29 +++++++++-------------------- 1 file changed, 9 insertions(+), 20 deletions(-) diff --git a/src/lol/base/string.h b/src/lol/base/string.h index cb795b7a..3762af5b 100644 --- a/src/lol/base/string.h +++ b/src/lol/base/string.h @@ -182,14 +182,9 @@ public: inline bool operator ==(String const &s) const { - if (this->m_count != s.m_count) - return false; - - for (int i = 0; i < this->m_count; ++i) - if ((*this)[i] != s[i]) - return false; - - return true; + using namespace std; + return Count() == s.Count() + && memcmp(C(), s.C(), Count()) == 0; } inline bool operator !=(String const &s) const @@ -197,20 +192,14 @@ public: return !(*this == s); } - inline bool operator ==(char const* sz) const { - int i; - for (i = 0; i < this->m_count; ++i) - { - if (i < this->m_count - 1 && sz[i] == '\0') - return false; - - if ((*this)[i] != sz[i]) - return false; - } - - return true; + /* We parse the C string twice because of strlen + memcmp + * but it's probably still faster than doing it by hand. */ + using namespace std; + int sz_len = (int)strlen(sz); + return Count() == sz_len + && memcmp(C(), sz, sz_len) == 0; } inline bool operator !=(char const* sz) const