Skip to content

Commit

Permalink
Merge pull request #384 from HandyMenny/drop-weak-concurrent-hashmap
Browse files Browse the repository at this point in the history
Drop WeakConcurrentHashMap
  • Loading branch information
handymenny authored Jan 13, 2024
2 parents 5eb0e90 + 57e8ef1 commit 3715050
Show file tree
Hide file tree
Showing 6 changed files with 0 additions and 131 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -16,15 +16,12 @@ import it.smartphonecombo.uecapabilityparser.model.component.ComponentLte
import it.smartphonecombo.uecapabilityparser.model.modulation.Modulation
import it.smartphonecombo.uecapabilityparser.model.modulation.ModulationOrder
import it.smartphonecombo.uecapabilityparser.util.ImportQcHelpers
import it.smartphonecombo.uecapabilityparser.util.WeakConcurrentHashMap
import java.io.BufferedInputStream
import java.io.IOException
import java.io.InputStream

object Import0xB0CDBin : ImportCapabilities {

private val cacheQamIndex = WeakConcurrentHashMap<Int, Modulation>()

/**
* This parser take as [input] a [InputSource] of a 0xB0CD (binary)
*
Expand Down Expand Up @@ -157,11 +154,6 @@ object Import0xB0CDBin : ImportCapabilities {
* The sequence generator is guessed, so it can be wrong or incomplete.
*/
fun getQamFromIndex(index: Int): Modulation {
val cachedResult = cacheQamIndex[index]
if (cachedResult != null) {
return cachedResult
}

/*
Some examples:
0 -> INVALID
Expand All @@ -187,7 +179,6 @@ object Import0xB0CDBin : ImportCapabilities {
}

val resultQam = Modulation.from(result.toList())
cacheQamIndex[index] = resultQam

return resultQam
}
Expand Down
18 changes: 0 additions & 18 deletions src/main/java/it/smartphonecombo/uecapabilityparser/model/BCS.kt
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
package it.smartphonecombo.uecapabilityparser.model

import it.smartphonecombo.uecapabilityparser.extension.mutableListWithCapacity
import it.smartphonecombo.uecapabilityparser.util.WeakConcurrentHashMap
import kotlinx.serialization.SerialName
import kotlinx.serialization.Serializable
import kotlinx.serialization.Transient
Expand All @@ -11,11 +10,6 @@ sealed interface BCS : Comparable<BCS> {
fun toCompactStr(): String

companion object {
// Cache used by fromBinaryString
private val cacheBinary = WeakConcurrentHashMap<String, BCS>()
// Cache used by fromQualcommCP
private val cacheCP = WeakConcurrentHashMap<String, BCS>()

/**
* Converts the given binaryString to an instance of [BCS]
* - If binaryString has no bit with value 1 return [EmptyBCS]
Expand All @@ -24,11 +18,6 @@ sealed interface BCS : Comparable<BCS> {
* - otherwise it returns a [MultiBCS]
*/
fun fromBinaryString(binaryString: String): BCS {
val cachedResult = cacheBinary[binaryString]
if (cachedResult != null) {
return cachedResult
}

val bcsList = mutableListWithCapacity<Int>(binaryString.length)
for (x in binaryString.indices) {
if (binaryString[x] == '1') {
Expand All @@ -43,7 +32,6 @@ sealed interface BCS : Comparable<BCS> {
32 -> AllBCS
else -> MultiBCS(bcsList.toIntArray())
}
cacheBinary[binaryString] = result
return result
}

Expand All @@ -56,11 +44,6 @@ sealed interface BCS : Comparable<BCS> {
*/
@Throws(NumberFormatException::class)
fun fromQualcommCP(bcsString: String): BCS {
val cachedResult = cacheCP[bcsString]
if (cachedResult != null) {
return cachedResult
}

val result =
when {
bcsString.isEmpty() -> EmptyBCS
Expand All @@ -72,7 +55,6 @@ sealed interface BCS : Comparable<BCS> {
}
else -> SingleBCS(bcsString.toInt())
}
cacheCP[bcsString] = result
return result
}
}
Expand Down
24 changes: 0 additions & 24 deletions src/main/java/it/smartphonecombo/uecapabilityparser/model/Mimo.kt
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
package it.smartphonecombo.uecapabilityparser.model

import it.smartphonecombo.uecapabilityparser.extension.indexOfMin
import it.smartphonecombo.uecapabilityparser.util.WeakConcurrentHashMap
import kotlinx.serialization.SerialName
import kotlinx.serialization.Serializable

Expand All @@ -14,16 +13,7 @@ sealed interface Mimo : Comparable<Mimo> {
override fun compareTo(other: Mimo): Int = average().compareTo(other.average())

companion object {
private val cacheInt = WeakConcurrentHashMap<Int, Mimo>()
private val cacheIntArray = WeakConcurrentHashMap<List<Int>, Mimo>()
private val cacheQcIndex = WeakConcurrentHashMap<Int, Mimo>()

fun from(int: Int): Mimo {
val cachedResult = cacheInt[int]
if (cachedResult != null) {
return cachedResult
}

val result =
if (int == 0) {
EmptyMimo
Expand All @@ -33,16 +23,10 @@ sealed interface Mimo : Comparable<Mimo> {
SingleMimo(int)
}

cacheInt[int] = result
return result
}

fun from(list: List<Int>): Mimo {
val cachedResult = cacheIntArray[list]
if (cachedResult != null) {
return cachedResult
}

val result =
if (list.isEmpty()) {
EmptyMimo
Expand All @@ -52,7 +36,6 @@ sealed interface Mimo : Comparable<Mimo> {
MixedMimo(list.sortedDescending())
}

cacheIntArray[list] = result
return result
}

Expand All @@ -62,11 +45,6 @@ sealed interface Mimo : Comparable<Mimo> {
* The sequence generator is guessed, so it can be wrong or incomplete.
*/
fun fromQcIndex(index: Int): Mimo {
val cachedResult = cacheQcIndex[index]
if (cachedResult != null) {
return cachedResult
}

/*
Some examples:
0 -> 0
Expand Down Expand Up @@ -94,8 +72,6 @@ sealed interface Mimo : Comparable<Mimo> {
}

val resultMimo = from(result.toList())
cacheQcIndex[index] = resultMimo

return resultMimo
}
}
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
package it.smartphonecombo.uecapabilityparser.model.bandwidth

import it.smartphonecombo.uecapabilityparser.util.WeakConcurrentHashMap
import kotlinx.serialization.SerialName
import kotlinx.serialization.Serializable

Expand All @@ -13,32 +12,18 @@ sealed interface Bandwidth : Comparable<Bandwidth> {
override fun compareTo(other: Bandwidth): Int = average().compareTo(other.average())

companion object {
private val cacheInt = WeakConcurrentHashMap<Int, Bandwidth>()
private val cacheIntList = WeakConcurrentHashMap<List<Int>, Bandwidth>()

fun from(int: Int): Bandwidth {
val cachedResult = cacheInt[int]
if (cachedResult != null) {
return cachedResult
}

val result =
if (int == 0) {
EmptyBandwidth
} else {
SingleBandwidth(int)
}

cacheInt[int] = result
return result
}

fun from(list: List<Int>): Bandwidth {
val cachedResult = cacheIntList[list]
if (cachedResult != null) {
return cachedResult
}

val result =
if (list.isEmpty()) {
EmptyBandwidth
Expand All @@ -48,7 +33,6 @@ sealed interface Bandwidth : Comparable<Bandwidth> {
MixedBandwidth(list.sortedDescending())
}

cacheIntList[list] = result
return result
}
}
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
package it.smartphonecombo.uecapabilityparser.model.modulation

import it.smartphonecombo.uecapabilityparser.util.WeakConcurrentHashMap
import kotlinx.serialization.SerialName
import kotlinx.serialization.Serializable

Expand All @@ -23,17 +22,10 @@ sealed interface Modulation : Comparable<Modulation> {
SingleModulation(it)
}
}
private val cacheModulationArray =
WeakConcurrentHashMap<List<ModulationOrder>, Modulation>()

fun from(modulationOrder: ModulationOrder) = singleModulations[modulationOrder.ordinal]

fun from(modulationList: List<ModulationOrder>): Modulation {
val cachedResult = cacheModulationArray[modulationList]
if (cachedResult != null) {
return cachedResult
}

val result =
if (modulationList.isEmpty()) {
EmptyModulation
Expand All @@ -43,7 +35,6 @@ sealed interface Modulation : Comparable<Modulation> {
MixedModulation(modulationList.sortedDescending())
}

cacheModulationArray[modulationList] = result
return result
}
}
Expand Down

This file was deleted.

0 comments on commit 3715050

Please sign in to comment.