fix: terrorist behaviour on ES maps with buyzone. (fixes #155).
fix: help commands causing host overflow when translated. crlib: use fnv1a for string hashes. crlib: add hash () method to String & StringRef classes.
This commit is contained in:
parent
e173accc13
commit
8acd84fdc8
6 changed files with 35 additions and 48 deletions
|
|
@ -59,14 +59,13 @@ CR_EXPOSE_GLOBAL_SINGLETON (SNPrintfWrap, fmtwrap);
|
|||
// simple non-owning string class like std::string_view
|
||||
class StringRef {
|
||||
private:
|
||||
static constexpr size_t strLength (const char *cstr) {
|
||||
size_t length = 0;
|
||||
static constexpr size_t len (const char *str) noexcept {
|
||||
return !*str ? 0 : 1 + len (str + 1);
|
||||
}
|
||||
|
||||
while (*cstr != kNullChar) {
|
||||
length++;
|
||||
cstr++;
|
||||
}
|
||||
return length;
|
||||
public:
|
||||
static constexpr uint32 fnv1a32 (const char *str, uint32 hash = 0x811c9dc5) {
|
||||
return !*str ? hash : fnv1a32 (str + 1, (hash ^ static_cast <uint8> (*str)) * 0x01000193);
|
||||
}
|
||||
|
||||
public:
|
||||
|
|
@ -81,7 +80,7 @@ private:
|
|||
public:
|
||||
constexpr StringRef () noexcept = default;
|
||||
|
||||
constexpr StringRef (const char *chars) : chars_ (chars), length_ (chars ? strLength (chars) : 0)
|
||||
constexpr StringRef (const char *chars) : chars_ (chars), length_ (chars ? len (chars) : 0)
|
||||
{ }
|
||||
|
||||
constexpr StringRef (const char *chars, size_t length) : chars_ (chars), length_ (length)
|
||||
|
|
@ -133,6 +132,10 @@ public:
|
|||
return *this == rhs;
|
||||
}
|
||||
|
||||
constexpr uint32 hash () const {
|
||||
return fnv1a32 (chars ());
|
||||
}
|
||||
|
||||
public:
|
||||
int32 int_ () const {
|
||||
return atoi (chars ());
|
||||
|
|
@ -606,6 +609,10 @@ public:
|
|||
}
|
||||
|
||||
public:
|
||||
uint32 hash () const {
|
||||
return str ().hash ();
|
||||
}
|
||||
|
||||
bool contains (StringRef rhs) const {
|
||||
return str ().contains (rhs);
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue