Skip to content

fix: improve Clone function to preserve nilness and avoid liveness issues#740

Merged
samber merged 1 commit intosamber:masterfrom
quexer:master
Nov 7, 2025
Merged

fix: improve Clone function to preserve nilness and avoid liveness issues#740
samber merged 1 commit intosamber:masterfrom
quexer:master

Conversation

@quexer
Copy link
Copy Markdown
Contributor

@quexer quexer commented Nov 7, 2025

This pull request updates the implementation of the Clone function in slice.go to improve its behavior and future compatibility. The main change is a safer cloning approach that avoids potential issues with slice liveness and preserves nilness, aligning with improvements in Go 1.21.

Improvements to slice cloning:

  • Updated the Clone function to avoid using collection[:0:0], which could cause unwanted liveness when cloning zero-length slices of large arrays. The new implementation uses append(Slice{}, collection...) for safer cloning.
  • Added a check to preserve nilness of the input slice, ensuring that cloning a nil slice returns nil.
  • Included a comment indicating that this is a backport from slices.Clone in Go 1.21 and can be replaced once support for Go 1.20 is dropped.

@codecov
Copy link
Copy Markdown

codecov bot commented Nov 7, 2025

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 94.01%. Comparing base (d99edab) to head (e1baff2).
⚠️ Report is 1 commits behind head on master.

Additional details and impacted files
@@            Coverage Diff             @@
##           master     #740      +/-   ##
==========================================
- Coverage   94.04%   94.01%   -0.04%     
==========================================
  Files          18       18              
  Lines        2838     2840       +2     
==========================================
+ Hits         2669     2670       +1     
- Misses        152      153       +1     
  Partials       17       17              
Flag Coverage Δ
unittests 94.01% <100.00%> (-0.04%) ⬇️

Flags with carried forward coverage won't be shown. Click here to find out more.

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.

@samber samber merged commit dc14b52 into samber:master Nov 7, 2025
11 of 12 checks passed
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