Skip to content

Commit 9f4be5d

Browse files
danbevMylesBorins
authored andcommitted
http2: make Http2Settings constructors delegate
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>
1 parent dad3d74 commit 9f4be5d

File tree

2 files changed

+12
-16
lines changed

2 files changed

+12
-16
lines changed

src/node_http2.cc

+11-16
Original file line numberDiff line numberDiff line change
@@ -226,32 +226,27 @@ void Http2Session::Http2Settings::Init() {
226226
count_ = n;
227227
}
228228

229-
Http2Session::Http2Settings::Http2Settings(
230-
Environment* env)
229+
Http2Session::Http2Settings::Http2Settings(Environment* env,
230+
Http2Session* session, uint64_t start_time)
231231
: AsyncWrap(env,
232232
env->http2settings_constructor_template()
233233
->NewInstance(env->context())
234234
.ToLocalChecked(),
235-
AsyncWrap::PROVIDER_HTTP2SETTINGS),
236-
session_(nullptr),
237-
startTime_(0) {
235+
PROVIDER_HTTP2SETTINGS),
236+
session_(session),
237+
startTime_(start_time) {
238238
Init();
239239
}
240240

241+
242+
Http2Session::Http2Settings::Http2Settings(Environment* env)
243+
: Http2Settings(env, nullptr, 0) {}
244+
241245
// The Http2Settings class is used to configure a SETTINGS frame that is
242246
// to be sent to the connected peer. The settings are set using a TypedArray
243247
// that is shared with the JavaScript side.
244-
Http2Session::Http2Settings::Http2Settings(
245-
Http2Session* session)
246-
: AsyncWrap(session->env(),
247-
session->env()->http2settings_constructor_template()
248-
->NewInstance(session->env()->context())
249-
.ToLocalChecked(),
250-
AsyncWrap::PROVIDER_HTTP2SETTINGS),
251-
session_(session),
252-
startTime_(uv_hrtime()) {
253-
Init();
254-
}
248+
Http2Session::Http2Settings::Http2Settings(Http2Session* session)
249+
: Http2Settings(session->env(), session, uv_hrtime()) {}
255250

256251
// Generates a Buffer that contains the serialized payload of a SETTINGS
257252
// frame. This can be used, for instance, to create the Base64-encoded

src/node_http2.h

+1
Original file line numberDiff line numberDiff line change
@@ -1136,6 +1136,7 @@ class Http2Session::Http2Settings : public AsyncWrap {
11361136
get_setting fn);
11371137

11381138
private:
1139+
Http2Settings(Environment* env, Http2Session* session, uint64_t start_time);
11391140
void Init();
11401141
Http2Session* session_;
11411142
uint64_t startTime_;

0 commit comments

Comments
 (0)