-
-
Notifications
You must be signed in to change notification settings - Fork 841
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
avm2: Add support for sparse arrays #15491
Conversation
The uses of |
Not blocking, but I just realized that several places in |
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.
After reading through most of the array code my main concern is just documenting what the usize
parameters do, since that was the biggest thing I was confused about. That's the only thing I feel needs to be fixed before I can merge this.
The splice code seemed straightforward once I puzzled out what it was doing, and it's probably correct. I'm a bit iffy about "drop to splice" as an API but it shouldn't impact correctness in this case. (Remember that memory leaks are safe and that Drop
doesn't always run!)
core/src/avm2/array.rs
Outdated
index_back: usize, | ||
} | ||
|
||
pub struct ArrayStorageMutableIterator<'a, 'gc> { |
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.
If I'm reading the rest of the code correctly, the Mutable
variants of the array storage iterator exist primarily so the splice iterators can call into their next
/prev
methods? It seems awkward, but I'm not aware of a more elegant way to do this...
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.
It exists because I don't know how to implement it without a mutable iterator 😅
core/src/avm2/array.rs
Outdated
storage, | ||
occupied_count, | ||
} => { | ||
if storage.len() < (item + 1) { |
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.
I think this can be item >= storage.len()
core/src/avm2/array.rs
Outdated
|
||
/// Convert the array storage to a sparse representation. | ||
fn convert_to_sparse(&mut self) { | ||
match self { |
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.
Can these be rewritten without the match? Would be a bit shorter
if let ArrayStorage::Dense { storage, .. } = self {
core/src/avm2/array.rs
Outdated
|
||
/// Convert the array to a sparse representation if it meets the criteria. | ||
fn maybe_convert_to_sparse(&mut self) { | ||
match self { |
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.
same as above
core/src/avm2/array.rs
Outdated
/// Convert the array to a dense representation if it meets the criteria. | ||
fn maybe_convert_to_dense(&mut self) { | ||
match self { | ||
ArrayStorage::Dense { .. } => {} |
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.
same
This attempts to implement sparse arrays. There are (as of creating this pull request) big caveats:
dense arrays are turned into sparse arrays only if they go beyond current array length and conditions for conversion into sparse arrays from avmplus aren't implementeddense arrays do not implement m_denseStart from avmplus, this might need a custom VecIt does pass tests and also fixes some known failures.