Skip to content

Commit 48b16aa

Browse files
maclover7targos
authored andcommitted
zlib: instance-ify two methods
Both `Params` and `SetDictionary` take `ZCtx` as an arg, so just make them both instance methods on `ZCtx`. PR-URL: #21702 Reviewed-By: Anna Henningsen <[email protected]> Reviewed-By: Tiancheng "Timothy" Gu <[email protected]> Reviewed-By: Gus Caplan <[email protected]> Reviewed-By: Franziska Hinkelmann <[email protected]> Reviewed-By: Colin Ihrig <[email protected]> Reviewed-By: James M Snell <[email protected]>
1 parent b9bbbbe commit 48b16aa

File tree

1 file changed

+18
-22
lines changed

1 file changed

+18
-22
lines changed

src/node_zlib.cc

+18-22
Original file line numberDiff line numberDiff line change
@@ -486,7 +486,7 @@ class ZCtx : public AsyncWrap, public ThreadPoolWork {
486486
write_js_callback, dictionary, dictionary_len);
487487
if (!ret) goto end;
488488

489-
SetDictionary(ctx);
489+
ctx->SetDictionary();
490490

491491
end:
492492
return args.GetReturnValue().Set(ret);
@@ -496,14 +496,14 @@ class ZCtx : public AsyncWrap, public ThreadPoolWork {
496496
CHECK(args.Length() == 2 && "params(level, strategy)");
497497
ZCtx* ctx;
498498
ASSIGN_OR_RETURN_UNWRAP(&ctx, args.Holder());
499-
Params(ctx, args[0]->Int32Value(), args[1]->Int32Value());
499+
ctx->Params(args[0]->Int32Value(), args[1]->Int32Value());
500500
}
501501

502502
static void Reset(const FunctionCallbackInfo<Value> &args) {
503503
ZCtx* ctx;
504504
ASSIGN_OR_RETURN_UNWRAP(&ctx, args.Holder());
505505
ctx->Reset();
506-
SetDictionary(ctx);
506+
ctx->SetDictionary();
507507
}
508508

509509
static bool Init(ZCtx* ctx, int level, int windowBits, int memLevel,
@@ -577,51 +577,47 @@ class ZCtx : public AsyncWrap, public ThreadPoolWork {
577577
return true;
578578
}
579579

580-
static void SetDictionary(ZCtx* ctx) {
581-
if (ctx->dictionary_ == nullptr)
580+
void SetDictionary() {
581+
if (dictionary_ == nullptr)
582582
return;
583583

584-
ctx->err_ = Z_OK;
584+
err_ = Z_OK;
585585

586-
switch (ctx->mode_) {
586+
switch (mode_) {
587587
case DEFLATE:
588588
case DEFLATERAW:
589-
ctx->err_ = deflateSetDictionary(&ctx->strm_,
590-
ctx->dictionary_,
591-
ctx->dictionary_len_);
589+
err_ = deflateSetDictionary(&strm_, dictionary_, dictionary_len_);
592590
break;
593591
case INFLATERAW:
594592
// The other inflate cases will have the dictionary set when inflate()
595593
// returns Z_NEED_DICT in Process()
596-
ctx->err_ = inflateSetDictionary(&ctx->strm_,
597-
ctx->dictionary_,
598-
ctx->dictionary_len_);
594+
err_ = inflateSetDictionary(&strm_, dictionary_, dictionary_len_);
599595
break;
600596
default:
601597
break;
602598
}
603599

604-
if (ctx->err_ != Z_OK) {
605-
ctx->Error("Failed to set dictionary");
600+
if (err_ != Z_OK) {
601+
Error("Failed to set dictionary");
606602
}
607603
}
608604

609-
static void Params(ZCtx* ctx, int level, int strategy) {
610-
AllocScope alloc_scope(ctx);
605+
void Params(int level, int strategy) {
606+
AllocScope alloc_scope(this);
611607

612-
ctx->err_ = Z_OK;
608+
err_ = Z_OK;
613609

614-
switch (ctx->mode_) {
610+
switch (mode_) {
615611
case DEFLATE:
616612
case DEFLATERAW:
617-
ctx->err_ = deflateParams(&ctx->strm_, level, strategy);
613+
err_ = deflateParams(&strm_, level, strategy);
618614
break;
619615
default:
620616
break;
621617
}
622618

623-
if (ctx->err_ != Z_OK && ctx->err_ != Z_BUF_ERROR) {
624-
ctx->Error("Failed to set parameters");
619+
if (err_ != Z_OK && err_ != Z_BUF_ERROR) {
620+
Error("Failed to set parameters");
625621
}
626622
}
627623

0 commit comments

Comments
 (0)