diff options
-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. |