Class ExpressionPool
- java.lang.Object
-
- com.sun.msv.grammar.ExpressionPool
-
- All Implemented Interfaces:
Serializable
public class ExpressionPool extends Object implements Serializable
Creates a new Expression by combining existing expressions. all expressions are memorized and unified so that every subexpression will be shared and reused. Optimization will be also done transparently. For example, createChoice(P,P) will result in P. createSequence(P,nullSet) will result in nullSet. Furthermore, associative operators are grouped to the left. createChoice( (P|Q), (R|S) ) will be ((P|Q)|R)|S.Although this unification is essential, this is also the performance bottle neck. In particular, createChoice and createSequence are two most commonly called methods.
For example, when validating a DocBook XML (150KB) twice against DocBook.trex(237KB), createChoice is called 63000 times and createSequence called 23000 times. (the third is the createOptional method and only 1560 times.) And they took more than 10% of validation time, which is the worst time-consuming method.
Therefore, please beware that this class includes several ugly code optimization.
- Author:
- Kohsuke KAWAGUCHI
- See Also:
- Serialized Form
-
-
Nested Class Summary
Nested Classes Modifier and Type Class Description static class
ExpressionPool.ClosedHash
expression cache by closed hash.
-
Constructor Summary
Constructors Constructor Description ExpressionPool()
ExpressionPool(ExpressionPool parent)
creates new expression pool as a child pool of the given parent pool.
-
Method Summary
-
-
-
Constructor Detail
-
ExpressionPool
public ExpressionPool(ExpressionPool parent)
creates new expression pool as a child pool of the given parent pool.Every expression memorized in the parent pool can be retrieved, but update operations are only performed upon the child pool. In this way, the parent pool can be shared among the multiple threads without interfering performance.
Furthermore, you can throw away a child pool after a certain time period to prevent it from eating up memory.
-
ExpressionPool
public ExpressionPool()
-
-
Method Detail
-
createAttribute
public final Expression createAttribute(NameClass nameClass)
-
createAttribute
public final Expression createAttribute(NameClass nameClass, Expression content)
-
createEpsilon
public final Expression createEpsilon()
-
createNullSet
public final Expression createNullSet()
-
createAnyString
public final Expression createAnyString()
-
createChoice
public final Expression createChoice(Expression left, Expression right)
-
createOneOrMore
public final Expression createOneOrMore(Expression child)
-
createZeroOrMore
public final Expression createZeroOrMore(Expression child)
-
createOptional
public final Expression createOptional(Expression child)
-
createData
public final Expression createData(XSDatatype dt)
-
createData
public final Expression createData(org.relaxng.datatype.Datatype dt, StringPair typeName)
-
createData
public final Expression createData(org.relaxng.datatype.Datatype dt, StringPair typeName, Expression except)
-
createValue
public final Expression createValue(XSDatatype dt, Object value)
-
createValue
public final Expression createValue(org.relaxng.datatype.Datatype dt, StringPair typeName, Object value)
-
createList
public final Expression createList(Expression exp)
-
createMixed
public final Expression createMixed(Expression body)
-
createSequence
public final Expression createSequence(Expression left, Expression right)
-
createConcur
public final Expression createConcur(Expression left, Expression right)
-
createInterleave
public final Expression createInterleave(Expression left, Expression right)
-
unify
protected final Expression unify(Expression exp)
unifies expressions. If the equivalent expression is already registered in the table, destroy newly created one (so that no two objects represents same expression structure). If it's not registered, then register it and return it.
-
-