-
Notifications
You must be signed in to change notification settings - Fork 273
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
feat: optimize the fast key format and encoding #923
Conversation
WalkthroughThe recent updates aim to improve code efficiency, readability, and maintainability. Key enhancements include introducing new encoding functions, a fast prefix formatter, and refining node key and hash handling. The restructuring of tree modification processes and adjustments in logging and key management strategies contribute to streamlining operations and reducing complexity. Changes
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 as PR comments)
Additionally, you can add CodeRabbit Configration File (
|
func (f *FastPrefixFormatter) Scan(key []byte, a interface{}) { | ||
scan(a, key[1:]) |
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.
The Scan
method lacks error handling or validation for the input parameters. Specifically, it assumes that the key
slice has at least one element without checking, which could lead to a runtime panic if called with an empty slice.
Consider adding validation to ensure that the key
slice is not empty before accessing its elements to prevent potential runtime panics.
@@ -620,7 +624,7 @@ func (node *Node) writeBytes(w io.Writer) error { | |||
return fmt.Errorf("writing mode, %w", err) | |||
} | |||
if mode&ModeLegacyLeftNode != 0 { // legacy leftNodeKey | |||
err = encoding.EncodeBytes(w, node.leftNodeKey) | |||
err = encoding.Encode32BytesHash(w, node.leftNodeKey) |
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.
The attempt to encode the legacy left node key using Encode32BytesHash
in the writeBytes
method seems incorrect. The method Encode32BytesHash
is designed for encoding 32-byte hashes, not for encoding node keys.
- err = encoding.Encode32BytesHash(w, node.leftNodeKey)
+ err = encoding.EncodeBytes(w, node.leftNodeKey)
Consider using EncodeBytes
or an appropriate method for encoding node keys to ensure correct behavior.
Committable suggestion
‼️ IMPORTANT
Carefully review the code before committing. Ensure that it accurately replaces the highlighted code, contains no missing lines, and has no issues with indentation.
err = encoding.Encode32BytesHash(w, node.leftNodeKey) | |
err = encoding.EncodeBytes(w, node.leftNodeKey) |
@@ -639,7 +643,7 @@ | |||
return ErrRightNodeKeyEmpty | |||
} | |||
if mode&ModeLegacyRightNode != 0 { // legacy rightNodeKey | |||
err = encoding.EncodeBytes(w, node.rightNodeKey) | |||
err = encoding.Encode32BytesHash(w, node.rightNodeKey) |
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.
Similar to the previous comment, using Encode32BytesHash
for encoding the legacy right node key is incorrect. The method is intended for hash encoding, not node key encoding.
- err = encoding.Encode32BytesHash(w, node.rightNodeKey)
+ err = encoding.EncodeBytes(w, node.rightNodeKey)
Use EncodeBytes
or a suitable method for encoding node keys to ensure the correct encoding process.
Committable suggestion
‼️ IMPORTANT
Carefully review the code before committing. Ensure that it accurately replaces the highlighted code, contains no missing lines, and has no issues with indentation.
err = encoding.Encode32BytesHash(w, node.rightNodeKey) | |
err = encoding.EncodeBytes(w, node.rightNodeKey) |
ref: #877
Some advanced features are missed in the master branch.