SingleCharString.cpp 1.5 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243
  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. #include "RuntimeLibraryPch.h"
  6. namespace Js
  7. {
  8. DEFINE_RECYCLER_TRACKER_PERF_COUNTER(SingleCharString);
  9. SingleCharString::SingleCharString(char16 ch, StaticType * type) : JavascriptString(type, 1, m_buff)
  10. {
  11. m_buff[0] = ch;
  12. m_buff[1] = _u('\0');
  13. #ifdef PROFILE_STRINGS
  14. StringProfiler::RecordNewString( this->GetScriptContext(), this->m_buff, 1 );
  15. #endif
  16. }
  17. /*static*/ SingleCharString* SingleCharString::New(char16 ch, ScriptContext* scriptContext)
  18. {
  19. Assert(scriptContext != nullptr);
  20. return RecyclerNew(scriptContext->GetRecycler(),SingleCharString,ch,
  21. scriptContext->GetLibrary()->GetStringTypeStatic());
  22. }
  23. /*static*/ SingleCharString* SingleCharString::New(char16 ch, ScriptContext* scriptContext, ArenaAllocator* arena)
  24. {
  25. Assert(scriptContext != nullptr);
  26. Assert(arena != nullptr);
  27. return Anew(arena, SingleCharString, ch,
  28. scriptContext->GetLibrary()->GetStringTypeStatic());
  29. }
  30. void const * SingleCharString::GetOriginalStringReference()
  31. {
  32. // The owning allocation for the string buffer is the string itself
  33. return this;
  34. }
  35. }