From 6de188457011b2e39bcfe6beb10823e6968dd0e8 Mon Sep 17 00:00:00 2001 From: Oscar Boykin Date: Tue, 26 Sep 2017 15:45:35 -1000 Subject: [PATCH] Use a null check rather than foreach --- .../src/main/scala/com/twitter/scalding/Stats.scala | 8 +++++--- 1 file changed, 5 insertions(+), 3 deletions(-) diff --git a/scalding-core/src/main/scala/com/twitter/scalding/Stats.scala b/scalding-core/src/main/scala/com/twitter/scalding/Stats.scala index fe44e9ebc4..d29c0a724c 100644 --- a/scalding-core/src/main/scala/com/twitter/scalding/Stats.scala +++ b/scalding-core/src/main/scala/com/twitter/scalding/Stats.scala @@ -65,12 +65,14 @@ private[scalding] final case class GenericFlowPCounterImpl(fp: FlowProcess[_], s } private[scalding] final case class HadoopFlowPCounterImpl(fp: HadoopFlowProcess, statKey: StatKey) extends CounterImpl { - private[this] val counter: Option[Counter] = (for { + // we use a nullable type here for efficiency + private[this] val counter: Counter = (for { r <- Option(fp.getReporter) c <- Option(r.getCounter(statKey.group, statKey.counter)) - } yield c) + } yield c).orNull - override def increment(amount: Long): Unit = counter.foreach(_.increment(amount)) + override def increment(amount: Long): Unit = + if (counter != null) counter.increment(amount) else () } object Stat {