Skip to content

Conversation

@jridgewell
Copy link
Contributor

@jridgewell jridgewell commented Aug 1, 2022

This replaces the String.p.replace uses that are only used for side-effects with a faster RegExp.p.exec loop. This avoids the string allocation of the output string, and makes it a little more clear the loop is used for side-effects.

@vercel
Copy link

vercel bot commented Aug 1, 2022

The latest updates on your projects. Learn more about Vercel for Git ↗︎

Name Status Preview Updated
hacker-news-slack-bot ✅ Ready (Inspect) Visit Preview Aug 4, 2022 at 11:44PM (UTC)

@jridgewell jridgewell requested a review from steven-tey August 1, 2022 22:12
Copy link
Contributor

@steven-tey steven-tey left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Left a couple of comments!

// actually matched, so that we can extract the appropriate keyword.
combineText(post).replace(termsRegex, (_, ...terms: string[]) => {
let match;
while ((match = termsRegex.exec(combined))) {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

is this an equals sign = or an equality == comparison?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Equals. In this situation, the extra parens are meant to indicate that this is an intentional assignment. See https://eslint.org/docs/latest/rules/no-cond-assign


text.replace(scanner, (_, ...terms) => {
let match;
while ((match = scanner.exec(text))) {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Should this be an equality == comparison?

Copy link

@omkarkulkarni2704 omkarkulkarni2704 Dec 5, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

No, scanner.exec(text) checks null. So == is not needed.

@leerob
Copy link
Contributor

leerob commented Aug 2, 2022

Could we add a description so it's clear what this PR solves? 🙏

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.

5 participants