Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Uses the MacroEvaluator's argument indices IntArray as-is instead of allocating a new List. #1035

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
}
Loading