summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorburaq <buraq@epfl.ch>2004-11-01 07:52:58 +0000
committerburaq <buraq@epfl.ch>2004-11-01 07:52:58 +0000
commitf99e4b1e18b0ab02d1f2abeea06fb035488b0b89 (patch)
treef786a0a9ac999b32c7e37871af1b89411f3ece7d
parentab3bc54b208f6f8bca3c33e5158882dfa32bf48f (diff)
downloadscala-f99e4b1e18b0ab02d1f2abeea06fb035488b0b89.tar.gz
scala-f99e4b1e18b0ab02d1f2abeea06fb035488b0b89.tar.bz2
scala-f99e4b1e18b0ab02d1f2abeea06fb035488b0b89.zip
bugfix in NodeFactory
-rw-r--r--sources/scala/xml/FactoryAdapter.scala2
-rw-r--r--sources/scala/xml/NodeFactory.scala63
2 files changed, 30 insertions, 35 deletions
diff --git a/sources/scala/xml/FactoryAdapter.scala b/sources/scala/xml/FactoryAdapter.scala
index 386b4b8841..f9cf1fb4aa 100644
--- a/sources/scala/xml/FactoryAdapter.scala
+++ b/sources/scala/xml/FactoryAdapter.scala
@@ -34,7 +34,7 @@ import javax.xml.parsers.SAXParser;
/** SAX adapter class, for use with Java SAX parser
**/
-abstract class FactoryAdapter extends DefaultHandler() {
+abstract class FactoryAdapter extends DefaultHandler() {
val buffer = new StringBuffer();
val attribStack = new Stack[HashMap[Pair[String,String],String]];
diff --git a/sources/scala/xml/NodeFactory.scala b/sources/scala/xml/NodeFactory.scala
index 3ab21963f4..d44d804def 100644
--- a/sources/scala/xml/NodeFactory.scala
+++ b/sources/scala/xml/NodeFactory.scala
@@ -22,51 +22,45 @@ abstract class NodeFactory[A <: Node] {
protected def create(uname: UName, attrs: AttributeSeq, children:Seq[Node]): A;
- def makeNode(uname: UName, attrSeq:AttributeSeq, children:Seq[Node]): A = {
- val hash = Utility.hashCode( uname, attrSeq.hashCode(), children ) ;
-
- def construct: A = {
- val el = create( uname, attrSeq, children );
- cache.update( hash, List(el));
- el
- }
+ protected def construct(hash:Int, old:List[A], uname: UName, attrSeq:AttributeSeq, children:Seq[Node]): A = {
+ val el = create(uname, attrSeq, children);
+ cache.update( hash, el::old );
+ el
+ }
- /** faster equality, because */
- def eqElements(ch1:Seq[Node], ch2:Seq[Node]): Boolean = {
- (ch1.length == ch2.length) && {
- val it1 = ch1.elements;
- val it2 = ch2.elements;
- var res = true;
- while(res && it1.hasNext) {
- res = it1.next.eq(it2.next);
- }
- res
+ /** faster equality, because */
+ def eqElements(ch1:Seq[Node], ch2:Seq[Node]): Boolean = {
+ (ch1.length == ch2.length) && {
+ val it1 = ch1.elements;
+ val it2 = ch2.elements;
+ var res = true;
+ while(res && it1.hasNext) {
+ res = it1.next.eq(it2.next);
}
+ res
}
+ }
- def nodeEquals(n: Node) =
- (n.namespace == uname.uri)
- &&(n.label == uname.label)
- &&(n.attributes == attrSeq)
- &&(eqElements(n.child,children));
+ def nodeEquals(n: Node, uname: UName, attrSeq:AttributeSeq, children:Seq[Node]) =
+ (n.namespace == uname.uri)
+ &&(n.label == uname.label)
+ &&(n.attributes == attrSeq)
+ &&(eqElements(n.child,children));
- /*
- Console.println("[makeNode called, hash: ]"+hash);
- Console.println("[elem name: ]"+uname+" hash "+(41 * uname.uri.hashCode() % 7 + uname.label.hashCode());
- Console.println("[attrs : ]"+attrSeq+" hash "+attrSeq.hashCode());
- Console.println("[children name: ]"+children+" hash "+children.hashCode());
- */
- cache.get( hash ) match {
+ def makeNode(uname: UName, attrSeq:AttributeSeq, children:Seq[Node]): A = {
+ Console.println("wrong makeNode");
+ val hash = Utility.hashCode( uname, attrSeq.hashCode(), children ) ;
+ cache.get( hash ) match {
case Some(list) => // find structurally equal
val it = list.elements;
- val lookup = it.find { x => nodeEquals(x) };
+ val lookup = it.find { x => nodeEquals(x,uname,attrSeq,children) };
lookup match {
case Some(x) =>
//Console.println("[cache hit !]"+x);
x; // return cached elem
- case _ => construct;
+ case _ => construct(hash, list, uname, attrSeq, children);
}
- case _ => construct
+ case _ => construct(hash, Nil, uname, attrSeq, children)
}
}
@@ -79,8 +73,9 @@ abstract class NodeFactory[A <: Node] {
def makeProcInstr(t: String, s: String): Seq[ProcInstr] =
if(ignoreProcInstr) Nil else List(ProcInstr(t, s));
+ /*
def makeCharData(s: String) =
CharData( s );
-
+ */
}