diff options
author | Paul Phillips <paulp@improving.org> | 2009-04-29 03:14:52 +0000 |
---|---|---|
committer | Paul Phillips <paulp@improving.org> | 2009-04-29 03:14:52 +0000 |
commit | cee28d7cc71e83463842f6672d13a5b14bb7c954 (patch) | |
tree | 8a442d05004eb1481ad5b9cf184a015a65a029d4 /src | |
parent | 6029fa793184426e4cc9e81fddcd5acee902311d (diff) | |
download | scala-cee28d7cc71e83463842f6672d13a5b14bb7c954.tar.gz scala-cee28d7cc71e83463842f6672d13a5b14bb7c954.tar.bz2 scala-cee28d7cc71e83463842f6672d13a5b14bb7c954.zip |
Minor refinements to pull parser, plus fix for ...
Minor refinements to pull parser, plus fix for #1079.
Diffstat (limited to 'src')
-rw-r--r-- | src/library/scala/xml/MetaData.scala | 2 | ||||
-rw-r--r-- | src/library/scala/xml/pull/XMLEventReader.scala | 27 |
2 files changed, 10 insertions, 19 deletions
diff --git a/src/library/scala/xml/MetaData.scala b/src/library/scala/xml/MetaData.scala index 159ddc05be..e2537b6018 100644 --- a/src/library/scala/xml/MetaData.scala +++ b/src/library/scala/xml/MetaData.scala @@ -137,7 +137,7 @@ abstract class MetaData extends Collection[MetaData] { * @return <code>true</code> iff ... */ def containedIn1(m: MetaData): Boolean = - m.equals1(this) || containedIn1(m.next) + m != null && (m.equals1(this) || containedIn1(m.next)) /** returns a copy of this MetaData item with next field set to argument. * diff --git a/src/library/scala/xml/pull/XMLEventReader.scala b/src/library/scala/xml/pull/XMLEventReader.scala index a0ab9667d0..dfb6ac4049 100644 --- a/src/library/scala/xml/pull/XMLEventReader.scala +++ b/src/library/scala/xml/pull/XMLEventReader.scala @@ -65,7 +65,7 @@ class XMLEventReader(src: Source) extends ProducerConsumerIterator[XMLEvent] // only performance (because it will finish the entire XML document, // or at least as much as it can fit in the queue.) def stop = { - parser.setEvent(POISON) + produce(POISON) parserThread.interrupt() } @@ -96,15 +96,7 @@ class XMLEventReader(src: Source) extends ProducerConsumerIterator[XMLEvent] override def run() { curInput = input - try { - this.nextch - this.document() - } - catch { - case _: InterruptedException => Thread.currentThread.interrupt() - case _: ClosedChannelException => - } - + interruptibly { this.nextch ; this.document() } setEvent(POISON) } } @@ -128,15 +120,17 @@ trait ProducerConsumerIterator[T >: Null] extends Iterator[T] // defaults to unbounded - override to positive Int if desired val MaxQueueSize = -1 + def interruptibly[T](body: => T): Option[T] = try Some(body) catch { + case _: InterruptedException => Thread.currentThread.interrupt() ; None + case _: ClosedChannelException => None + } + private[this] lazy val queue = if (MaxQueueSize < 0) new LinkedBlockingQueue[T]() else new LinkedBlockingQueue[T](MaxQueueSize) private[this] var buffer: T = _ private def fillBuffer() = { - buffer = try queue.take catch { - case _: InterruptedException => Thread.currentThread.interrupt() ; EndOfStream - case _: ClosedChannelException => EndOfStream - } + buffer = interruptibly(queue.take) getOrElse EndOfStream isElement(buffer) } private def isElement(x: T) = x != null && x != EndOfStream @@ -144,10 +138,7 @@ trait ProducerConsumerIterator[T >: Null] extends Iterator[T] // public producer interface - this is the only method producers call, so // LinkedBlockingQueue's synchronization is all we need. - def produce(x: T): Unit = if (!eos) try queue put x catch { - case _: InterruptedException => Thread.currentThread.interrupt() - case _: ClosedChannelException => - } + def produce(x: T): Unit = if (!eos) interruptibly(queue put x) // consumer/iterator interface - we need not synchronize access to buffer // because we required there to be only one consumer. |