diff options
author | Divy Srivastava <dj.srivastava23@gmail.com> | 2023-07-07 09:09:25 +0530 |
---|---|---|
committer | GitHub <noreply@github.com> | 2023-07-07 09:09:25 +0530 |
commit | 75d2c045f79aee4f772cb235860e6ef340177a05 (patch) | |
tree | af410764bb2f78ccb668c029c4b17c3901aaceea /ext/websocket/01_websocket.js | |
parent | 679a0c428c2aeebdd5c23141d3653b8fbb9c41fc (diff) |
perf(ext/websocket): optimize server websocket js (#19719)
Split from https://github.com/denoland/deno/pull/19686
- timestamp set to 0 for server websocket events.
- take fast call path with op_ws_send_binary.
Diffstat (limited to 'ext/websocket/01_websocket.js')
-rw-r--r-- | ext/websocket/01_websocket.js | 11 |
1 files changed, 6 insertions, 5 deletions
diff --git a/ext/websocket/01_websocket.js b/ext/websocket/01_websocket.js index 50e110444..635979174 100644 --- a/ext/websocket/01_websocket.js +++ b/ext/websocket/01_websocket.js @@ -322,7 +322,12 @@ class WebSocket extends EventTarget { throw new DOMException("readyState not OPEN", "InvalidStateError"); } - if (ObjectPrototypeIsPrototypeOf(BlobPrototype, data)) { + if (ArrayBufferIsView(data)) { + op_ws_send_binary(this[_rid], data); + } else if (ObjectPrototypeIsPrototypeOf(ArrayBufferPrototype, data)) { + // deno-lint-ignore prefer-primordials + op_ws_send_binary(this[_rid], new Uint8Array(data)); + } else if (ObjectPrototypeIsPrototypeOf(BlobPrototype, data)) { PromisePrototypeThen( // deno-lint-ignore prefer-primordials data.slice().arrayBuffer(), @@ -332,10 +337,6 @@ class WebSocket extends EventTarget { new DataView(ab), ), ); - } else if (ArrayBufferIsView(data)) { - op_ws_send_binary(this[_rid], data); - } else if (ObjectPrototypeIsPrototypeOf(ArrayBufferPrototype, data)) { - op_ws_send_binary(this[_rid], data); } else { const string = String(data); op_ws_send_text( |