Skip to content

Commit

Permalink
src: simplify SlicedArguments
Browse files Browse the repository at this point in the history
Re-use the existing `MaybeStackBuffer` logic for `SlicedArguments`.

PR-URL: #25745
Reviewed-By: James M Snell <jasnell@gmail.com>
Reviewed-By: Colin Ihrig <cjihrig@gmail.com>
  • Loading branch information
addaleax committed Jan 30, 2019
1 parent 35454e0 commit be499c3
Show file tree
Hide file tree
Showing 4 changed files with 19 additions and 33 deletions.
10 changes: 5 additions & 5 deletions src/inspector_js_api.cc
Original file line number Diff line number Diff line change
Expand Up @@ -139,7 +139,7 @@ void CallAndPauseOnStart(const FunctionCallbackInfo<v8::Value>& args) {
env->inspector_agent()->PauseOnNextJavascriptStatement("Break on start");
v8::MaybeLocal<v8::Value> retval =
args[0].As<v8::Function>()->Call(env->context(), args[1],
call_args.size(), call_args.data());
call_args.length(), call_args.out());
if (!retval.IsEmpty()) {
args.GetReturnValue().Set(retval.ToLocalChecked());
}
Expand All @@ -164,8 +164,8 @@ void InspectorConsoleCall(const FunctionCallbackInfo<Value>& info) {
v8::True(isolate)).FromJust());
CHECK(!inspector_method.As<Function>()->Call(context,
info.Holder(),
call_args.size(),
call_args.data()).IsEmpty());
call_args.length(),
call_args.out()).IsEmpty());
}
CHECK(config_object->Delete(context, in_call_key).FromJust());
}
Expand All @@ -174,8 +174,8 @@ void InspectorConsoleCall(const FunctionCallbackInfo<Value>& info) {
CHECK(node_method->IsFunction());
node_method.As<Function>()->Call(context,
info.Holder(),
call_args.size(),
call_args.data()).FromMaybe(Local<Value>());
call_args.length(),
call_args.out()).FromMaybe(Local<Value>());
}

static void* GetAsyncTask(int64_t asyncId) {
Expand Down
4 changes: 2 additions & 2 deletions src/node_perf.cc
Original file line number Diff line number Diff line change
Expand Up @@ -344,10 +344,10 @@ void TimerFunctionCall(const FunctionCallbackInfo<Value>& args) {
v8::MaybeLocal<Value> ret;

if (is_construct_call) {
ret = fn->NewInstance(context, call_args.size(), call_args.data())
ret = fn->NewInstance(context, call_args.length(), call_args.out())
.FromMaybe(Local<Object>());
} else {
ret = fn->Call(context, args.This(), call_args.size(), call_args.data());
ret = fn->Call(context, args.This(), call_args.length(), call_args.out());
}

uint64_t end = PERFORMANCE_NOW();
Expand Down
11 changes: 11 additions & 0 deletions src/util-inl.h
Original file line number Diff line number Diff line change
Expand Up @@ -455,6 +455,17 @@ v8::MaybeLocal<v8::Value> ToV8Value(v8::Local<v8::Context> context,
return v8::Number::New(isolate, static_cast<double>(number));
}

SlicedArguments::SlicedArguments(
const v8::FunctionCallbackInfo<v8::Value>& args, size_t start) {
const size_t length = static_cast<size_t>(args.Length());
if (start >= length) return;
const size_t size = length - start;

AllocateSufficientStorage(size);
for (size_t i = 0; i < size; ++i)
(*this)[i] = args[i + start];
}

} // namespace node

#endif // defined(NODE_WANT_INTERNALS) && NODE_WANT_INTERNALS
Expand Down
27 changes: 1 addition & 26 deletions src/util.h
Original file line number Diff line number Diff line change
Expand Up @@ -629,37 +629,12 @@ constexpr T RoundUp(T a, T b) {
#define MUST_USE_RESULT
#endif

class SlicedArguments {
class SlicedArguments : public MaybeStackBuffer<v8::Local<v8::Value>> {
public:
inline explicit SlicedArguments(
const v8::FunctionCallbackInfo<v8::Value>& args, size_t start = 0);
inline size_t size() const { return size_; }
inline v8::Local<v8::Value>* data() { return data_; }

private:
size_t size_;
v8::Local<v8::Value>* data_;
v8::Local<v8::Value> fixed_[64];
std::vector<v8::Local<v8::Value>> dynamic_;
};

SlicedArguments::SlicedArguments(
const v8::FunctionCallbackInfo<v8::Value>& args, size_t start)
: size_(0), data_(fixed_) {
const size_t length = static_cast<size_t>(args.Length());
if (start >= length) return;
const size_t size = length - start;

if (size > arraysize(fixed_)) {
dynamic_.resize(size);
data_ = dynamic_.data();
}

for (size_t i = 0; i < size; ++i) data_[i] = args[i + start];

size_ = size;
}

} // namespace node

#endif // defined(NODE_WANT_INTERNALS) && NODE_WANT_INTERNALS
Expand Down

0 comments on commit be499c3

Please sign in to comment.