From 80c24c71127bcbe349064339bf6d33ae5c6cfa8c Mon Sep 17 00:00:00 2001 From: Anna Henningsen Date: Wed, 28 Aug 2019 14:35:36 +0200 Subject: [PATCH 1/2] src: inline `SLICE_START_END()` in node_buffer.cc MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit This macro is only used once, so it doesn’t need to be a macro. --- src/node_buffer.cc | 17 +++++++---------- 1 file changed, 7 insertions(+), 10 deletions(-) diff --git a/src/node_buffer.cc b/src/node_buffer.cc index d3a9abc571c42b..22f5ca56823495 100644 --- a/src/node_buffer.cc +++ b/src/node_buffer.cc @@ -44,15 +44,6 @@ return node::THROW_ERR_OUT_OF_RANGE(env, "Index out of range"); \ } while (0) \ -#define SLICE_START_END(env, start_arg, end_arg, end_max) \ - size_t start = 0; \ - size_t end = 0; \ - THROW_AND_RETURN_IF_OOB(ParseArrayIndex(env, start_arg, 0, &start)); \ - THROW_AND_RETURN_IF_OOB(ParseArrayIndex(env, end_arg, end_max, &end)); \ - if (end < start) end = start; \ - THROW_AND_RETURN_IF_OOB(Just(end <= end_max)); \ - size_t length = end - start; - namespace node { namespace Buffer { @@ -468,7 +459,13 @@ void StringSlice(const FunctionCallbackInfo& args) { if (buffer.length() == 0) return args.GetReturnValue().SetEmptyString(); - SLICE_START_END(env, args[0], args[1], buffer.length()) + size_t start = 0; + size_t end = 0; + THROW_AND_RETURN_IF_OOB(ParseArrayIndex(env, args[0], 0, &start)); + THROW_AND_RETURN_IF_OOB(ParseArrayIndex(env, args[1], buffer.length(), &end)); + if (end < start) end = start; + THROW_AND_RETURN_IF_OOB(Just(end <= buffer.length())); + size_t length = end - start; Local error; MaybeLocal ret = From b00f2db42e0446c0af959b8cfc549517648c4112 Mon Sep 17 00:00:00 2001 From: Anna Henningsen Date: Wed, 28 Aug 2019 14:37:18 +0200 Subject: [PATCH 2/2] src: turn `GET_OFFSET()` into an inline function MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit There’s no need for this to be a macro. --- src/node_file.cc | 11 +++++++---- 1 file changed, 7 insertions(+), 4 deletions(-) diff --git a/src/node_file.cc b/src/node_file.cc index c4e3b83392c5cc..ae2aa0677f6e89 100644 --- a/src/node_file.cc +++ b/src/node_file.cc @@ -88,7 +88,10 @@ constexpr char kPathSeparator = '/'; const char* const kPathSeparator = "\\/"; #endif -#define GET_OFFSET(a) (IsSafeJsInt(a) ? (a).As()->Value() : -1) +inline int64_t GetOffset(Local value) { + return IsSafeJsInt(value) ? value.As()->Value() : -1; +} + #define TRACE_NAME(name) "fs.sync." #name #define GET_TRACE_ENABLED \ (*TRACE_EVENT_API_GET_CATEGORY_GROUP_ENABLED \ @@ -1681,7 +1684,7 @@ static void WriteBuffer(const FunctionCallbackInfo& args) { CHECK_LE(len, buffer_length); CHECK_GE(off + len, off); - const int64_t pos = GET_OFFSET(args[4]); + const int64_t pos = GetOffset(args[4]); char* buf = buffer_data + off; uv_buf_t uvbuf = uv_buf_init(buf, len); @@ -1721,7 +1724,7 @@ static void WriteBuffers(const FunctionCallbackInfo& args) { CHECK(args[1]->IsArray()); Local chunks = args[1].As(); - int64_t pos = GET_OFFSET(args[2]); + int64_t pos = GetOffset(args[2]); MaybeStackBuffer iovs(chunks->Length()); @@ -1765,7 +1768,7 @@ static void WriteString(const FunctionCallbackInfo& args) { CHECK(args[0]->IsInt32()); const int fd = args[0].As()->Value(); - const int64_t pos = GET_OFFSET(args[2]); + const int64_t pos = GetOffset(args[2]); const auto enc = ParseEncoding(isolate, args[3], UTF8);