Skip to content

Commit

Permalink
less memory impact when updating bi- or multi-mapped single-threaded …
Browse files Browse the repository at this point in the history
…properties
  • Loading branch information
Miha-x64 committed Feb 26, 2019
1 parent b5650eb commit 431ff29
Show file tree
Hide file tree
Showing 4 changed files with 18 additions and 5 deletions.
9 changes: 9 additions & 0 deletions .idea/inspectionProfiles/Project_Default.xml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions .travis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ before_install:

script:
- ./gradlew clean :persistence:test :properties:test :sql:test :fx-bindings:test :android-bindings:test --info --stacktrace
# - ./gradlew clean :persistence:test :properties:test :sql:test :fx-bindings:test :android-bindings:test :persistence:bintrayUpload :properties:bintrayUpload :android-bindings:bintrayUpload

#after_success:
# - java -jar ~/codacy-coverage-reporter-assembly-latest.jar report -l Java -r properties/build/reports/jacoco/test/jacocoTestReport.xml
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -33,16 +33,18 @@ internal class `BiMapped-`<in A, in B, out T>(
}

@JvmSynthetic internal fun update(idx: Int, value: Any?) {
var prevValue: T
var prev: Array<Any?>
var next: Array<Any?>
do {
prev = ref as Array<Any?>
next = prev.clone() // todo: don't even clone for single-thread properties
prevValue = prev[2] as T
next = if (isConcurrent) prev.clone() else prev
next[idx] = value
next[2] = transform(next[0] as A, next[1] as B)
} while (!refUpdater().eagerOrLazyCas(this, thread, prev, next))

valueChanged(prev[2] as T, next[2] as T, null)
valueChanged(prevValue, next[2] as T, null)
}

override fun observedStateChanged(observed: Boolean) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -33,17 +33,18 @@ internal class `MultiMapped-`<in A, out T>(
}

@JvmSynthetic internal fun patch(index: Int, new: A) {
var prevValue: T
var oldVals: Array<Any?>
var newVals: Array<Any?>

do {
oldVals = ref as Array<Any?>
newVals = oldVals.clone() // todo: don't even clone for single-thread properties
prevValue = oldVals.last() as T
newVals = if (isConcurrent) oldVals.clone() else oldVals
newVals[index] = new
newVals[newVals.size - 1] = transform(SmallerList(newVals) as List<A>)
} while (!cas(oldVals, newVals))

valueChanged(oldVals.last() as T, newVals.last() as T, null)
valueChanged(prevValue, newVals.last() as T, null)
}

private fun cas(old: Any?, new: Any?): Boolean = if (thread === null) {
Expand Down

0 comments on commit 431ff29

Please sign in to comment.