EvalMapString.h 2.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869
  1. //-------------------------------------------------------------------------------------------------------
  2. // Copyright (C) Microsoft. All rights reserved.
  3. // Licensed under the MIT license. See LICENSE.txt file in the project root for full license information.
  4. //-------------------------------------------------------------------------------------------------------
  5. #pragma once
  6. namespace Js
  7. {
  8. template <bool fastHash>
  9. struct EvalMapStringInternal
  10. {
  11. JsUtil::CharacterBuffer<char16> str;
  12. hash_t hash;
  13. ModuleID moduleID;
  14. BOOL strict;
  15. BOOL isLibraryCode;
  16. EvalMapStringInternal() : str(), moduleID(0), strict(FALSE), isLibraryCode(FALSE), hash(0) {};
  17. EvalMapStringInternal(__in_ecount(charLength) char16 const* content, int charLength, ModuleID moduleID, BOOL strict, BOOL isLibraryCode)
  18. : str(content, charLength), moduleID(moduleID), strict(strict), isLibraryCode(isLibraryCode)
  19. {
  20. // NOTE: this hash is not equivalent to the character buffer hash
  21. // Don't use a CharacteBuffer to do a map lookup on the EvalMapString.
  22. if (fastHash)
  23. {
  24. hash = TAGHASH(str.FastHash());
  25. }
  26. else
  27. {
  28. hash = TAGHASH((hash_t)str);
  29. }
  30. };
  31. EvalMapStringInternal& operator=(void * str)
  32. {
  33. Assert(str == null);
  34. memset(this, 0, sizeof(EvalMapString));
  35. return (*this);
  36. }
  37. inline ModuleID GetModuleID() const
  38. {
  39. return moduleID;
  40. }
  41. inline BOOL IsStrict() const
  42. {
  43. return strict;
  44. }
  45. // Equality and hash function
  46. bool operator==(EvalMapStringInternal const& other) const
  47. {
  48. return this->str == other.str &&
  49. this->GetModuleID() == other.GetModuleID() &&
  50. this->IsStrict() == other.IsStrict() &&
  51. this->isLibraryCode == other.isLibraryCode;
  52. }
  53. operator hash_t() const
  54. {
  55. return UNTAGHASH(hash);
  56. }
  57. };
  58. typedef EvalMapStringInternal<true> FastEvalMapString;
  59. typedef EvalMapStringInternal<false> EvalMapString;
  60. void ConvertKey(const FastEvalMapString& src, EvalMapString& dest);
  61. };