Skip to content

Commit

Permalink
[JSC] Use Identifier::from in IdentifierArena::makeNumericIdentifier
Browse files Browse the repository at this point in the history
https://bugs.webkit.org/show_bug.cgi?id=259959
rdar://113598301

Reviewed by Keith Miller.

We should just use Identifier::from from IdentifierArena::makeNumericIdentifier, which can have some optimization additionally via per-VM string cache.
Also, we can use `canBeInt32` to check wether we can stringify it as int32_t instead of double, which is much faster.

* Source/JavaScriptCore/parser/ParserArena.h:
(JSC::IdentifierArena::makeNumericIdentifier):

Canonical link: https://commits.webkit.org/266743@main
  • Loading branch information
Constellation committed Aug 9, 2023
1 parent de4ab2c commit 624b442
Showing 1 changed file with 7 additions and 3 deletions.
10 changes: 7 additions & 3 deletions Source/JavaScriptCore/parser/ParserArena.h
Original file line number Diff line number Diff line change
Expand Up @@ -133,9 +133,13 @@ namespace JSC {

inline const Identifier& IdentifierArena::makeNumericIdentifier(VM& vm, double number)
{
// FIXME: Why doesn't this use the Identifier::from overload that takes a double?
// Seems we are missing out on multiple optimizations by not using it.
m_identifiers.append(Identifier::fromString(vm, String::number(number)));
Identifier token;
// This is possible that number can be -0, but it is OK since ToString(-0) is "0".
if (canBeInt32(number))
token = Identifier::from(vm, static_cast<int32_t>(number));
else
token = Identifier::from(vm, number);
m_identifiers.append(WTFMove(token));
return m_identifiers.last();
}

Expand Down

0 comments on commit 624b442

Please sign in to comment.