-
Notifications
You must be signed in to change notification settings - Fork 27
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
s3: avoid array copies when dealing with ByteStrings #658
Conversation
@mdedetrich You are the most active contributor to the S3 code base. Do these changes look ok to you? |
@@ -36,7 +36,16 @@ package object auth { | |||
new String(out) | |||
} | |||
|
|||
@InternalApi private[impl] def encodeHex(bytes: ByteString): String = encodeHex(bytes.toArray) | |||
@InternalApi private[impl] def encodeHex(bytes: ByteString): String = { | |||
val length = bytes.length |
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.
ByteString implements IndexedSeq[Byte]
so we can iterate it without converting it to an array.
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.
looking at the ByteStrings code (complex ByteString made up of underlying ByteStrings) the apply(Int) function and the iterator function are not performant.
So I'm now thinking of changing this to
def encodeHex(bytes: ByteString): String = encodeHex(bytes.toArrayUnsafe)
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.
lgtm
lgtm |
the 'unsafe' methods are ok if you know the data is not being mutated