Skip to content

Accept a Uint8Array so as not to waste memory and time? #22

Open
@greggman

Description

@greggman

As it is, if you have some Uint8Array that is a view into a larger ArrayBuffer then a copy of the data is made in encode because new Uint8Array(someOtherUint8Array) makes new ArrayBuffer with a copy of the data. Where as you could just use the Uint8Array passed in?

Basically this would change

  exports.encode = function(arraybuffer) {
    var bytes = new Uint8Array(arraybuffer),

To something like

  exports.encode = function(arraybuffer) {
    var bytes = (arrayBuffer instanceof Uint8Array || arrayBuffer instanceof Uint8ClampArray)
            ? arrayBuffer
            : new Uint8Array(arraybuffer),


Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions