-
Notifications
You must be signed in to change notification settings - Fork 329
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
flate: Cleanup & reduce casts #1050
Conversation
Small improvement by reducing casts for matchlen.
📝 WalkthroughWalkthroughThis pull request introduces type modifications across multiple files in the Changes
Possibly related PRs
✨ Finishing Touches
Thank you for using CodeRabbit. We offer it for free to the OSS community and would appreciate your support in helping us grow. If you find it useful, would you consider giving us a shout-out on your favorite social media? 🪧 TipsChatThere are 3 ways to chat with CodeRabbit:
Note: Be mindful of the bot's finite context window. It's strongly recommended to break down tasks such as reading entire modules into smaller chunks. For a focused discussion, use review comments to chat about specific files and their changes, instead of using the PR comments. CodeRabbit Commands (Invoked using PR comments)
Other keywords and placeholders
CodeRabbit Configuration File (
|
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.
Actionable comments posted: 0
🧹 Nitpick comments (3)
internal/le/unsafe_disabled.go (1)
29-41
: LGTM! Store functions are correctly implemented.The Store functions correctly use
binary.LittleEndian
for endianness handling, ensuring consistent behavior across platforms.Consider adding examples in the documentation to show typical usage patterns:
// Store16 will store v at b. // // Example: // // b := make([]byte, 2) // Store16(b, 0x1234) // b now contains [0x34, 0x12]internal/le/unsafe_enabled.go (1)
11-16
: LGTM! Efficient unsafe implementation.The implementation correctly uses unsafe pointer arithmetic for optimal performance while maintaining the same behavior as the safe version.
Consider removing the commented-out previous implementations since they're no longer needed and might cause confusion:
- //return binary.LittleEndian.Uint16(b[i:]) - //return *(*uint16)(unsafe.Pointer(&b[i]))flate/level1.go (1)
123-123
: Consider using matchlen for small matches.For small matches (< 8 bytes), using
matchlen
might be more efficient thanmatchlenLong
as it avoids the function call overhead.- l := e.matchlenLong(int(s+4), int(t+4), src) + 4 + // Use matchlen for small matches + l := e.matchlen(src[s+4:], src[t+4:]) + 4 + if l >= 8 { + l = e.matchlenLong(int(s+4), int(t+4), src) + 4 + }Also applies to: 126-130
📜 Review details
Configuration used: CodeRabbit UI
Review profile: CHILL
Plan: Pro
📒 Files selected for processing (9)
flate/fast_encoder.go
(4 hunks)flate/level1.go
(6 hunks)flate/level2.go
(1 hunks)flate/level3.go
(1 hunks)flate/level4.go
(1 hunks)flate/level5.go
(6 hunks)flate/level6.go
(8 hunks)internal/le/unsafe_disabled.go
(1 hunks)internal/le/unsafe_enabled.go
(1 hunks)
✅ Files skipped from review due to trivial changes (1)
- flate/level3.go
⏰ Context from checks skipped due to timeout of 90000ms (16)
- GitHub Check: build (1.23.x, windows-latest)
- GitHub Check: build (1.23.x, macos-latest)
- GitHub Check: build (1.23.x, ubuntu-latest)
- GitHub Check: build (1.22.x, windows-latest)
- GitHub Check: build (1.22.x, macos-latest)
- GitHub Check: build (1.22.x, ubuntu-latest)
- GitHub Check: fuzz-zstd ("noasm,nounsafe")
- GitHub Check: fuzz-s2 ("noasm,nounsafe")
- GitHub Check: build (1.21.x, windows-latest)
- GitHub Check: fuzz-zstd (nounsafe)
- GitHub Check: fuzz-s2 (nounsafe)
- GitHub Check: build (1.21.x, macos-latest)
- GitHub Check: build (1.21.x, ubuntu-latest)
- GitHub Check: fuzz-other ("noasm,nounsafe")
- GitHub Check: fuzz-other (nounsafe)
- GitHub Check: Analyze (go)
🔇 Additional comments (8)
internal/le/unsafe_disabled.go (1)
9-12
: LGTM! Simple and correct implementation.The
Load8
function provides a straightforward and safe way to access bytes from a slice.flate/level1.go (1)
80-80
: LGTM! Improved readability with explicit offset calculation.The introduction of variable
t
makes the offset calculation clearer and reduces repeated expressions.Also applies to: 92-93
flate/level4.go (1)
130-130
: LGTM! Consistent type casting.The explicit casting to
int
aligns with the PR's goal of reducing unnecessary casts and maintains consistency with other level files.flate/fast_encoder.go (2)
Line range hint
139-180
: LGTM! Type change improves consistency.The change from
int32
toint
parameters aligns better with Go's native integer type and reduces type conversions when working with slice lengths.
Line range hint
181-220
: LGTM! Consistent with matchlen changes.The parameter type change to
int
maintains consistency withmatchlen
and Go's native types.flate/level2.go (1)
129-129
: LGTM! Necessary type cast for compatibility.The explicit casting to
int
is required to match the updatedmatchlenLong
signature.flate/level6.go (1)
127-128
: LGTM! Consistent type casting throughout the file.All calls to
matchlen
andmatchlenLong
have been updated with appropriateint
casts to match the new method signatures.Also applies to: 151-151, 165-165, 179-179, 190-190, 210-212, 230-230, 240-240
flate/level5.go (1)
122-123
: LGTM! Consistent type casting throughout the file.All calls to
matchlen
andmatchlenLong
have been updated with appropriateint
casts to match the new method signatures.Also applies to: 145-145, 157-157, 168-168, 188-190, 206-206
Small improvement by reducing casts for matchlen.
Sanity check before/after...
Summary by CodeRabbit
Release Notes
Performance Improvements
New Features
le
packageLoad8
,Store16
,Store32
, andStore64
utility methodsTechnical Updates
These changes optimize the compression and byte manipulation capabilities of the library, focusing on performance and type safety.