C: Revert lazy array initialization and restore hb_array_size() usage
#1025
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
This pull request reverts #885 which caused memory issues in WebAssembly by always allocating arrays, even when
NULLwas passed.The
hb_array_size()function safely returns0forNULLarrays, eliminating the need for allocating arrays for all AST Nodes. This was causing the"Cannot enlarge memory"errors in WASM builds, as seen in #1016.This pull request brings back
hb_array_size()in places where we previously accessedarray->sizedirectly. With that, we don't need to allocatearray_init(8)just so we can assume we always have asize.The problem is, even if we would use
array_init(0)it would allocate memory that we are not going to need. So for now, I think it's better to be avoid allocating arrays and usehb_array_size()until we have fully integrated the new array implementation from #782. (/cc @timkaechele).I also added a
hb_narray_size()for API consistency that should help with the future array migration.Resolves #1016
(Might also resolve #993)