Skip to content

Commit 857b9a3

Browse files
committed
refactor: 彻底移除 Phase 2 残留
- 删除 GeneratedLayoutRegistry.kt - FastInflater inflate/inflateAsync miss 路径不再查 registry - 移除 FastInflater.registry() public API - consumer-rules.pro 移除 GeneratedLayoutRegistry/Gen_*/FastInflaterGenerated 规则 - 补充 ViewPool$WarmUpListener kep 规则
1 parent 37b2edc commit 857b9a3

3 files changed

Lines changed: 5 additions & 63 deletions

File tree

‎lib/consumer-rules.pro‎

Lines changed: 1 addition & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -7,14 +7,9 @@
77
-keep class com.github.donglua.fastinflater.FastRecycledViewPool { *; }
88
-keep class com.github.donglua.fastinflater.ViewPool { *; }
99
-keep class com.github.donglua.fastinflater.ViewPool$WarmUpEntry { *; }
10+
-keep class com.github.donglua.fastinflater.ViewPool$WarmUpListener { *; }
1011
-keep class com.github.donglua.fastinflater.InflateTracker { *; }
1112
-keep class com.github.donglua.fastinflater.InflateTracker$LayoutStat { *; }
1213
-keep class com.github.donglua.fastinflater.PoolStats { *; }
1314
-keep class com.github.donglua.fastinflater.PoolStats$Stat { *; }
1415
-keep class com.github.donglua.fastinflater.ViewRecyclePolicy { *; }
15-
-keep class com.github.donglua.fastinflater.GeneratedLayoutRegistry { *; }
16-
-keep class com.github.donglua.fastinflater.GeneratedLayoutRegistry$Creator { *; }
17-
18-
# 保留 codegen 生成的类(Phase 2)
19-
-keep class **.Gen_* { *; }
20-
-keep class **.FastInflaterGenerated { *; }

‎lib/src/main/java/com/github/donglua/fastinflater/FastInflater.kt‎

Lines changed: 4 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -15,14 +15,11 @@ class FastInflater private constructor(context: Context) {
1515

1616
private val appContext = context.applicationContext
1717
private val viewPool = ViewPool()
18-
private val registry = GeneratedLayoutRegistry()
1918
// 单线程避免 LayoutInflater 并发访问 Resources 的线程安全问题(Android 8.x 及以下)
2019
private val asyncExecutor = Executors.newSingleThreadExecutor { r ->
2120
Thread(r, "FastInflater-async").apply { isDaemon = true }
2221
}
2322

24-
fun registry(): GeneratedLayoutRegistry = registry
25-
2623
fun registerPolicy(@LayoutRes layoutId: Int, policy: ViewRecyclePolicy) {
2724
viewPool.registerPolicy(layoutId, policy)
2825
}
@@ -61,13 +58,6 @@ class FastInflater private constructor(context: Context) {
6158

6259
PoolStats.recordMiss(layoutId)
6360

64-
val creator = registry.resolve(context, layoutId)
65-
if (creator != null) {
66-
return InflateTracker.track(layoutId) {
67-
creator.create(context, parent, attachToRoot)
68-
}
69-
}
70-
7161
return InflateTracker.track(layoutId) {
7262
LayoutInflater.from(context).inflate(layoutId, parent, attachToRoot)
7363
}
@@ -95,15 +85,12 @@ class FastInflater private constructor(context: Context) {
9585

9686
PoolStats.recordMiss(layoutId)
9787

98-
val creator = registry.resolve(context, layoutId)
99-
10088
// 已知必须主线程:直接在主线程 inflate,避免后台崩溃
10189
if (viewPool.isMainThreadOnly(layoutId)) {
10290
val handler = Handler(Looper.getMainLooper())
10391
val run = Runnable {
10492
val view = InflateTracker.track(layoutId) {
105-
if (creator != null) creator.create(context, parent, false)
106-
else LayoutInflater.from(context).inflate(layoutId, parent, false)
93+
LayoutInflater.from(context).inflate(layoutId, parent, false)
10794
}
10895
callback(view)
10996
}
@@ -114,21 +101,16 @@ class FastInflater private constructor(context: Context) {
114101
asyncExecutor.execute {
115102
try {
116103
val view = InflateTracker.track(layoutId) {
117-
if (creator != null) {
118-
creator.create(context, parent, false)
119-
} else {
120-
LayoutInflater.from(context).cloneInContext(context)
121-
.inflate(layoutId, parent, false)
122-
}
104+
LayoutInflater.from(context).cloneInContext(context)
105+
.inflate(layoutId, parent, false)
123106
}
124107
parent?.post { callback(view) } ?: callback(view)
125108
} catch (e: Throwable) {
126109
// 后台 inflate 失败,标记并降级到主线程重试
127110
viewPool.markAsMainThreadOnly(layoutId)
128111
Handler(Looper.getMainLooper()).post {
129112
val view = InflateTracker.track(layoutId) {
130-
if (creator != null) creator.create(context, parent, false)
131-
else LayoutInflater.from(context).inflate(layoutId, parent, false)
113+
LayoutInflater.from(context).inflate(layoutId, parent, false)
132114
}
133115
callback(view)
134116
}

‎lib/src/main/java/com/github/donglua/fastinflater/GeneratedLayoutRegistry.kt‎

Lines changed: 0 additions & 35 deletions
This file was deleted.

0 commit comments

Comments
 (0)