-
-
Notifications
You must be signed in to change notification settings - Fork 7
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
refactor: use for loop replace spread to fix stack overflow #15
base: main
Are you sure you want to change the base?
Changes from 1 commit
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -109,13 +109,16 @@ export class EditMap { | |
events.length = this.map[index][0] | ||
} | ||
|
||
vecs.push([...events]) | ||
vecs.push(events.slice()) | ||
events.length = 0 | ||
|
||
let slice = vecs.pop() | ||
|
||
while (slice) { | ||
events.push(...slice) | ||
// NOTE: do not use spread operator here, it will cause a stack overflow. | ||
for (let i = 0; i < slice.length; i++) { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Adding a loop could could significant negative performance impact. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I try to use |
||
events.push(slice[i]) | ||
} | ||
slice = vecs.pop() | ||
} | ||
|
||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Better than a comment, would be a test that fails with the current logic and passes after
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I add a large markdown file to
test/fixtures
, it will fail when run the original codes.There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks, could we remove this comment now, since the test will cover it?