Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Remove questionable uses of LiteralString class #5685

Merged
merged 1 commit into from
Sep 11, 2018

Conversation

jackhorton
Copy link
Contributor

Found this as a driveby while making a different change. To me, LiteralString::NewCopy* is an anti-pattern -- LiteralString doesn't override NewCopy*, so it calls the JavascriptString version regardless, and it gives the impression that some optimization was in mind but not achieved. Additionally, by searching for more cases, I found a number of cases where we were wastefully creating JavascriptStrings for various string constants (most were especially brutal since they were going in rarely used ConcatStrings).

Not sure if there is value in actually hardening LiteralString against incorrect uses, but I can implement that if others see value.

@@ -3246,7 +3247,7 @@ void __cdecl _alloca_probe_16()
if (proxy)
{
ParseableFunctionInfo * func = proxy->EnsureDeserialized();
return LiteralString::NewCopySz(func->GetDisplayName(), scriptContext);
return JavascriptString::NewCopySz(func->GetDisplayName(), scriptContext);
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@boingoing It seems like PFI::GetDisplayName sometimes returns a non-recycler-allocated buffer, so we can't use NewWithSz here. Is that accurate?

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

If you want to get super fancy, you could call GetDisplayNameIsRecyclerAllocated to find out


In reply to: 216497636 [](ancestors = 216497636)

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

True. I will do that instead.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yes, it is possible the display name is not recycler-allocated. If it's allocated in the bytecode buffer, for example.

@sethbrenith
Copy link
Contributor

Surely someone at some time has written a lint rule saying "don't call Base::foo by writing Derived::foo". I think that rule would eliminate a lot of creepy code (including the Is pattern I'm still planning to finish fixing eventually).

Copy link
Contributor

@sethbrenith sethbrenith left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

:shipit:

@@ -3246,7 +3247,7 @@ void __cdecl _alloca_probe_16()
if (proxy)
{
ParseableFunctionInfo * func = proxy->EnsureDeserialized();
return LiteralString::NewCopySz(func->GetDisplayName(), scriptContext);
return JavascriptString::NewCopySz(func->GetDisplayName(), scriptContext);
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yes, it is possible the display name is not recycler-allocated. If it's allocated in the bytecode buffer, for example.

Copy link
Contributor

@VSadov VSadov left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM

@chakrabot chakrabot merged commit 6cf039d into chakra-core:master Sep 11, 2018
chakrabot pushed a commit that referenced this pull request Sep 11, 2018
…lass

Merge pull request #5685 from jackhorton:literal-strings

Found this as a driveby while making a different change. To me, `LiteralString::NewCopy*` is an anti-pattern -- LiteralString doesn't override NewCopy*, so it calls the JavascriptString version regardless, and it gives the impression that some optimization was in mind but not achieved. Additionally, by searching for more cases, I found a number of cases where we were wastefully creating JavascriptStrings for various string constants (most were especially brutal since they were going in rarely used ConcatStrings).

Not sure if there is value in actually hardening LiteralString against incorrect uses, but I can implement that if others see value.
@jackhorton jackhorton deleted the literal-strings branch September 11, 2018 05:40
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

6 participants