Skip to content

Commit cc8f7db

Browse files
nopdanWhiredPlanck
authored andcommitted
perf: make parseColor no longer check the parameter is null
1 parent 9373ea6 commit cc8f7db

File tree

2 files changed

+15
-10
lines changed

2 files changed

+15
-10
lines changed

app/src/main/java/com/osfans/trime/data/theme/ColorManager.kt

Lines changed: 14 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -314,8 +314,11 @@ object ColorManager {
314314
m: Map<String, Any?>,
315315
key: String?,
316316
): Int? {
317-
val value = getColorValue(m[key].toString())
318-
return if (value is Int) value else null
317+
m[key].let {
318+
if (it == null) return null
319+
val value = getColorValue(it.toString())
320+
return if (value is Int) value else null
321+
}
319322
}
320323

321324
// 返回drawable。 Config 2.0
@@ -335,13 +338,16 @@ object ColorManager {
335338
m: Map<String, Any?>,
336339
key: String,
337340
): Drawable? {
338-
val value = getColorValue(m[key].toString())
339-
if (value is Int) {
340-
return GradientDrawable().apply { setColor(value) }
341-
} else if (value is Drawable) {
342-
return value
341+
m[key].let {
342+
if (it == null) return null
343+
val value = getColorValue(it.toString())
344+
if (value is Int) {
345+
return GradientDrawable().apply { setColor(value) }
346+
} else if (value is Drawable) {
347+
return value
348+
}
349+
return null
343350
}
344-
return null
345351
}
346352

347353
// 返回图片或背景的drawable,支持null参数。 Config 2.0

app/src/main/java/com/osfans/trime/util/ColorUtils.kt

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -13,8 +13,7 @@ import timber.log.Timber
1313

1414
object ColorUtils {
1515
@JvmStatic
16-
fun parseColor(s: String?): Int? {
17-
if (s == null) return null
16+
fun parseColor(s: String): Int? {
1817
val hex: String = if (s.startsWith("#")) s.replace("#", "0x") else s
1918
return try {
2019
val completed =

0 commit comments

Comments
 (0)