-
Notifications
You must be signed in to change notification settings - Fork 447
fix(uverse): overlap handling in append/copy for slice-backed lists #5128
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
base: master
Are you sure you want to change the base?
Conversation
🛠 PR Checks Summary🔴 Pending initial approval by a review team member, or review from tech-staff Manual Checks (for Reviewers):
Read More🤖 This bot helps streamline PR reviews by verifying automated checks and providing guidance for contributors and reviewers. ✅ Automated Checks (for Contributors):🟢 Maintainers must be able to edit this pull request (more info) ☑️ Contributor Actions:
☑️ Reviewer Actions:
📚 Resources:Debug
|
Codecov Report✅ All modified and coverable lines are covered by tests. 📢 Thoughts on this report? Let us know! |
Davphla
left a comment
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.
Fix works great, all comments are refacto / nitpick
gnovm/pkg/gnolang/uverse.go
Outdated
| for i := arg1Length - 1; i >= 0; i-- { | ||
| oldElem := list[dstStart+i] | ||
| // unrefCopy will resolve references and copy their values | ||
| // to copy by value rather than by reference. |
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.
This comment can be simplified
| srcEnd := arg1Offset + arg1Length | ||
| overlap := arg0Base == arg1Base && dstStart < srcEnd && srcStart < dstEnd | ||
| // Overlap-safe copy: copy backward when dst starts after src to avoid clobbering. | ||
| if overlap && dstStart > srcStart { |
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.
This double duplicate loop can be simplified either by doing a sub helper function, or something like that:
step := 1
start := 0
if overlap && dstStart > srcStart {
step = -1
start = arg1Length - 1
}
for i := start; i >= 0 && i < arg1Length; i += step {
oldElem := list[dstStart+i]
newElem := arg1Base.List[arg1Offset+i].unrefCopy(m.Alloc, m.Store)
list[dstStart+i] = newElem
m.Realm.DidUpdate(
arg0Base,
oldElem.GetFirstObject(m.Store),
newElem.GetFirstObject(m.Store),
)
}I think it would be much easier to read
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.
nice suggestion ^^
| srcEnd := srcStart + minl | ||
| overlap := dstBase == srcBase && dstStart < srcEnd && srcStart < dstEnd | ||
| // Overlap-safe copy: copy backward when dst starts after src to avoid clobbering. | ||
| if overlap && dstStart > srcStart { |
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.
same for this one
| s4 := []byte{0, 1, 2, 3, 4} | ||
| r4 := append(s4[:1], s4[2:4]...) | ||
| fmt.Println("append overlap bytes:", r4) // [0 2 3] | ||
| } |
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.
It's missing the case where it append to itself (fixed by that PR)
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.
WDYM, Can you give me an example ?
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.
Example:
r4 := append(s4[:1], s4...)It's not essential to add tbh
Uh oh!
There was an error while loading. Please reload this page.