• There are quite a lot of flat strings .... Can it be the javascript code that is uploaded?

    Yes - if there's a decent size string to allocate Espruino will try and use a flat string since it's more space efficient, so that could be it. Using trace would tell you what's flat and what isn't.

    And yes, potentially compacting flat strings could be added. I think it just felt non-trivial at the time so I didn't add it.

    But yeah, ideally there'd be a way to get the string from an arraybuffer. I guess I could add a non-standard function like ArrayBuffer.getBackingString?

  • I guess I could add a non-standard function like ArrayBuffer.getBackingString?

    Yes, if E.toString is taken and not usable for this then why not. .asString() or .bufferString() could be shorter but naming is always hard :-) Also depends a bit how exactly it will work. For this code

    a1=new Uint8Array([1,2,3,4,5]);
    a2=new Uint8Array(a1.buffer,0,3)
    

    can I call a2.getBackingString() to get string of 3 bytes or is this method for underlying a2.buffer buffer. In first case there could be a2.buffer and a2.bufferString or a2.bufferAsString. For second case a2.buffer.getBackingString makes sense.

About

Avatar for Gordon @Gordon started