Skip to content

Commit

Permalink
Avoids using lambdas in MacroEvaluator hot paths.
Browse files Browse the repository at this point in the history
  • Loading branch information
tgregg committed Jan 31, 2025
1 parent 76e8e2f commit 8e1785e
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 23 deletions.
36 changes: 17 additions & 19 deletions src/main/java/com/amazon/ion/impl/macro/MacroEvaluator.kt
Original file line number Diff line number Diff line change
Expand Up @@ -864,10 +864,9 @@ class MacroEvaluator {
*/
fun initExpansion(encodingExpressions: List<EExpressionBodyExpression>) {
session.reset()
containerStack.push { ci ->
ci.type = ContainerInfo.Type.TopLevel
ci.expansion = session.getExpander(ExpansionKind.Stream, encodingExpressions, 0, encodingExpressions.size, Environment.EMPTY)
}
val ci = containerStack.push { _ -> }
ci.type = ContainerInfo.Type.TopLevel
ci.expansion = session.getExpander(ExpansionKind.Stream, encodingExpressions, 0, encodingExpressions.size, Environment.EMPTY)
}

/**
Expand Down Expand Up @@ -908,21 +907,20 @@ class MacroEvaluator {
if (expression is DataModelContainer) {
val currentContainer = containerStack.peek()
val topExpansion = currentContainer.expansion.top()
containerStack.push { ci ->
ci.type = when (expression.type) {
IonType.LIST -> ContainerInfo.Type.List
IonType.SEXP -> ContainerInfo.Type.Sexp
IonType.STRUCT -> ContainerInfo.Type.Struct
else -> unreachable()
}
ci.expansion = session.getExpander(
expansionKind = ExpansionKind.Stream,
expressions = topExpansion.expressions,
startInclusive = expression.startInclusive,
endExclusive = expression.endExclusive,
environment = topExpansion.environment,
)
}
val ci = containerStack.push { _ -> }
ci.type = when (expression.type) {
IonType.LIST -> ContainerInfo.Type.List
IonType.SEXP -> ContainerInfo.Type.Sexp
IonType.STRUCT -> ContainerInfo.Type.Struct
else -> unreachable()
}
ci.expansion = session.getExpander(
expansionKind = ExpansionKind.Stream,
expressions = topExpansion.expressions,
startInclusive = expression.startInclusive,
endExclusive = expression.endExclusive,
environment = topExpansion.environment,
)
currentExpr = null
} else {
throw IonException("Not positioned on a container.")
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -117,10 +117,9 @@ class MacroEvaluatorAsIonReader(

val containerToStepInto = currentValueExpression
evaluator.stepIn()
containerStack.push {
it.container = containerToStepInto as Expression.DataModelContainer
it.currentFieldName = null
}
val it = containerStack.push { _ -> }
it.container = containerToStepInto as Expression.DataModelContainer
it.currentFieldName = null
currentFieldName = null
currentValueExpression = null
queuedFieldName = null
Expand Down

0 comments on commit 8e1785e

Please sign in to comment.