fix: replace deprecated reflect.SliceHeader with unsafe.Slice#366
Open
dlevy-msft-sql wants to merge 1 commit into
Open
fix: replace deprecated reflect.SliceHeader with unsafe.Slice#366dlevy-msft-sql wants to merge 1 commit into
dlevy-msft-sql wants to merge 1 commit into
Conversation
Codecov Report✅ All modified and coverable lines are covered by tests. Additional details and impacted files@@ Coverage Diff @@
## main #366 +/- ##
===========================================
+ Coverage 80.66% 96.62% +15.95%
===========================================
Files 35 92 +57
Lines 6842 74273 +67431
===========================================
+ Hits 5519 71764 +66245
- Misses 1055 2176 +1121
- Partials 268 333 +65
Flags with carried forward coverage won't be shown. Click here to find out more.
🚀 New features to boost your workflow:
|
74022f2 to
5368a77
Compare
reflect.SliceHeader was deprecated in Go 1.21. Replace the manual slice header manipulation with unsafe.Slice which is the recommended modern alternative (available since Go 1.17). The new code is also simpler and clearer: a single unsafe.Slice call replaces 7 lines of manual header field assignments. Fixes microsoft#272
5368a77 to
1784275
Compare
There was a problem hiding this comment.
Pull request overview
Updates the UCS-2 decoding fast/slow-path implementation to remove use of deprecated reflect.SliceHeader in favor of the modern unsafe.Slice API, aligning the driver with Go 1.21+ guidance while preserving the existing optimization approach.
Changes:
- Removed the
reflectimport and manualreflect.SliceHeadermanipulation inucs22str.go. - Replaced the byte-slice-to-uint16-slice reinterpretation with a single
unsafe.Slicecall for the UTF-16 decode slow path.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Problem
The UCS-2 string decoding optimization in
ucs22str.gousesreflect.SliceHeaderwhich was deprecated in Go 1.21. The deprecation notice recommends usingunsafe.Sliceinstead.Fix
Replace 7 lines of manual slice header manipulation:
With a single
unsafe.Slicecall:This is equivalent behavior: both reinterpret the underlying
[]byteas[]uint16for the subsequentutf16.Decodecall. Theunsafe.Sliceversion is the recommended modern pattern and lets the compiler/GC properly track the pointer.Tests
All 17 UCS-2 string conversion tests pass, covering ASCII (lengths 1-9+), Unicode, and emoji inputs.
Fixes #272