Skip to content

Commit

Permalink
Cleanup
Browse files Browse the repository at this point in the history
  • Loading branch information
fzhinkin committed Jun 23, 2023
1 parent 6a535f8 commit 77f27a8
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 23 deletions.
6 changes: 1 addition & 5 deletions bytestring/api/kotlinx-io-bytestring.api
Original file line number Diff line number Diff line change
Expand Up @@ -73,11 +73,7 @@ public abstract interface annotation class kotlinx/io/bytestring/unsafe/UnsafeBy
}

public final class kotlinx/io/bytestring/unsafe/UnsafeByteStringOperations {
public static final field Companion Lkotlinx/io/bytestring/unsafe/UnsafeByteStringOperations$Companion;
public fun <init> ()V
}

public final class kotlinx/io/bytestring/unsafe/UnsafeByteStringOperations$Companion {
public static final field INSTANCE Lkotlinx/io/bytestring/unsafe/UnsafeByteStringOperations;
public final fun getByteArrayUnsafe (Lkotlinx/io/bytestring/ByteString;)[B
public final fun wrapUnsafe ([B)Lkotlinx/io/bytestring/ByteString;
}
Expand Down
34 changes: 16 additions & 18 deletions bytestring/src/commonMain/kotlin/UnsafeByteStringOperations.kt
Original file line number Diff line number Diff line change
Expand Up @@ -16,22 +16,20 @@ import kotlinx.io.bytestring.ByteString
* consequences in the code using the byte string and should be avoided at all costs.
*/
@UnsafeByteStringApi
public class UnsafeByteStringOperations {
public companion object {
/**
* Creates a new byte string by wrapping [array] without copying it.
* Make sure that the wrapped array won't be modified during the lifespan of the returned byte string.
*
* @param array the array to wrap into the byte string.
*/
public fun wrapUnsafe(array: ByteArray): ByteString = ByteString.wrap(array)
public object UnsafeByteStringOperations {
/**
* Creates a new byte string by wrapping [array] without copying it.
* Make sure that the wrapped array won't be modified during the lifespan of the returned byte string.
*
* @param array the array to wrap into the byte string.
*/
public fun wrapUnsafe(array: ByteArray): ByteString = ByteString.wrap(array)

/**
* Returns a reference to the underlying array.
*
* These methods return reference to the underlying array, not to its copy.
* Consider using [ByteString.toByteArray] if it's impossible to guarantee that the array won't be modified.
*/
public fun getByteArrayUnsafe(byteString: ByteString): ByteArray = byteString.getBackingArrayReference()
}
}
/**
* Returns a reference to the underlying array.
*
* These methods return reference to the underlying array, not to its copy.
* Consider using [ByteString.toByteArray] if it's impossible to guarantee that the array won't be modified.
*/
public fun getByteArrayUnsafe(byteString: ByteString): ByteArray = byteString.getBackingArrayReference()
}

0 comments on commit 77f27a8

Please sign in to comment.