Skip to content

Commit fb644ce

Browse files
Elena LepilkinaElena Lepilkina
authored andcommitted
Changed Blackhole implementation
1 parent 2709405 commit fb644ce

File tree

1 file changed

+13
-16
lines changed

1 file changed

+13
-16
lines changed
Lines changed: 13 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -1,37 +1,34 @@
11
package kotlinx.benchmark
22

3+
import kotlinx.cinterop.pin
4+
5+
36
actual class Blackhole {
4-
@ThreadLocal
5-
companion object {
6-
var consumer = 0
7-
}
87
actual fun consume(obj: Any?) {
9-
// hashCode now is implemented as taking address of object, so it's suitable now.
10-
// If implementation is changed `Blackhole` should be reimplemented.
11-
consumer += obj.hashCode()
8+
obj?.pin()
129
}
1310
actual fun consume(bool: Boolean) {
14-
consumer += bool.hashCode()
11+
bool.pin()
1512
}
1613
actual fun consume(c: Char) {
17-
consumer += c.hashCode()
14+
c.pin()
1815
}
1916
actual fun consume(b: Byte) {
20-
consumer += b.hashCode()
17+
b.pin()
2118
}
2219
actual fun consume(s: Short) {
23-
consumer += s.hashCode()
20+
s.pin()
2421
}
2522
actual fun consume(i: Int) {
26-
consumer += i.hashCode()
23+
i.pin()
2724
}
2825
actual fun consume(l: Long) {
29-
consumer += l.hashCode()
26+
l.pin()
3027
}
3128
actual fun consume(f: Float) {
32-
consumer += f.hashCode()
29+
f.pin()
3330
}
3431
actual fun consume(d: Double) {
35-
consumer += d.hashCode()
32+
d.pin()
3633
}
37-
}
34+
}

0 commit comments

Comments
 (0)