You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@daffodil.apache.org by mb...@apache.org on 2018/08/15 12:58:57 UTC
[incubator-daffodil] branch master updated: Moved pushDiscriminator
to fix separators bug.
This is an automated email from the ASF dual-hosted git repository.
mbeckerle pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/incubator-daffodil.git
The following commit(s) were added to refs/heads/master by this push:
new efd7c0e Moved pushDiscriminator to fix separators bug.
efd7c0e is described below
commit efd7c0e8d01a791977c9e302172ef16941fbe278
Author: Michael Beckerle <mb...@tresys.com>
AuthorDate: Tue Aug 14 14:26:14 2018 -0400
Moved pushDiscriminator to fix separators bug.
Also found some unused code and deleted it. Old methods not used
anywmore.
Removed beforeArrayState - not needed. Prevents streaming behavior.
DAFFODIL-1984, DAFFODIL-1985
---
.../grammar/primitives/PrimitivesDelimiters.scala | 51 ----------------------
.../parsers/SeparatedSequenceParsers.scala | 12 +++--
.../processors/parsers/SequenceParserBases.scala | 20 ++-------
.../parsers/UnseparatedSequenceParsers.scala | 3 --
4 files changed, 13 insertions(+), 73 deletions(-)
diff --git a/daffodil-core/src/main/scala/org/apache/daffodil/grammar/primitives/PrimitivesDelimiters.scala b/daffodil-core/src/main/scala/org/apache/daffodil/grammar/primitives/PrimitivesDelimiters.scala
index 9aaf5f3..ac3f387 100644
--- a/daffodil-core/src/main/scala/org/apache/daffodil/grammar/primitives/PrimitivesDelimiters.scala
+++ b/daffodil-core/src/main/scala/org/apache/daffodil/grammar/primitives/PrimitivesDelimiters.scala
@@ -80,57 +80,6 @@ abstract class Text(es: Term, e: Term, guard: Boolean) extends StringDelimBase(e
""
}
}
-
- def getMatchedDelimiterInfo(remoteDelimRegex: Set[(String, String)], foundDelimiter: String,
- delimiters: List[(List[String], String, String)]) = {
- val matchedDelim = remoteDelimRegex.find {
- case (delimRegex, _) => {
- foundDelimiter.matches("(?s)^(" + delimRegex + ")$")
- }
- } match {
- case Some((_, theValue)) => theValue
- case None => Assert.impossibleCase()
- }
-
- val (remoteDelimValue, remoteElemName, remoteElemPath, _) =
- {
- val findResult = delimiters.map {
- case (delimValueList, elemName, elemPath) => {
- delimValueList.find(delim => delim == matchedDelim) match {
- case Some(d) => (d, elemName, elemPath, true)
- case None => (delimValueList.mkString(","), elemName, elemPath, false)
- }
- }
- }.toSet.filter { x => x._4 == true }
-
- if (findResult.size == 0) Assert.impossibleCase()
- findResult.head
- }
- (remoteDelimValue, remoteElemName, remoteElemPath)
- }
-
- def getMatchedDelimiterInfo(
- originalDelimRep: String,
- delimiters: List[(List[String], String, String)]) = {
-
- val (remoteDelimValue, remoteElemName, remoteElemPath, _) =
- {
- val findResult = delimiters.map {
- case (delimValueList, elemName, elemPath) => {
- val res = delimValueList.find(delim => delim == originalDelimRep) match {
- case Some(d) => (d, elemName, elemPath, true)
- case None => (delimValueList.mkString(","), elemName, elemPath, false)
- }
- res
- }
- }.toSet.filter { x => x._4 == true }
-
- if (findResult.size == 0) Assert.impossibleCase()
- findResult.head
- }
- (remoteDelimValue, remoteElemName, remoteElemPath)
- }
-
}
// NOTE: LiteralNil still uses this as it can only be Static/Constant
diff --git a/daffodil-runtime1/src/main/scala/org/apache/daffodil/processors/parsers/SeparatedSequenceParsers.scala b/daffodil-runtime1/src/main/scala/org/apache/daffodil/processors/parsers/SeparatedSequenceParsers.scala
index 889e5dd..38e39ca 100644
--- a/daffodil-runtime1/src/main/scala/org/apache/daffodil/processors/parsers/SeparatedSequenceParsers.scala
+++ b/daffodil-runtime1/src/main/scala/org/apache/daffodil/processors/parsers/SeparatedSequenceParsers.scala
@@ -299,6 +299,15 @@ final class OrderedSeparatedSequenceParser(
val bitPosBeforeSeparator = pstate.bitPos0b
+ //
+ // Note: Performance. All this conditional branch logic could in principle be hoisted
+ // out and decided at schema compile time, as what is being tested here is statically known.
+ //
+ // However, that's trading a few conditional branches for a virtual function call, and that
+ // might or might not be an improvement worth making. Not worth bothering with unless
+ // some profiling makes it look like this could help.
+ //
+
// parse prefix sep if any
val prefixSepSuccessful =
if (spos eq SeparatorPosition.Prefix) {
@@ -342,8 +351,6 @@ final class OrderedSeparatedSequenceParser(
//
val prevBitPosBeforeChild = pstate.bitPos0b
- pstate.pushDiscriminator
-
if (pstate.dataProc.isDefined) pstate.dataProc.get.beforeRepetition(pstate, this)
parser.parse1(pstate)
@@ -496,7 +503,6 @@ final class OrderedSeparatedSequenceParser(
result
} // end if child success/fail
} // end val res
- pstate.popDiscriminator
res
} // end if postfix
} // end if infix
diff --git a/daffodil-runtime1/src/main/scala/org/apache/daffodil/processors/parsers/SequenceParserBases.scala b/daffodil-runtime1/src/main/scala/org/apache/daffodil/processors/parsers/SequenceParserBases.scala
index 541137a..4de4a99 100644
--- a/daffodil-runtime1/src/main/scala/org/apache/daffodil/processors/parsers/SequenceParserBases.scala
+++ b/daffodil-runtime1/src/main/scala/org/apache/daffodil/processors/parsers/SequenceParserBases.scala
@@ -118,13 +118,6 @@ abstract class OrderedSequenceParserBase(
// different, or OCK=parsed.
//
- //
- // The beforeArrayState will be assigned the priorState before the whole array
- // This is the same object as the priorState before the first
- // occurrence.
- //
- var beforeArrayState: PState.Mark = null
-
var resultOfTry: ParseAttemptStatus = ParseAttemptStatus.Uninitialized
var ais: ArrayIndexStatus = null
@@ -155,8 +148,7 @@ abstract class OrderedSequenceParserBase(
//
val priorState =
if (isFirstIteration) {
- beforeArrayState = pstate.mark("before all occurrences")
- beforeArrayState
+ pstate.mark("before all occurrences")
} else {
pstate.mark("before second/subsequent occurrence")
}
@@ -166,9 +158,11 @@ abstract class OrderedSequenceParserBase(
var markLeakCausedByException = false
var wasThrow = true
try {
+ pstate.pushDiscriminator
resultOfTry =
parseOneWithPoU(parser, erd, pstate, priorState, goAIS, isBounded)
wasThrow = false
+ pstate.popDiscriminator
//
// Now we handle the result of the parse attempt.
//
@@ -231,7 +225,6 @@ abstract class OrderedSequenceParserBase(
// discarded.
//
if (!isFirstIteration) pstate.discard(priorState)
- pstate.reset(beforeArrayState)
pstate.setFailed(cause)
resultOfTry = ParseAttemptStatus.Failed_EntireArray
}
@@ -284,7 +277,7 @@ abstract class OrderedSequenceParserBase(
}
}
// if it wasn't reset, we discard priorState here.
- if (!isFirstIteration && pstate.isInUse(priorState)) {
+ if (pstate.isInUse(priorState)) {
pstate.discard(priorState)
}
@@ -300,11 +293,6 @@ abstract class OrderedSequenceParserBase(
} // end while for each repeat
- // if it wasn't reset or discarded, discard here.
- if (pstate.isInUse(beforeArrayState)) {
- pstate.discard(beforeArrayState)
- }
-
} // end match case hasPoU = true
case false => {
diff --git a/daffodil-runtime1/src/main/scala/org/apache/daffodil/processors/parsers/UnseparatedSequenceParsers.scala b/daffodil-runtime1/src/main/scala/org/apache/daffodil/processors/parsers/UnseparatedSequenceParsers.scala
index 3210f7d..8ea27fe 100644
--- a/daffodil-runtime1/src/main/scala/org/apache/daffodil/processors/parsers/UnseparatedSequenceParsers.scala
+++ b/daffodil-runtime1/src/main/scala/org/apache/daffodil/processors/parsers/UnseparatedSequenceParsers.scala
@@ -118,8 +118,6 @@ class OrderedUnseparatedSequenceParser(rd: SequenceRuntimeData, childParsersArg:
Assert.invariant(erd.isArray || erd.isOptional) // not a PoU otherwise.
- pstate.pushDiscriminator
-
if (pstate.dataProc.isDefined) pstate.dataProc.get.beforeRepetition(pstate, this)
val posBefore = pstate.bitPos0b
@@ -160,7 +158,6 @@ class OrderedUnseparatedSequenceParser(rd: SequenceRuntimeData, childParsersArg:
}
}
}
- pstate.popDiscriminator
res
}