nashorn icon indicating copy to clipboard operation
nashorn copied to clipboard

Update ScriptObjectMirror.java

Open davidekholm opened this issue 10 months ago • 6 comments

Added removeAll method for improved performance and for symmetry with putAll (makes a significant (1.7x) improvement in gallery maker jAlbum (Tiger skin)


Progress

  • [ ] Change must be properly reviewed (1 review required, with at least 1 Reviewer)
  • [x] Change must not contain extraneous whitespace

Error

 ⚠️ OCA signatory status must be verified

Reviewing

Using git

Checkout this PR locally:
$ git fetch https://git.openjdk.org/nashorn.git pull/24/head:pull/24
$ git checkout pull/24

Update a local copy of the PR:
$ git checkout pull/24
$ git pull https://git.openjdk.org/nashorn.git pull/24/head

Using Skara CLI tools

Checkout this PR locally:
$ git pr checkout 24

View PR using the GUI difftool:
$ git pr show -t 24

Using diff file

Download this PR as a diff file:
https://git.openjdk.org/nashorn/pull/24.diff

davidekholm avatar Feb 06 '25 13:02 davidekholm

Hi @davidekholm, welcome to this OpenJDK project and thanks for contributing!

We do not recognize you as Contributor and need to ensure you have signed the Oracle Contributor Agreement (OCA). If you have not signed the OCA, please follow the instructions. Please fill in your GitHub username in the "Username" field of the application. Once you have signed the OCA, please let us know by writing /signed in a comment in this pull request.

If you already are an OpenJDK Author, Committer or Reviewer, please click here to open a new issue so that we can record that fact. Please use "Add GitHub user davidekholm" as summary for the issue.

If you are contributing this work on behalf of your employer and your employer has signed the OCA, please let us know by writing /covered in a comment in this pull request.

bridgekeeper[bot] avatar Feb 06 '25 13:02 bridgekeeper[bot]

❗ This change is not yet ready to be integrated. See the Progress checklist in the description for automated requirements.

openjdk[bot] avatar Feb 06 '25 13:02 openjdk[bot]

@davidekholm This pull request has been inactive for more than 4 weeks and will be automatically closed if another 4 weeks passes without any activity. To avoid this, simply add a new comment to the pull request. Feel free to ask for assistance if you need help with progressing this pull request towards integration!

bridgekeeper[bot] avatar Mar 06 '25 15:03 bridgekeeper[bot]

I've signed the OCA. My github username is [email protected] /David

davidekholm avatar Mar 06 '25 16:03 davidekholm

@davidekholm This pull request has been inactive for more than 4 weeks and will be automatically closed if another 4 weeks passes without any activity. To avoid this, simply add a new comment to the pull request. Feel free to ask for assistance if you need help with progressing this pull request towards integration!

bridgekeeper[bot] avatar Apr 03 '25 19:04 bridgekeeper[bot]

/signed

davidekholm avatar Apr 03 '25 21:04 davidekholm

Hi David, thank you for submitting this contribution.

This class has a putAll method because it is specified in javax.script.Bindings (and indirectly, from java.util.Map.) These interfaces do not prescribe a removeAll method, though and I'm reluctant to add to it methods not required by the interfaces, although they admittedly have few already.

The usual way you remove multiple elements from a Map by the key is through map.keySet().removeAll(…). Unfortunately, you can't do this with ScriptObjectMirror.keySet() as it is currently not coded to the spec which says:

Returns a Set view of the keys contained in this map. The set is backed by the map, so changes to the map are reflected in the set, and vice-versa. … The set supports element removal, which removes the corresponding mapping from the map, via the Iterator.remove, Set.remove, removeAll, retainAll, and clear operations. It does not support the add or addAll operations.

Basically, we should have keySet(), entrySet(), and values() implementations that are live views of the Map, instead of current implementation where they're creating copies. The proper way to go about this would be to implement these methods to return live views of the underlying Map and then you could use scriptObjectMirror.keySet().removeAll(…) to remove multiple elements (and you could specialize any method you need for performance.)

Does this sound like something you'd be comfortable undertaking? Let me know. If not, I'll still give some thought to maybe adopting this method as it is now.

szegedi avatar Apr 17 '25 13:04 szegedi

I understand your reasoning, but I'm afraid that me undertaking the task of ensuring that the returned data is a live view will be like opening a can of worms. I simply cannot foresee the side effects this may have.

davidekholm avatar Apr 17 '25 13:04 davidekholm

@davidekholm This pull request has been inactive for more than 4 weeks and will be automatically closed if another 4 weeks passes without any activity. To avoid this, simply issue a /touch or /keepalive command to the pull request. Feel free to ask for assistance if you need help with progressing this pull request towards integration!

bridgekeeper[bot] avatar May 16 '25 09:05 bridgekeeper[bot]

@davidekholm This pull request has been inactive for more than 8 weeks and will now be automatically closed. If you would like to continue working on this pull request in the future, feel free to reopen it! This can be done using the /open pull request command.

bridgekeeper[bot] avatar Jun 13 '25 14:06 bridgekeeper[bot]