Skip to content

Commit

Permalink
Adds configrable preallocation for primitives
Browse files Browse the repository at this point in the history
Summary: Adds configrable preallocation for primitives typically seen in account switcher

Reviewed By: astreet

Differential Revision: D55432316

fbshipit-source-id: 693c99983cba0dfe1a4065f87d48293c8c62abcd
  • Loading branch information
adityasharat authored and facebook-github-bot committed Mar 27, 2024
1 parent 3a698c2 commit 691ce59
Showing 1 changed file with 19 additions and 6 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -35,12 +35,20 @@ fun RichTextPrimitive(id: Long, text: CharSequence, style: TextStyle): Primitive
return Primitive(
layoutBehavior = RichTextLayoutBehavior(text, style),
mountBehavior =
MountBehavior(id = id, contentAllocator = ViewAllocator { c -> RCTextView(c) }) {
bindWithLayoutData<TextLayout>(Unit) { content, textLayout ->
content.mount(textLayout)
onUnbind { content.unmount() }
}
})
MountBehavior(
id = id,
contentAllocator =
ViewAllocator(
canPreallocate = RichTextPrimitiveConfig.canPreallocation,
poolSize = RichTextPrimitiveConfig.poolSize,
) { c ->
RCTextView(c)
}) {
bindWithLayoutData<TextLayout>(Unit) { content, textLayout ->
content.mount(textLayout)
onUnbind { content.unmount() }
}
})
}

private class RichTextLayoutBehavior(val text: CharSequence, val style: TextStyle) :
Expand All @@ -60,3 +68,8 @@ private class RichTextLayoutBehavior(val text: CharSequence, val style: TextStyl
layoutData = textLayout)
}
}

object RichTextPrimitiveConfig {
val canPreallocation: Boolean = true
val poolSize: Int = 10
}

0 comments on commit 691ce59

Please sign in to comment.