Fix lua-style dictionary operator performance #68925
Closed
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Fixes #68834.
I'm having the GDScript analyzer replace an
IdentifierNode
with aLiteralNode
so the behavior ofdict.someIndex
becomes the same asdict["someIndex"]
.I don't believe I can do this in the parser, because the parser does not know whether
dict
is a dictionary or not. That is something the analyzer infers.Unfortunately, this does require us to go into
GDScriptParser
's singly-linked listlist
and do a search for theIdentifierNode
so we can remove it from there and replace it with theLiteralNode
. For large scripts, this is not very efficient at all. IfGDScriptParser::Node
had aprev
as well as anext
, then it would become a doubly-linked list and beO(1)
instead ofO(n)
, wheren
is the number of parse nodes in a script.I will likely add some more documentation in the future, but technically, this is ready for review.
Quick note: I really only added
if (base_type.kind == GDScriptParser::DataType::BUILTIN && base_type.builtin_type == Variant::DICTIONARY && p_subscript->attribute->type == GDScriptParser::Node::IDENTIFIER) { ... }
. The rest of the lines are counting as added lines but only because they got indented inside theelse
.