diff options
| author | Christian Wailes <chriswailes@google.com> | 2019-03-08 18:16:09 +0000 |
|---|---|---|
| committer | Gerrit Code Review <noreply-gerritcodereview@google.com> | 2019-03-08 18:16:09 +0000 |
| commit | 49c40bcec18e200009f9e770ccf1079d583bece6 (patch) | |
| tree | 01304153f71f874fbae5ae402f7dbbcd73e533f8 | |
| parent | 2d686b1bec34bbb8007479b1a4f0d7ac1d01fd9f (diff) | |
| parent | 7243b41eed6d9be5935dd6ebb1dcfafac889b96c (diff) | |
| download | platform_tools_trebuchet-49c40bcec18e200009f9e770ccf1079d583bece6.tar.gz platform_tools_trebuchet-49c40bcec18e200009f9e770ccf1079d583bece6.tar.bz2 platform_tools_trebuchet-49c40bcec18e200009f9e770ccf1079d583bece6.zip | |
Merge "Fixed assorted warnings."android-q-preview-1
7 files changed, 36 insertions, 47 deletions
diff --git a/core/common/src/main/kotlin/trebuchet/extractors/ZlibExtractor.kt b/core/common/src/main/kotlin/trebuchet/extractors/ZlibExtractor.kt index ed7b4dc..237dabe 100644 --- a/core/common/src/main/kotlin/trebuchet/extractors/ZlibExtractor.kt +++ b/core/common/src/main/kotlin/trebuchet/extractors/ZlibExtractor.kt @@ -19,11 +19,9 @@ package trebuchet.extractors import trebuchet.importers.ImportFeedback import trebuchet.io.* import trebuchet.util.indexOf -import java.io.InputStream import java.util.zip.DataFormatException import java.util.zip.Inflater -import java.util.zip.InflaterInputStream -import kotlin.coroutines.experimental.buildIterator +import kotlin.sequences.iterator private const val TRACE = "TRACE:" @@ -48,7 +46,7 @@ private class DeflateProducer(stream: StreamingReader, val feedback: ImportFeedb private val inflater = Inflater() private var closed = false - private val sourceIterator = buildIterator { + private val sourceIterator = iterator { stream.loadIndex(stream.startIndex + 1024) val offset = findStart(stream) val buffIter = stream.iter(offset) @@ -64,12 +62,12 @@ private class DeflateProducer(stream: StreamingReader, val feedback: ImportFeedb if (inflater.needsDictionary()) { feedback.reportImportException(IllegalStateException( "inflater needs dictionary, which isn't supported")) - return@buildIterator + return@iterator } val compressFactor = len.toDouble() / (remaining - inflater.remaining) avgCompressFactor = (avgCompressFactor * 9 + compressFactor) / 10 yield(array.asSlice(len)) - if (closed) return@buildIterator + if (closed) return@iterator } while (!inflater.needsInput()) inflater.end() } diff --git a/core/common/src/main/kotlin/trebuchet/io/StreamingLineReader.kt b/core/common/src/main/kotlin/trebuchet/io/StreamingLineReader.kt index cc07a0b..234dbb5 100644 --- a/core/common/src/main/kotlin/trebuchet/io/StreamingLineReader.kt +++ b/core/common/src/main/kotlin/trebuchet/io/StreamingLineReader.kt @@ -16,7 +16,7 @@ package trebuchet.io -import kotlin.coroutines.experimental.buildIterator +import kotlin.sequences.iterator private fun findNewlineInWindow(window: StreamingReader.Window, startIndex: Long): Long { for (i in startIndex..window.globalEndIndex) { @@ -29,7 +29,7 @@ private fun findNewlineInWindow(window: StreamingReader.Window, startIndex: Long * Iterates over all the lines in the stream, skipping any empty line. Lines do not contain * the line-end marker(s). Handles both LF & CRLF endings. */ -fun StreamingReader.iterLines() = buildIterator { +fun StreamingReader.iterLines() = iterator { val stream = this@iterLines var lineStartIndex = stream.startIndex @@ -45,6 +45,7 @@ fun StreamingReader.iterLines() = buildIterator { if (foundAt != -1L) break index = window.globalEndIndex + 1 } + // Reached EOF with no data, return if (lineStartIndex > stream.endIndex) break @@ -64,7 +65,7 @@ fun StreamingReader.iterLines() = buildIterator { yield(window.slice.slice((lineStartIndex - window.globalStartIndex).toInt(), (lineEndIndexInclusive - window.globalStartIndex + 1).toInt())) } else { - var tmpBuffer = ByteArray((lineEndIndexInclusive - lineStartIndex + 1).toInt()) + val tmpBuffer = ByteArray((lineEndIndexInclusive - lineStartIndex + 1).toInt()) stream.copyTo(tmpBuffer, lineStartIndex, lineEndIndexInclusive) yield(tmpBuffer.asSlice()) } diff --git a/core/common/src/main/kotlin/trebuchet/io/StreamingReader.kt b/core/common/src/main/kotlin/trebuchet/io/StreamingReader.kt index 18c87b6..765733e 100644 --- a/core/common/src/main/kotlin/trebuchet/io/StreamingReader.kt +++ b/core/common/src/main/kotlin/trebuchet/io/StreamingReader.kt @@ -16,8 +16,7 @@ package trebuchet.io -import javax.xml.crypto.Data -import kotlin.coroutines.experimental.buildIterator +import kotlin.sequences.iterator class StreamingReader(val source: BufferProducer, val keepLoadedSize: Int = 8096) : GenericByteBuffer { val windows = mutableListOf<Window>() @@ -57,7 +56,7 @@ class StreamingReader(val source: BufferProducer, val keepLoadedSize: Int = 8096 } fun iter(startIndex: Long = 0L): Iterator<DataSlice> { - return buildIterator { + return iterator { for (win in windows) { if (startIndex <= win.globalStartIndex) { yield(win.slice) @@ -65,14 +64,20 @@ class StreamingReader(val source: BufferProducer, val keepLoadedSize: Int = 8096 yield(win.slice.slice((startIndex - win.globalStartIndex).toInt())) } } + while (!reachedEof) { val nextBuffer = source.next() - if (nextBuffer == null) { + if (nextBuffer != null) { + addBuffer(nextBuffer) + + // This variable is a workaround for an apparent bug in the Kotlin + // type system that causes it to handle type inference around yield + // statements incorrectly. + val notNullNextBuffer : DataSlice = nextBuffer + yield(notNullNextBuffer) + } else { reachedEof = true - break } - addBuffer(nextBuffer) - yield(nextBuffer!!) } } } diff --git a/core/common/src/main/kotlin/trebuchet/queries/SliceQueries.kt b/core/common/src/main/kotlin/trebuchet/queries/SliceQueries.kt index 70d5b34..95efe28 100644 --- a/core/common/src/main/kotlin/trebuchet/queries/SliceQueries.kt +++ b/core/common/src/main/kotlin/trebuchet/queries/SliceQueries.kt @@ -16,13 +16,14 @@ package trebuchet.queries +import kotlin.sequences.Sequence +import kotlin.sequences.SequenceScope + import trebuchet.model.Model import trebuchet.model.ProcessModel import trebuchet.model.ThreadModel import trebuchet.model.base.Slice import trebuchet.model.base.SliceGroup -import kotlin.coroutines.experimental.SequenceBuilder -import kotlin.coroutines.experimental.buildSequence enum class TraverseAction { /** @@ -175,7 +176,7 @@ object SliceQueries { } } -private suspend fun SequenceBuilder<Slice>.yieldSlices(slices: List<SliceGroup>) { +private suspend fun SequenceScope<Slice>.yieldSlices(slices: List<SliceGroup>) { slices.forEach { yield(it) yieldSlices(it.children) @@ -184,7 +185,7 @@ private suspend fun SequenceBuilder<Slice>.yieldSlices(slices: List<SliceGroup>) fun Model.slices(includeAsync: Boolean = true): Sequence<Slice> { val model = this - return buildSequence { + return sequence { model.processes.values.forEach { process -> if (includeAsync) { yieldAll(process.asyncSlices) diff --git a/core/common/src/main/kotlin/trebuchet/util/BatchProcessor.kt b/core/common/src/main/kotlin/trebuchet/util/BatchProcessor.kt index 69e7362..fe98564 100644 --- a/core/common/src/main/kotlin/trebuchet/util/BatchProcessor.kt +++ b/core/common/src/main/kotlin/trebuchet/util/BatchProcessor.kt @@ -52,7 +52,7 @@ class WorkQueue { fun processAll() { while (!finished) { - var next: Runnable? = null + var next: Runnable? do { synchronized(workArray) { next = workArray.poll() @@ -68,7 +68,7 @@ class WorkQueue { spinLoop(60000) } - var remaining: Runnable? = null + var remaining: Runnable? do { synchronized(workArray) { remaining = workArray.poll() @@ -106,35 +106,18 @@ fun<T, U, S> par_map(iterator: Iterator<T>, threadState: () -> S, chunkSize: Int val resultPipe = ArrayBlockingQueue<Future<List<U>>>(1024, false) thread { val threadLocal = ThreadLocal.withInitial { threadState() } - if (true) { - WorkPool().use { pool -> - while (iterator.hasNext()) { - val source = ArrayList<T>(chunkSize) - while (source.size < chunkSize && iterator.hasNext()) { - source.add(iterator.next()) - } - val future = CompletableFuture<List<U>>() - pool.submit(Runnable { - val state = threadLocal.get() - future.complete(source.map { map(state, it) }) - }) - resultPipe.put(future) - } - resultPipe.put(endOfStreamMarker) - } - } else { - val pool = Executors.newFixedThreadPool(ThreadCount) { - Thread(it).apply { isDaemon = true } - } + WorkPool().use { pool -> while (iterator.hasNext()) { val source = ArrayList<T>(chunkSize) while (source.size < chunkSize && iterator.hasNext()) { source.add(iterator.next()) } - resultPipe.put(pool.submit( Callable { + val future = CompletableFuture<List<U>>() + pool.submit(Runnable { val state = threadLocal.get() - source.map { map(state, it) } - })) + future.complete(source.map { map(state, it) }) + }) + resultPipe.put(future) } resultPipe.put(endOfStreamMarker) } diff --git a/core/common/src/test/kotlin/trebuchet/extractors/ZlibExtractorTest.kt b/core/common/src/test/kotlin/trebuchet/extractors/ZlibExtractorTest.kt index 0f92089..5f1e493 100644 --- a/core/common/src/test/kotlin/trebuchet/extractors/ZlibExtractorTest.kt +++ b/core/common/src/test/kotlin/trebuchet/extractors/ZlibExtractorTest.kt @@ -58,7 +58,7 @@ class ZlibExtractorTest { extractor.extract(StreamingReader(openSample())) { val first = it.next() assertNotNull(first) - assertTrue(first!!.length > expected.length) + assertTrue(first.length > expected.length) assertEquals(expected, first.slice(0, expected.length).toString()) it.close() } diff --git a/gradle/wrapper/gradle-wrapper.properties b/gradle/wrapper/gradle-wrapper.properties index a95009c..f860796 100644 --- a/gradle/wrapper/gradle-wrapper.properties +++ b/gradle/wrapper/gradle-wrapper.properties @@ -1,5 +1,6 @@ +#Thu Mar 07 17:00:27 PST 2019 distributionBase=GRADLE_USER_HOME distributionPath=wrapper/dists -distributionUrl=https\://services.gradle.org/distributions/gradle-4.9-bin.zip zipStoreBase=GRADLE_USER_HOME zipStorePath=wrapper/dists +distributionUrl=https\://services.gradle.org/distributions/gradle-4.9-all.zip |
