summaryrefslogtreecommitdiff
path: root/src/main.cc
diff options
context:
space:
mode:
authorBert Belder <bertbelder@gmail.com>2018-07-09 03:35:34 +0200
committerBert Belder <bertbelder@gmail.com>2018-07-12 21:26:38 +0200
commit24b0e91d8096f84a114f662e3eb42c83d0d3878d (patch)
treeacd9ae306618276020e75450c064ead463e64387 /src/main.cc
parentbbcd4c8dd33121868d82123a3d36e3df282af45f (diff)
Move buffers between V8 and native
* send()/recv() now operate on TypedArrays rather than ArrayBuffers. * Remove a copy (through ArrayBuffer.slice()) from the send path. * Remove a copy (through v8::ArrayBuffer::New()) from the return path. * After moving a buffer from JS to native, the ArrayBuffer object and it's views are made inaccessible ('neutered'). * `struct deno_buf` now holds two [ptr, length] tuples, one for the actual memory allocation, and one for the logical data contained therein. This is necessary because flatbuffers fills it's buffer bottom-up, so the serialized blob doesn't start at beginning of the buffer, but somewhere in the middle.
Diffstat (limited to 'src/main.cc')
-rw-r--r--src/main.cc12
1 files changed, 5 insertions, 7 deletions
diff --git a/src/main.cc b/src/main.cc
index a801bc292..81b8a2710 100644
--- a/src/main.cc
+++ b/src/main.cc
@@ -11,6 +11,7 @@
#endif
#include "deno.h"
+#include "flatbuffer_builder.h"
#include "flatbuffers/flatbuffers.h"
#include "src/handlers.h"
#include "src/msg_generated.h"
@@ -23,7 +24,7 @@ static int global_argc;
// Sends StartRes message
void HandleStart(Deno* d, uint32_t cmd_id) {
- flatbuffers::FlatBufferBuilder builder;
+ deno::FlatBufferBuilder builder;
char cwdbuf[1024];
// TODO(piscisaureus): support unicode on windows.
@@ -39,9 +40,7 @@ void HandleStart(Deno* d, uint32_t cmd_id) {
auto start_msg = CreateStartRes(builder, start_cwd, start_argv);
auto base = CreateBase(builder, cmd_id, 0, Any_StartRes, start_msg.Union());
builder.Finish(base);
- deno_buf bufout{reinterpret_cast<const char*>(builder.GetBufferPointer()),
- builder.GetSize()};
- deno_set_response(d, bufout);
+ deno_set_response(d, builder.ExportBuf());
}
void HandleCodeFetch(Deno* d, uint32_t cmd_id, const CodeFetch* msg) {
@@ -54,11 +53,10 @@ void HandleCodeFetch(Deno* d, uint32_t cmd_id, const CodeFetch* msg) {
}
void MessagesFromJS(Deno* d, deno_buf buf) {
- auto data = reinterpret_cast<const uint8_t*>(buf.data);
- flatbuffers::Verifier verifier(data, buf.len);
+ flatbuffers::Verifier verifier(buf.data_ptr, buf.data_len);
DCHECK(verifier.VerifyBuffer<Base>());
- auto base = flatbuffers::GetRoot<Base>(buf.data);
+ auto base = flatbuffers::GetRoot<Base>(buf.data_ptr);
auto cmd_id = base->cmdId();
auto msg_type = base->msg_type();
const char* msg_type_name = EnumNamesAny()[msg_type];