Browse Source

base: leverage the libc for string comparisons.

legacy
Sam Hocevar sam 11 years ago
parent
commit
9584830bad
1 changed files with 9 additions and 20 deletions
  1. +9
    -20
      src/lol/base/string.h

+ 9
- 20
src/lol/base/string.h View File

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


Loading…
Cancel
Save