Do not copy data in readArray when possible #70
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.
To avoid copying data (using slice), the TypedArray can be created with the arrayBuffer. However it handles only when start offset is a multiple of its type bytes occupancy (otherwise it will trigger similar error :
start offset of Int16Array should be a multiple of 2
). I'll use it when it is possible.However, since the data is not longer copied, this could have bad consequences if a depend library modified the read data.
I also move line
const slice = this.buffer.slice(offset, offset + bytes);
as in some case the variable is not used (when entering right after in the if condition).Note that I'm using similar code https://github.com/remmel/volograms-js/blob/92e3166cebe1dcb823291c11ec50dfb226d7dc99/src/BinaryReader.js#L68