summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorAndreas Kling <kling@serenityos.org>2020-10-04 17:36:12 +0200
committerAndreas Kling <kling@serenityos.org>2020-10-04 19:25:49 +0200
commitd01b746d8810890250995084dcd7b97f870286b1 (patch)
tree0f92fcd30059992aa144b538ae62a34c73d7f665
parent3d053f244f0cb16be187a8935e8120e221e1c716 (diff)
downloadserenity-d01b746d8810890250995084dcd7b97f870286b1.zip
LibJS: Add StringOrSymbol constructor that takes a FlyString
This avoids refcount churn from implicit conversion in some places.
-rw-r--r--Libraries/LibJS/Runtime/StringOrSymbol.h8
1 files changed, 8 insertions, 0 deletions
diff --git a/Libraries/LibJS/Runtime/StringOrSymbol.h b/Libraries/LibJS/Runtime/StringOrSymbol.h
index 6939194183..bb4aba3e7a 100644
--- a/Libraries/LibJS/Runtime/StringOrSymbol.h
+++ b/Libraries/LibJS/Runtime/StringOrSymbol.h
@@ -26,6 +26,7 @@
#pragma once
+#include <AK/FlyString.h>
#include <LibJS/Runtime/PrimitiveString.h>
#include <LibJS/Runtime/Symbol.h>
#include <LibJS/Runtime/Value.h>
@@ -58,6 +59,13 @@ public:
static_cast<const StringImpl*>(m_ptr)->ref();
}
+ StringOrSymbol(const FlyString& string)
+ : m_ptr(string.impl())
+ {
+ ASSERT(!string.is_null());
+ static_cast<const StringImpl*>(m_ptr)->ref();
+ }
+
~StringOrSymbol()
{
if (is_string())