Skip to content

Commit 513bad1

Browse files
authored
Remove superfluous AtomicInt value read after write
The new value is already available locally and can be returned directly.
1 parent 806daf6 commit 513bad1

File tree

1 file changed

+3
-2
lines changed
  • stately-concurrency/src/jsWasmMain/kotlin/co/touchlab/stately/concurrency

1 file changed

+3
-2
lines changed

Diff for: stately-concurrency/src/jsWasmMain/kotlin/co/touchlab/stately/concurrency/AtomicInt.kt

+3-2
Original file line numberDiff line numberDiff line change
@@ -23,8 +23,9 @@ actual class AtomicInt actual constructor(initialValue: Int) {
2323
private var internalValue: Int = initialValue
2424

2525
actual fun addAndGet(delta: Int): Int {
26-
internalValue += delta
27-
return internalValue
26+
return (internalValue + delta).also {
27+
internalValue = it
28+
}
2829
}
2930

3031
actual fun compareAndSet(expected: Int, new: Int): Boolean {

0 commit comments

Comments
 (0)