Skip to content

Commit bfe7478

Browse files
committed
inline unsigned arrays
1 parent 59feccd commit bfe7478

File tree

2 files changed

+55
-2
lines changed

2 files changed

+55
-2
lines changed

build.gradle

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6,14 +6,14 @@ plugins {
66
ext{
77
moduleName = 'com.github.kotlin_graphics.kotlin_unsigned'
88
kotlin = 'org.jetbrains.kotlin:kotlin'
9-
kotlintest_version = '3.4.3'
9+
kotlintest_version = '3.4.2'
1010
}
1111

1212
dependencies {
1313

1414
implementation "$kotlin-stdlib"
1515

16-
testImplementation "io.kotlintest:kotlintest-runner-junit5:$kotlintest_version".toString()
16+
testImplementation "io.kotlintest:kotlintest-runner-junit5:$kotlintest_version"
1717
}
1818

1919
repositories {
@@ -40,6 +40,7 @@ compileKotlin {
4040
// Enable Kotlin compilation to Java 8 class files with method parameter name metadata
4141
kotlinOptions{
4242
jvmTarget = "11"
43+
freeCompilerArgs = ["-XXLanguage:+InlineClasses"]
4344
// javaParameters = true
4445
}
4546
// As per https://stackoverflow.com/a/47669720

src/main/kotlin/unsigned/arrays.kt

Lines changed: 52 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,52 @@
1+
package unsigned
2+
3+
4+
fun UbyteArray(size: Int) = UbyteArray(ByteArray(size))
5+
fun UbyteArray(size: Int, init: (Int) -> Byte) = UbyteArray(ByteArray(size, init))
6+
7+
inline class UbyteArray(val data: ByteArray) {
8+
9+
operator fun get(index: Int) = Ubyte(data[index])
10+
11+
operator fun set(index: Int, value: Ubyte) {
12+
data[index] = value.v
13+
}
14+
}
15+
16+
17+
fun UshortArray(size: Int) = UshortArray(ShortArray(size))
18+
fun UshortArray(size: Int, init: (Int) -> Short) = UshortArray(ShortArray(size, init))
19+
20+
inline class UshortArray(val data: ShortArray) {
21+
22+
operator fun get(index: Int) = Ushort(data[index])
23+
24+
operator fun set(index: Int, value: Ushort) {
25+
data[index] = value.v
26+
}
27+
}
28+
29+
30+
fun UintArray(size: Int) = UintArray(IntArray(size))
31+
fun UintArray(size: Int, init: (Int) -> Int) = UintArray(IntArray(size, init))
32+
33+
inline class UintArray(val data: IntArray) {
34+
35+
operator fun get(index: Int) = Uint(data[index])
36+
37+
operator fun set(index: Int, value: Uint) {
38+
data[index] = value.v
39+
}
40+
}
41+
42+
fun UlongArray(size: Int) = UlongArray(LongArray(size))
43+
fun UlongArray(size: Int, init: (Int) -> Long) = UlongArray(LongArray(size, init))
44+
45+
inline class UlongArray(val data: LongArray) {
46+
47+
operator fun get(index: Int) = Ulong(data[index])
48+
49+
operator fun set(index: Int, value: Ulong) {
50+
data[index] = value.v
51+
}
52+
}

0 commit comments

Comments
 (0)