Skip to content

Commit 6b3604e

Browse files
[MERGE #4686 @agarwal-sandeep] OS#15813592 Create PropertyString for common built-in properties
Merge pull request #4686 from agarwal-sandeep:createpropertystring This fixes a regression in react.js from RS3 to RS4 which got introduced when we started creating less new string object for known texts
2 parents 298641d + 4b432f1 commit 6b3604e

File tree

1 file changed

+37
-14
lines changed

1 file changed

+37
-14
lines changed

lib/Runtime/Library/StringCache.h

Lines changed: 37 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,19 @@ public: \
2121
return __##name; \
2222
}
2323

24+
#define DEFINE_CACHED_STRING_WITH_PROPERTYSTRING(name, str) \
25+
private: \
26+
Field(JavascriptString*) __##name; \
27+
public: \
28+
JavascriptString* name() { \
29+
if (__##name == nullptr) \
30+
{ \
31+
__##name = CreatePropertyStringFromFromCppLiteral(str); \
32+
} \
33+
\
34+
return __##name; \
35+
}
36+
2437
class StaticType;
2538

2639
class StringCache
@@ -159,26 +172,36 @@ class StringCache
159172
DEFINE_CACHED_STRING(GetObjectStringDisplayString, _u("[object String]"))
160173
DEFINE_CACHED_STRING(GetObjectNullDisplayString, _u("[object Null]"))
161174
DEFINE_CACHED_STRING(GetObjectUndefinedDisplayString, _u("[object Undefined]"))
162-
DEFINE_CACHED_STRING(GetUndefinedDisplayString, _u("undefined"))
163-
DEFINE_CACHED_STRING(GetNaNDisplayString, _u("NaN"))
164-
DEFINE_CACHED_STRING(GetNullDisplayString, _u("null"))
165-
DEFINE_CACHED_STRING(GetUnknownDisplayString, _u("unknown"))
166-
DEFINE_CACHED_STRING(GetTrueDisplayString, _u("true"))
167-
DEFINE_CACHED_STRING(GetFalseDisplayString, _u("false"))
168-
DEFINE_CACHED_STRING(GetStringTypeDisplayString, _u("string"))
169-
DEFINE_CACHED_STRING(GetObjectTypeDisplayString, _u("object"))
170-
DEFINE_CACHED_STRING(GetFunctionTypeDisplayString, _u("function"))
171-
DEFINE_CACHED_STRING(GetBooleanTypeDisplayString, _u("boolean"))
172-
DEFINE_CACHED_STRING(GetNumberTypeDisplayString, _u("number"))
173-
DEFINE_CACHED_STRING(GetModuleTypeDisplayString, _u("Module"))
174-
DEFINE_CACHED_STRING(GetVariantDateTypeDisplayString, _u("date"))
175-
DEFINE_CACHED_STRING(GetSymbolTypeDisplayString, _u("symbol"))
175+
DEFINE_CACHED_STRING_WITH_PROPERTYSTRING(GetUndefinedDisplayString, _u("undefined"))
176+
DEFINE_CACHED_STRING_WITH_PROPERTYSTRING(GetNaNDisplayString, _u("NaN"))
177+
DEFINE_CACHED_STRING_WITH_PROPERTYSTRING(GetNullDisplayString, _u("null"))
178+
DEFINE_CACHED_STRING_WITH_PROPERTYSTRING(GetUnknownDisplayString, _u("unknown"))
179+
DEFINE_CACHED_STRING_WITH_PROPERTYSTRING(GetTrueDisplayString, _u("true"))
180+
DEFINE_CACHED_STRING_WITH_PROPERTYSTRING(GetFalseDisplayString, _u("false"))
181+
DEFINE_CACHED_STRING_WITH_PROPERTYSTRING(GetStringTypeDisplayString, _u("string"))
182+
DEFINE_CACHED_STRING_WITH_PROPERTYSTRING(GetObjectTypeDisplayString, _u("object"))
183+
DEFINE_CACHED_STRING_WITH_PROPERTYSTRING(GetFunctionTypeDisplayString, _u("function"))
184+
DEFINE_CACHED_STRING_WITH_PROPERTYSTRING(GetBooleanTypeDisplayString, _u("boolean"))
185+
DEFINE_CACHED_STRING_WITH_PROPERTYSTRING(GetNumberTypeDisplayString, _u("number"))
186+
DEFINE_CACHED_STRING_WITH_PROPERTYSTRING(GetModuleTypeDisplayString, _u("Module"))
187+
DEFINE_CACHED_STRING_WITH_PROPERTYSTRING(GetVariantDateTypeDisplayString, _u("date"))
188+
DEFINE_CACHED_STRING_WITH_PROPERTYSTRING(GetSymbolTypeDisplayString, _u("symbol"))
176189

177190
private:
178191
template< size_t N > JavascriptString* CreateStringFromCppLiteral(const char16(&value)[N]) const
179192
{
180193
return LiteralString::New(stringTypeStatic, value, N - 1 /*don't include terminating NUL*/, scriptContext->GetRecycler());
181194
}
195+
196+
template< size_t N > JavascriptString* CreatePropertyStringFromFromCppLiteral(const char16(&value)[N]) const
197+
{
198+
const PropertyRecord* propertyRecord = nullptr;
199+
scriptContext->FindPropertyRecord(value, N - 1, &propertyRecord);
200+
AssertMsg(propertyRecord != nullptr, "Trying to create a propertystring for non property string?");
201+
Assert(IsBuiltInPropertyId(propertyRecord->GetPropertyId()));
202+
return scriptContext->GetPropertyString(propertyRecord->GetPropertyId());
203+
}
204+
182205
};
183206

184207
#undef SCACHE_INIT_DEFAULT

0 commit comments

Comments
 (0)