diff options
| author | Kevin Newton <kddnewton@gmail.com> | 2024-01-22 11:19:27 -0500 |
|---|---|---|
| committer | git <svn-admin@ruby-lang.org> | 2024-01-22 16:23:11 +0000 |
| commit | 5906ce42fe04e8d4a4fe4b68b8ac54193598db56 (patch) | |
| tree | 7d3ee110b186bdd3e188689f6454e32e45618082 /prism | |
| parent | 6401f282d25fa89823c9360b43e377c55e9ff7a5 (diff) | |
[ruby/prism] Static literal flag for string hash keys
https://github.com/ruby/prism/commit/26a2d774cd
Diffstat (limited to 'prism')
| -rw-r--r-- | prism/prism.c | 12 |
1 files changed, 7 insertions, 5 deletions
diff --git a/prism/prism.c b/prism/prism.c index 4a6797896b..6b53417523 100644 --- a/prism/prism.c +++ b/prism/prism.c @@ -1352,6 +1352,13 @@ pm_assoc_node_create(pm_parser_t *parser, pm_node_t *key, const pm_token_t *oper end = key->location.end; } + // Hash string keys will be frozen, so we can mark them as frozen here so + // that the compiler picks them up and also when we check for static literal + // on the keys it gets factored in. + if (PM_NODE_TYPE_P(key, PM_STRING_NODE)) { + key->flags |= PM_STRING_FLAGS_FROZEN | PM_NODE_FLAG_STATIC_LITERAL; + } + // If the key and value of this assoc node are both static literals, then // we can mark this node as a static literal. pm_node_flags_t flags = 0; @@ -1359,11 +1366,6 @@ pm_assoc_node_create(pm_parser_t *parser, pm_node_t *key, const pm_token_t *oper flags = key->flags & value->flags & PM_NODE_FLAG_STATIC_LITERAL; } - // Hash string keys should be frozen - if (PM_NODE_TYPE_P(key, PM_STRING_NODE)) { - key->flags |= PM_STRING_FLAGS_FROZEN; - } - *node = (pm_assoc_node_t) { { .type = PM_ASSOC_NODE, |
