Skip to content

Commit

Permalink
Uses the MacroEvaluator's argument indices IntArray as-is instead of …
Browse files Browse the repository at this point in the history
…allocating a new List.
  • Loading branch information
tgregg committed Jan 16, 2025
1 parent 8c121f7 commit ac38bdc
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 8 deletions.
9 changes: 4 additions & 5 deletions src/main/java/com/amazon/ion/impl/macro/Environment.kt
Original file line number Diff line number Diff line change
Expand Up @@ -16,11 +16,10 @@ package com.amazon.ion.impl.macro
data class Environment private constructor(
// Any variables found here have to be looked up in [parentEnvironment]
val arguments: List<Expression>,
// TODO: Replace with IntArray
val argumentIndices: List<Int>,
val argumentIndices: IntArray,
val parentEnvironment: Environment?,
) {
fun createChild(arguments: List<Expression>, argumentIndices: List<Int>) = Environment(arguments, argumentIndices, this)
fun createChild(arguments: List<Expression>, argumentIndices: IntArray) = Environment(arguments, argumentIndices, this)

override fun toString() = """
|Environment(
Expand All @@ -33,8 +32,8 @@ data class Environment private constructor(

companion object {
@JvmStatic
val EMPTY = Environment(emptyList(), emptyList(), null)
val EMPTY = Environment(emptyList(), IntArray(0), null)
@JvmStatic
fun create(arguments: List<Expression>, argumentIndices: List<Int>) = Environment(arguments, argumentIndices, null)
fun create(arguments: List<Expression>, argumentIndices: IntArray) = Environment(arguments, argumentIndices, null)
}
}
6 changes: 3 additions & 3 deletions src/main/java/com/amazon/ion/impl/macro/MacroEvaluator.kt
Original file line number Diff line number Diff line change
Expand Up @@ -906,10 +906,10 @@ private fun calculateArgumentIndices(
encodingExpressions: List<Expression>,
argsStartInclusive: Int,
argsEndExclusive: Int
): List<Int> {
): IntArray {
// TODO: For TDL macro invocations, see if we can calculate this during the "compile" step.
var numArgs = 0
val argsIndices = IntArray(macro.signature.size)
val argsIndices = IntArray(macro.signature.size) // TODO performance: pool these
var currentArgIndex = argsStartInclusive

for (p in macro.signature) {
Expand All @@ -936,5 +936,5 @@ private fun calculateArgumentIndices(
if (numArgs > macro.signature.size) {
throw IonException("Too many arguments. Expected ${macro.signature.size}, but found $numArgs")
}
return argsIndices.toList()
return argsIndices
}

0 comments on commit ac38bdc

Please sign in to comment.