InternalString.h 1.8 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849
  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. class InternalString
  9. {
  10. charcount_t m_charLength;
  11. unsigned char m_offset;
  12. const wchar16* m_content;
  13. public:
  14. InternalString() : m_charLength(0), m_content(NULL), m_offset(0) { };
  15. InternalString(const wchar16* content, charcount_t charLength, unsigned char offset = 0);
  16. static InternalString* New(ArenaAllocator* alloc, const wchar16* content, charcount_t length);
  17. static InternalString* New(Recycler* recycler, const wchar16* content, charcount_t length);
  18. static InternalString* NewNoCopy(ArenaAllocator* alloc, const wchar16* content, charcount_t length);
  19. inline charcount_t GetLength() const
  20. {
  21. return m_charLength;
  22. }
  23. inline const wchar16* GetBuffer() const
  24. {
  25. return m_content + m_offset;
  26. }
  27. };
  28. struct InternalStringComparer
  29. {
  30. __inline static bool Equals(InternalString const& str1, InternalString const& str2)
  31. {
  32. return str1.GetLength() == str2.GetLength() &&
  33. JsUtil::CharacterBuffer<wchar16>::StaticEquals(str1.GetBuffer(), str2.GetBuffer(), str1.GetLength());
  34. }
  35. __inline static hash_t GetHashCode(InternalString const& str)
  36. {
  37. return JsUtil::CharacterBuffer<wchar16>::StaticGetHashCode(str.GetBuffer(), str.GetLength());
  38. }
  39. };
  40. }
  41. template<>
  42. struct DefaultComparer<Js::InternalString> : public Js::InternalStringComparer {};