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

Avoids using lambdas in MacroEvaluator hot paths. #1045

Open
wants to merge 1 commit into
base: ion-11-encoding-optimize-initial-expression-array-size-session-pools-merge-presencebitmap-pool
Choose a base branch
from
Open
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
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