Skip to content

Commit

Permalink
src: inline SLICE_START_END() in node_buffer.cc
Browse files Browse the repository at this point in the history
This macro is only used once, so it doesn’t need to be a macro.

PR-URL: #29357
Reviewed-By: Jiawen Geng <technicalcute@gmail.com>
Reviewed-By: Masashi Hirano <shisama07@gmail.com>
Reviewed-By: Colin Ihrig <cjihrig@gmail.com>
Reviewed-By: Luigi Pinca <luigipinca@gmail.com>
Reviewed-By: James M Snell <jasnell@gmail.com>
Reviewed-By: Richard Lau <riclau@uk.ibm.com>
Reviewed-By: Michael Dawson <michael_dawson@ca.ibm.com>
  • Loading branch information
addaleax authored and BridgeAR committed Sep 3, 2019
1 parent 1dc5ded commit 00ed7d1
Showing 1 changed file with 7 additions and 10 deletions.
17 changes: 7 additions & 10 deletions src/node_buffer.cc
Original file line number Diff line number Diff line change
Expand Up @@ -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 {

Expand Down Expand Up @@ -467,7 +458,13 @@ void StringSlice(const FunctionCallbackInfo<Value>& 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<Value> error;
MaybeLocal<Value> ret =
Expand Down

0 comments on commit 00ed7d1

Please sign in to comment.