Skip to content

Rewrite line number computation in WSL#304

Open
jrmuizel wants to merge 1 commit into
WebKit:mainfrom
jrmuizel:main
Open

Rewrite line number computation in WSL#304
jrmuizel wants to merge 1 commit into
WebKit:mainfrom
jrmuizel:main

Conversation

@jrmuizel
Copy link
Copy Markdown
Contributor

@jrmuizel jrmuizel commented Apr 22, 2026

Instead of computing the line number on demand, keep track of it as we lex.

Previously, we ended up spending a quadratic amount of time computing the line number because we'd do something like:

for every index:
        count the number line breaks up to this index.

Fixes #298

@netlify
Copy link
Copy Markdown

netlify Bot commented Apr 22, 2026

Deploy Preview for webkit-jetstream-preview ready!

Name Link
🔨 Latest commit a47226e
🔍 Latest deploy log https://app.netlify.com/projects/webkit-jetstream-preview/deploys/6a20828e4bd40c00088a9a57
😎 Deploy Preview https://deploy-preview-304--webkit-jetstream-preview.netlify.app
📱 Preview on mobile
Toggle QR Code...

QR Code

Use your smartphone camera to open QR code link.

To edit notification comments on pull requests, go to your Netlify project configuration.

@jrmuizel
Copy link
Copy Markdown
Contributor Author

jrmuizel commented Jun 3, 2026

@camillobruni review ping

Copy link
Copy Markdown
Contributor

@kmiller68 kmiller68 left a comment

Choose a reason for hiding this comment

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

Overall seems like a reasonable change. I do think most devs will end up using a regex for this so I'd mildly prefer keeping that. That's also how the original test was structured so all other things equal I'd prefer to keep it.

I know it's maybe(?) faster to use the manual loop due to Array allocation but we shouldn't be optimizing the benchmark itself.

Comment thread WSL/Lexer.js Outdated
Instead of computing the line number on demand, keep track of it as we
lex.

Previously, we ended up spending a quadratic amount of time computing
the line number because we'd do something like:
for every index:
        count the number line breaks up to this index.

Fixes WebKit#298
Copy link
Copy Markdown
Contributor

@kmiller68 kmiller68 left a comment

Choose a reason for hiding this comment

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

LGTM

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.

Rewrite line number computation in WSL

2 participants