protocolbuffers / protobuf-javascript

BSD 3-Clause "New" or "Revised" License
367 stars 67 forks source link

Using JS typed arrays in JoinFloat #87

Open tomasreimers opened 7 years ago

tomasreimers commented 7 years ago

Hi,

Has anyone thought of using JS typed arrays in the splitFloat and joinFloat methods for the JavaScript library (https://github.com/google/protobuf/blob/master/js/binary/utils.js#L388)?

One could imagine adding something like:

jspb.utils.joinFloat64 = function(bitsLow, bitsHigh) {
    if (window.Uint32Array) {
        bytes = Uint8Array.of(bitsLow, bitsHigh)
        data = new Float64Array(bytes.buffer)
        return data[0];
    }
    // ...
}

And vica-versa for the splitFloat method. This might increase readability (and depending on if it taps into the JS engine's native implementation, maybe even speed).

Happy to write the PR, just curious if it would be useful / appreciated!

Let me know,

dibenede commented 2 years ago

This is reasonable, but we'd need performance data to justify it.