#pragma once
#include <wtf/text/StringHash.h>
#include <wtf/text/WTFString.h>
namespace JSC {
enum RegExpFlags {
NoFlags = 0,
FlagGlobal = 1,
FlagIgnoreCase = 2,
FlagMultiline = 4,
FlagSticky = 8,
FlagUnicode = 16,
FlagDotAll = 32,
InvalidFlags = 64,
DeletedValueFlags = -1
};
struct RegExpKey {
RegExpFlags flagsValue;
RefPtr<StringImpl> pattern;
RegExpKey()
: flagsValue(NoFlags)
{
}
RegExpKey(RegExpFlags flags)
: flagsValue(flags)
{
}
RegExpKey(RegExpFlags flags, const String& pattern)
: flagsValue(flags)
, pattern(pattern.impl())
{
}
RegExpKey(RegExpFlags flags, RefPtr<StringImpl>&& pattern)
: flagsValue(flags)
, pattern(WTFMove(pattern))
{
}
RegExpKey(RegExpFlags flags, const RefPtr<StringImpl>& pattern)
: flagsValue(flags)
, pattern(pattern)
{
}
friend inline bool operator==(const RegExpKey& a, const RegExpKey& b);
struct Hash {
static unsigned hash(const RegExpKey& key) { return key.pattern->hash(); }
static bool equal(const RegExpKey& a, const RegExpKey& b) { return a == b; }
static const bool safeToCompareToEmptyOrDeleted = false;
};
};
inline bool operator==(const RegExpKey& a, const RegExpKey& b)
{
if (a.flagsValue != b.flagsValue)
return false;
if (!a.pattern)
return !b.pattern;
if (!b.pattern)
return false;
return equal(a.pattern.get(), b.pattern.get());
}
}
namespace WTF {
template<typename T> struct DefaultHash;
template<> struct DefaultHash<JSC::RegExpKey> {
typedef JSC::RegExpKey::Hash Hash;
};
template<> struct HashTraits<JSC::RegExpKey> : GenericHashTraits<JSC::RegExpKey> {
static const bool emptyValueIsZero = true;
static void constructDeletedValue(JSC::RegExpKey& slot) { slot.flagsValue = JSC::DeletedValueFlags; }
static bool isDeletedValue(const JSC::RegExpKey& value) { return value.flagsValue == JSC::DeletedValueFlags; }
};
}