-
-
Notifications
You must be signed in to change notification settings - Fork 407
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Initial implementation of Map() #550
Conversation
Codecov Report
@@ Coverage Diff @@
## master #550 +/- ##
==========================================
+ Coverage 69.87% 70.37% +0.49%
==========================================
Files 172 175 +3
Lines 10811 11145 +334
==========================================
+ Hits 7554 7843 +289
- Misses 3257 3302 +45
Continue to review full report at Codecov.
|
I'm not entirely sure what to do about the mutable key types lint. I think it should be OK because the values are cloned when they're placed in the HashMap and then again when they're removed, so it shouldn't be possible to modify that particular copy, but I'm probably missing something |
I've just done some additional testing and it seems the current implementation works. I tried creating an object and using it as the key in a map, then modifying the object and using it to get from the map, and it still got the value. |
About this I don't think |
when we clone a The way we extracting the data is a bit awkward though. |
That seems like it could work well. Unfortunately, there are a few places that might be a bit inefficient, but it would at least be correct. In order to maintain insertion order with removals, we'd have to use the shift_remove function, which is O(n). Likewise, when inserting a duplicate key the original would have to be removed so that the new one is placed at the back, rather than swapped in. For now, though, this would be good, and I'll work on swapping over.
But yes, modifying the data does feel a bit awkward, as updating the data requires cloning the hashmap and replacing the original. Using a RefCell could work, as could instance methods taking a mutable reference, although that might be quite a large architectural change. |
Sadly yes. but that's what the spec requires.
for insertion it replaces or appends if there isn't a duplicate key, right? https://tc39.es/ecma262/#sec-map.prototype.set step 4.a.i
Yes. for now we can use
It's because the |
Yes the way we do it is far from ideal. Edit: We can use |
Yes, sorry, you're completely right. That does simplify things then.
I don't think RefCell would work because Trace isn't implemented for it. GcCell works though. I also don't think Rc should be necessary, as there should only ever be one owner of the data. |
For this we need to set this to false for Maybe we should make https://github.com/boa-dev/boa/blob/master/boa/src/builtins/function/mod.rs#L416-L467 accept another parameter or an enum with field I think the bitfield would be much nicer and it would shrink the size of |
About this, we don't have iterator anywhere, also we don't support well-known symbols ( If you want we can leave this to be a separate PR, implementing |
Co-authored-by: HalidOdat <halidodat@gmail.com>
That's probably best, it would probably pollute the PR quite a lot, and I'm not sure whether I'd be able to implement it, although I'll have a go |
I see many changes in the diff not directly related to this PR, why is that? Could we rebase? |
I think this is due to how github is displaying the diffs, as described here. I changed the base branch away and back as described and it seems to be better now. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Looks good to me! :)
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Looks good to me. Should we add some benchmarks?
Co-authored-by: HalidOdat <halidodat@gmail.com>
This Pull Request closes #401.
It changes the following:
There are a few things that currently aren't implemented: