use getOrPut where possible

This commit is contained in:
Jays2Kings 2022-05-04 20:48:03 -04:00
parent 6217afb469
commit 467f60ed9b
2 changed files with 2 additions and 12 deletions

View file

@ -19,13 +19,7 @@ object EstimatedItemHeight {
return if (childSizesMap[pos] != null) { return if (childSizesMap[pos] != null) {
childSizesMap[pos] ?: 0 childSizesMap[pos] ?: 0
} else { } else {
val type = if (childTypeMap[pos] == null) { val type = childTypeMap.getOrPut(pos) { itemViewType ?: 0 }
val t = itemViewType ?: 0
childTypeMap[pos] = t
t
} else {
childTypeMap[pos] ?: 0
}
when { when {
childTypeEstimateMap[type] != null -> childTypeEstimateMap[type] ?: 0 childTypeEstimateMap[type] != null -> childTypeEstimateMap[type] ?: 0
childAvgHeightMap[type] == null && !childTypeHeightMap[type]?.values.isNullOrEmpty() -> { childAvgHeightMap[type] == null && !childTypeHeightMap[type]?.values.isNullOrEmpty() -> {

View file

@ -37,11 +37,7 @@ class LinearLayoutManagerAccurateOffset(context: Context?) : LinearLayoutManager
childSizesMap[position] = child.height childSizesMap[position] = child.height
val type = getItemViewType(child) val type = getItemViewType(child)
childTypeMap[position] = type childTypeMap[position] = type
if (childTypeHeightMap[type] != null) { childTypeHeightMap.getOrPut(type) { hashMapOf() }[position] = child.height
childTypeHeightMap[type]!![position] = child.height
} else {
childTypeHeightMap[type] = hashMapOf(position to child.height)
}
} }
} }