Breaking: change meaning of the parameters of ImmutableBlob.to(U)ByteArray
To be consistent with other subrange copying to* functions: String.toCharArray, Array.copyInto etc
This commit is contained in:
committed by
Nikolay Igotti
parent
6f6bfd15ed
commit
22ef0a1a4c
@@ -467,17 +467,18 @@ KInt Kotlin_NativePtrArray_getArrayLength(KConstRef thiz) {
|
|||||||
return array->count_;
|
return array->count_;
|
||||||
}
|
}
|
||||||
|
|
||||||
OBJ_GETTER(Kotlin_ImmutableBlob_toByteArray, KConstRef thiz, KInt start, KInt count) {
|
OBJ_GETTER(Kotlin_ImmutableBlob_toByteArray, KConstRef thiz, KInt startIndex, KInt endIndex) {
|
||||||
const ArrayHeader* array = thiz->array();
|
const ArrayHeader* array = thiz->array();
|
||||||
if (start < 0 || count < 0 || start > array->count_ - count) {
|
if (startIndex < 0 || endIndex > array->count_ || startIndex > endIndex) {
|
||||||
ThrowArrayIndexOutOfBoundsException();
|
ThrowArrayIndexOutOfBoundsException();
|
||||||
}
|
}
|
||||||
ArrayHeader* result = AllocArrayInstance(
|
KInt count = endIndex - startIndex;
|
||||||
theByteArrayTypeInfo, count, OBJ_RESULT)->array();
|
ArrayHeader* result = AllocArrayInstance(
|
||||||
memcpy(PrimitiveArrayAddressOfElementAt<KByte>(result, 0),
|
theByteArrayTypeInfo, count, OBJ_RESULT)->array();
|
||||||
PrimitiveArrayAddressOfElementAt<KByte>(array, start),
|
memcpy(PrimitiveArrayAddressOfElementAt<KByte>(result, 0),
|
||||||
count);
|
PrimitiveArrayAddressOfElementAt<KByte>(array, startIndex),
|
||||||
RETURN_OBJ(result->obj());
|
count);
|
||||||
|
RETURN_OBJ(result->obj());
|
||||||
}
|
}
|
||||||
|
|
||||||
KNativePtr Kotlin_ImmutableBlob_asCPointerImpl(KRef thiz, KInt offset) {
|
KNativePtr Kotlin_ImmutableBlob_asCPointerImpl(KRef thiz, KInt offset) {
|
||||||
|
|||||||
@@ -42,19 +42,23 @@ private class ImmutableBlobIteratorImpl(val blob: ImmutableBlob) : ByteIterator(
|
|||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Allocates new [ByteArray] and copies the data from blob starting from [start]
|
* Copies the data from this blob into a new [ByteArray].
|
||||||
* and with [count] amount of bytes.
|
*
|
||||||
|
* @param startIndex the beginning (inclusive) of the subrange to copy, 0 by default.
|
||||||
|
* @param endIndex the end (exclusive) of the subrange to copy, size of this blob by default.
|
||||||
*/
|
*/
|
||||||
@SymbolName("Kotlin_ImmutableBlob_toByteArray")
|
@SymbolName("Kotlin_ImmutableBlob_toByteArray")
|
||||||
public external fun ImmutableBlob.toByteArray(start: Int = 0, count: Int = size): ByteArray
|
public external fun ImmutableBlob.toByteArray(startIndex: Int = 0, endIndex: Int = size): ByteArray
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Allocates new [UByteArray] and copies the data from blob starting from [start]
|
* Copies the data from this blob into a new [UByteArray].
|
||||||
* and with [count] amount of bytes.
|
*
|
||||||
|
* @param startIndex the beginning (inclusive) of the subrange to copy, 0 by default.
|
||||||
|
* @param endIndex the end (exclusive) of the subrange to copy, size of this blob by default.
|
||||||
*/
|
*/
|
||||||
@ExperimentalUnsignedTypes
|
@ExperimentalUnsignedTypes
|
||||||
@SymbolName("Kotlin_ImmutableBlob_toByteArray")
|
@SymbolName("Kotlin_ImmutableBlob_toByteArray")
|
||||||
public external fun ImmutableBlob.toUByteArray(start: Int = 0, count: Int = size): UByteArray
|
public external fun ImmutableBlob.toUByteArray(startIndex: Int = 0, endIndex: Int = size): UByteArray
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Returns stable C pointer to data at certain [offset], useful as a way to pass resource
|
* Returns stable C pointer to data at certain [offset], useful as a way to pass resource
|
||||||
|
|||||||
Reference in New Issue
Block a user