Skip to content

core: Use Vec::retain in Avm1TextFieldBinding::bind_variables#23940

Open
SuchAFuriousDeath wants to merge 2 commits into
ruffle-rs:masterfrom
SuchAFuriousDeath:unbound-text-fields
Open

core: Use Vec::retain in Avm1TextFieldBinding::bind_variables#23940
SuchAFuriousDeath wants to merge 2 commits into
ruffle-rs:masterfrom
SuchAFuriousDeath:unbound-text-fields

Conversation

@SuchAFuriousDeath

@SuchAFuriousDeath SuchAFuriousDeath commented Jun 9, 2026

Copy link
Copy Markdown
Collaborator

Description

Just a tiny refactor, std::mem::take has to be used to satisfy the borrow checker.

SIDENOTE: The TODO talks about Vec::drain_filter, which got stabilized as Vec::extract_if, but retain is the better fit here, since there is no resulting iterator we have to consume.

Checklist

  • I, a human, have self-reviewed this PR and fully understand the changes within.
  • I have made or updated tests where possible.
  • All of my commits are properly scoped, compile successfully, and pass all tests.
  • This PR does not make sense to split up into smaller PRs.
  • An LLM was involved in the authoring of this code.

@SuchAFuriousDeath SuchAFuriousDeath added code-cleanup General improvement of the code base T-refactor Type: Refactor / Cleanup labels Jun 9, 2026
@kjarosh

kjarosh commented Jun 9, 2026

Copy link
Copy Markdown
Member

Just a general note about this particular code (text variable binding): it's generally untested and buggy in Ruffle, it can easily introduce regressions.

@SuchAFuriousDeath

Copy link
Copy Markdown
Collaborator Author

@kjarosh 🥺

}
let mut text_fields = std::mem::take(activation.context.unbound_text_fields);

text_fields.retain(|field| !field.try_bind_text_field_variable(activation, false));

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

This will change the order of elements, does it matter?

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

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

Good question, I didn't consider that. From looking at the code, I don't see a reason why it should matter.

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

For instance, try_bind_text_field_variable calls object.set which calls watchers. Can we add at least a test that checks the order of called watchers?

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

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

I had Claude vibe out a test, see if it makes sense please, it does to me, but this isn't really an area of code I'm familiar with.

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Is the test failing with the previous code?

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

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

No, I just checked. It doesn't depend on the order of iteration I guess.

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

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

However, I think your claim here:

For instance, try_bind_text_field_variable calls object.set which calls watchers.

Is wrong because try_bind_text_field_variable is called with false as the second argument and that results in watchers not being called, at least based on my understanding.

@SuchAFuriousDeath

Copy link
Copy Markdown
Collaborator Author

@kjarosh 🥺

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

code-cleanup General improvement of the code base T-refactor Type: Refactor / Cleanup

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants