Skip to content

Commit

Permalink
http2: make Http2Settings constructors delegate
Browse files Browse the repository at this point in the history
This commit extracts the common code in the existing Http2Settings
constructors into a private constructor, allowing the existing ones to
delegate to the private constructor it and avoid code duplication.

PR-URL: #23326
Reviewed-By: James M Snell <jasnell@gmail.com>
Reviewed-By: Sakthipriyan Vairamani <thechargingvolcano@gmail.com>
  • Loading branch information
danbev authored and MylesBorins committed Nov 29, 2018
1 parent 7b4c4db commit d08d252
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 16 deletions.
27 changes: 11 additions & 16 deletions src/node_http2.cc
Original file line number Diff line number Diff line change
Expand Up @@ -226,32 +226,27 @@ void Http2Session::Http2Settings::Init() {
count_ = n;
}

Http2Session::Http2Settings::Http2Settings(
Environment* env)
Http2Session::Http2Settings::Http2Settings(Environment* env,
Http2Session* session, uint64_t start_time)
: AsyncWrap(env,
env->http2settings_constructor_template()
->NewInstance(env->context())
.ToLocalChecked(),
AsyncWrap::PROVIDER_HTTP2SETTINGS),
session_(nullptr),
startTime_(0) {
PROVIDER_HTTP2SETTINGS),
session_(session),
startTime_(start_time) {
Init();
}


Http2Session::Http2Settings::Http2Settings(Environment* env)
: Http2Settings(env, nullptr, 0) {}

// The Http2Settings class is used to configure a SETTINGS frame that is
// to be sent to the connected peer. The settings are set using a TypedArray
// that is shared with the JavaScript side.
Http2Session::Http2Settings::Http2Settings(
Http2Session* session)
: AsyncWrap(session->env(),
session->env()->http2settings_constructor_template()
->NewInstance(session->env()->context())
.ToLocalChecked(),
AsyncWrap::PROVIDER_HTTP2SETTINGS),
session_(session),
startTime_(uv_hrtime()) {
Init();
}
Http2Session::Http2Settings::Http2Settings(Http2Session* session)
: Http2Settings(session->env(), session, uv_hrtime()) {}

// Generates a Buffer that contains the serialized payload of a SETTINGS
// frame. This can be used, for instance, to create the Base64-encoded
Expand Down
1 change: 1 addition & 0 deletions src/node_http2.h
Original file line number Diff line number Diff line change
Expand Up @@ -1136,6 +1136,7 @@ class Http2Session::Http2Settings : public AsyncWrap {
get_setting fn);

private:
Http2Settings(Environment* env, Http2Session* session, uint64_t start_time);
void Init();
Http2Session* session_;
uint64_t startTime_;
Expand Down

0 comments on commit d08d252

Please sign in to comment.