mirror of
https://github.com/facebook/react-native.git
synced 2025-11-01 09:14:26 +00:00
Cache vector image detection for assets (#46415)
Summary: Pull Request resolved: https://github.com/facebook/react-native/pull/46415 Changelog: [Internal] Cache the results checking for vector content. This check is decompressing the asset content and parsing XML to check for vector graphics. Caching the result per context/asset name removes the need to parse the content on each image assignment. Reviewed By: Abbondanzo Differential Revision: D62436412 fbshipit-source-id: 9e1fe9f0747c9a30ac0d89124b6909d4260a2a2f
This commit is contained in:
committed by
Facebook GitHub Bot
parent
4a22f2c816
commit
65beadb00a
+10
-1
@@ -19,6 +19,7 @@ import org.xmlpull.v1.XmlPullParser
|
||||
@ThreadSafe
|
||||
public class ResourceDrawableIdHelper private constructor() {
|
||||
private val resourceDrawableIdMap: MutableMap<String, Int> = HashMap()
|
||||
private val vectorDrawableCheckCache: MutableMap<Context, MutableMap<String, Boolean>> = HashMap()
|
||||
|
||||
@Synchronized
|
||||
public fun clear() {
|
||||
@@ -64,7 +65,15 @@ public class ResourceDrawableIdHelper private constructor() {
|
||||
}
|
||||
|
||||
public fun isVectorDrawable(context: Context, name: String): Boolean {
|
||||
return getOpeningXmlTag(context, name) == "vector"
|
||||
val cachedResult = vectorDrawableCheckCache[context]?.get(name);
|
||||
if (cachedResult != null) {
|
||||
return cachedResult
|
||||
}
|
||||
|
||||
|
||||
val result = getOpeningXmlTag(context, name) == "vector"
|
||||
vectorDrawableCheckCache.getOrPut(context, { HashMap() }).put(name, result)
|
||||
return result
|
||||
}
|
||||
|
||||
/**
|
||||
|
||||
Reference in New Issue
Block a user