I believe we may eliminate for loop execution most of the time, in onCreateViewHolder.
The key idea is that, getItemViewType will always be executed before onCreateViewHolder, as RecyclerView need to pass view type information to onCreateViewHolder's function.
My proposed method is as follow.
1) In getItemViewType, cache the last hit Section's TAG.
2) In onCreateViewHolder, get viewType from last hit Section's TAG. Compare with function parameter viewType. If matched, we can proceed with get...ViewHolder(parent, section). The section will retrieved from last hit Section's TAG in step 1.
3) If not matched, we will continue execute with old loop searching code. (I believe most of the time, the hit will success)
By referring to code at
https://github.com/lisawray/groupie/blob/c3411d814f18e9b308e3b829b1e8a532f34b6ee2/library/src/main/java/com/xwray/groupie/GroupAdapter.java#L526
I believe we may eliminate for loop execution most of the time, in
onCreateViewHolder
.The key idea is that,
getItemViewType
will always be executed beforeonCreateViewHolder
, asRecyclerView
need to pass view type information toonCreateViewHolder
's function.My proposed method is as follow.
1) In getItemViewType, cache the last hit Section's TAG.
2) In onCreateViewHolder, get viewType from last hit Section's TAG. Compare with function parameter viewType. If matched, we can proceed with get...ViewHolder(parent, section). The section will retrieved from last hit Section's TAG in step 1.
3) If not matched, we will continue execute with old loop searching code. (I believe most of the time, the hit will success)
Thank you.