Skip to content

Commit

Permalink
prevent implicit copying of array
Browse files Browse the repository at this point in the history
  • Loading branch information
Martijn Hoekstra committed Jun 25, 2019
1 parent b07c3f6 commit 2f1fd14
Show file tree
Hide file tree
Showing 8 changed files with 15 additions and 17 deletions.
2 changes: 1 addition & 1 deletion util-app/src/main/scala/com/twitter/app/ClassPath.scala
Original file line number Diff line number Diff line change
Expand Up @@ -228,7 +228,7 @@ private[app] class LoadServiceClassPath extends ClassPath[ClassPath.LoadServiceI

private[app] def readLines(source: Source): Seq[String] = {
try {
source.getLines().toArray.flatMap { line =>
source.getLines().toVector.flatMap { line =>
val commentIdx = line.indexOf('#')
val end = if (commentIdx != -1) commentIdx else line.length
val str = line.substring(0, end).trim
Expand Down
6 changes: 3 additions & 3 deletions util-app/src/test/scala/com/twitter/app/LoadServiceTest.scala
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,8 @@ import java.io.{File, InputStream}
import java.net.URL
import java.util
import java.util.concurrent.{Callable, CountDownLatch, ExecutorService, Executors}
import java.util.{Random, concurrent}
import java.util.concurrent.{Future => JFuture}
import java.util.Random
import org.scalatest.FunSuite
import org.scalatestplus.mockito.MockitoSugar
import scala.collection.mutable
Expand Down Expand Up @@ -140,7 +141,7 @@ class LoadServiceTest extends FunSuite with MockitoSugar {
// Run LoadService in a different thread from the custom classloader
val clazz: Class[_] = loader.loadClass("com.twitter.app.LoadServiceCallable")
val executor: ExecutorService = Executors.newSingleThreadExecutor()
val future: concurrent.Future[Seq[Any]] =
val future: JFuture[Seq[Any]] =
executor.submit(clazz.newInstance().asInstanceOf[Callable[Seq[Any]]])

// Get the result
Expand Down Expand Up @@ -262,7 +263,6 @@ class LoadServiceTest extends FunSuite with MockitoSugar {
assert(lsds0.size == 1)
assert(lsds0.head.getClass == classOf[LoadServiceDeadlockImpl])
}

}

class LoadServiceCallable extends Callable[Seq[Any]] {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ package com.twitter.concurrent

import com.twitter.util.{Await, Duration, Future, Promise, Time, Timer}
import com.twitter.util.Return
import scala.collection.compat.immutable.ArraySeq
import scala.util.Random

/**
Expand Down Expand Up @@ -280,7 +281,7 @@ object Offer {
if (foundPos >= 0) {
updateLosers(foundPos, prepd)
} else {
Future.selectIndex(prepd) flatMap { winPos =>
Future.selectIndex(ArraySeq.unsafeWrapArray(prepd)) flatMap { winPos =>
updateLosers(winPos, prepd)
}
}
Expand Down
11 changes: 4 additions & 7 deletions util-core/src/main/scala/com/twitter/util/Var.scala
Original file line number Diff line number Diff line change
Expand Up @@ -369,13 +369,10 @@ object Var {
if (!filling) v() = build()
}

val closes = new Array[Closable](N)
var i = 0
for (v <- vars) {
val j = i
closes(j) = v.observe(0, Observer(newValue => publish(j, newValue)))
i += 1
}
val closes = vars.iterator
.zipWithIndex
.map{ case (v, i) => v.observe(0, Observer(newValue => publish(i, newValue)))}
.toSeq

filling = false
v() = build()
Expand Down
2 changes: 1 addition & 1 deletion util-core/src/test/scala/com/twitter/io/BufTest.scala
Original file line number Diff line number Diff line change
Expand Up @@ -107,7 +107,7 @@ class BufTest
test("Buf.equals") {
val bytes = Array[Byte](0, 1, 2)
val byteBuffer = Buf.ByteBuffer.Owned(java.nio.ByteBuffer.wrap(bytes))
val byteArray = Buf.ByteArray(bytes: _*)
val byteArray = Buf.ByteArray(bytes.toSeq: _*)
val composite = Buf.ByteArray(0).concat(Buf.ByteArray(1)).concat(Buf.ByteArray(2))
val bufs = Seq(byteBuffer, byteArray, composite)

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ class ByteReaderTest extends FunSuite with ScalaCheckDrivenPropertyChecks {
test("readString")(forAll { (str1: String, str2: String) =>
val bytes1 = str1.getBytes(StandardCharsets.UTF_8)
val bytes2 = str2.getBytes(StandardCharsets.UTF_8)
val br = readerWith(bytes1 ++ bytes2: _*)
val br = readerWith((bytes1 ++ bytes2).toSeq: _*)
assert(br.readString(bytes1.length, StandardCharsets.UTF_8) == str1)
assert(br.readString(bytes2.length, StandardCharsets.UTF_8) == str2)
intercept[UnderflowException] { br.readByte() }
Expand Down
4 changes: 2 additions & 2 deletions util-jvm/src/test/scala/com/twitter/jvm/EstimatorApp.scala
Original file line number Diff line number Diff line change
Expand Up @@ -20,12 +20,12 @@ object EstimatorApp extends App {
case Array("windowed", n, windows) =>
new WindowedMeans(
n.toInt,
windows.split(",") map { w =>
windows.split(",").iterator.map { w =>
w.split(":") match {
case Array(w, i) => (w.toInt, i.toInt)
case _ => throw new IllegalArgumentException("bad weight, count pair " + w)
}
}
}.toSeq
)
case Array("load", interval) =>
new LoadAverage(interval.toDouble)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -66,7 +66,7 @@ trait TestLogging extends BeforeAndAfter { self: WordSpec =>
logger.addHandler(traceHandler)
}

def logLines(): Seq[String] = traceHandler.get.split("\n")
def logLines(): Seq[String] = traceHandler.get.split("\n").toSeq

/**
* Verify that the logger set up with `traceLogger` has received a log line with the given
Expand Down

0 comments on commit 2f1fd14

Please sign in to comment.