Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

perf: simplify req.accepts* #56

Merged
merged 3 commits into from
Nov 16, 2024
Merged

perf: simplify req.accepts* #56

merged 3 commits into from
Nov 16, 2024

Conversation

nigrosimone
Copy link
Contributor

@nigrosimone nigrosimone commented Nov 16, 2024

  • No need to declare a new variable const accept = accepts({ headers: this.headers }); e8bb956
  • No need to create a object accepts({ headers: this.headers }) 6ff51e6

Bonus Improvements:

Copy link

pkg-pr-new bot commented Nov 16, 2024

Open in Stackblitz

npm i https://pkg.pr.new/dimdenGD/ultimate-express@56

commit: 6ff51e6

@nigrosimone
Copy link
Contributor Author

nigrosimone commented Nov 16, 2024

@dimdenGD Maybe we can also cache accepts(this) initialization, eg: ?

 accepts(...types) {
    if (!this.#accepts) {
      this.#accepts = accepts(this);
    }
    return this.#accepts.types(...types);
  }

  acceptsCharsets(...charsets) {
    if (!this.#accepts) {
      this.#accepts = accepts(this);
    }
    return this.#accepts.charsets(...charsets);
  }

  acceptsEncodings(...encodings) {
    if (!this.#accepts) {
      this.#accepts = accepts(this);
    }
    return this.#accepts.encodings(...encodings);
  }

  acceptsLanguages(...languages) {
    if (!this.#accepts) {
      this.#accepts = accepts(this);
    }
    return this.#accepts.languages(...languages);
  }

@nigrosimone nigrosimone changed the title simplify req.acceptsEncodings simplify req.accepts* Nov 16, 2024
@nigrosimone nigrosimone changed the title simplify req.accepts* perf: simplify req.accepts* Nov 16, 2024
@dimdenGD
Copy link
Owner

Probably no point in caching because calling that function just creates a class with no real work done until function is called

@dimdenGD dimdenGD merged commit a027b92 into dimdenGD:main Nov 16, 2024
6 checks passed
@nigrosimone nigrosimone deleted the patch-1 branch November 17, 2024 03:55
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants