Skip to content

Commit ecb4985

Browse files
committed
Caches the lowest MacroRef.ById, reducing allocation rate by 37.5%.
1 parent f26c78a commit ecb4985

File tree

1 file changed

+4
-1
lines changed

1 file changed

+4
-1
lines changed

src/main/java/com/amazon/ion/impl/macro/MacroRef.kt

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,8 +13,11 @@ sealed interface MacroRef {
1313
// TODO: Since system macros have an independent address space, do we need to have a `SystemById` variant?
1414

1515
companion object {
16+
17+
private val LOW_IDS = Array(128) { i -> ById(i) }
18+
1619
@JvmStatic
17-
fun byId(id: Int): MacroRef = ById(id)
20+
fun byId(id: Int): MacroRef = if (id < 128) LOW_IDS[id] else ById(id)
1821

1922
@JvmStatic
2023
fun byName(name: String): MacroRef = ByName(name)

0 commit comments

Comments
 (0)